text
stringlengths
1
1.05M
; A040302: Continued fraction for sqrt(320). ; 17,1,7,1,34,1,7,1,34,1,7,1,34,1,7,1,34,1,7,1,34,1,7,1,34,1,7,1,34,1,7,1,34,1,7,1,34,1,7,1,34,1,7,1,34,1,7,1,34,1,7,1,34,1,7,1,34,1,7,1,34,1,7,1,34,1,7,1,34,1,7,1,34,1,7,1,34,1,7,1,34,1,7,1 mov $3,4 cal $0,40236 ; Continued fraction for sqrt(252). mov $2,1 lpb $2,2 mov $1,$0 mov $2,$0 mul $2,3 mov $4,$0 lpb $4 sub $1,$2 mov $2,2 mov $3,0 sub $4,7 lpe div $1,2 pow $2,0 lpe mov $4,1 sub $4,$1 mov $1,$4
C arm/v6/sha1-compress.asm ifelse(< Copyright (C) 2013 Niels Möller This file is part of GNU Nettle. GNU Nettle is free software: you can redistribute it and/or modify it under the terms of either: * 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. or * the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. or both in parallel, as here. GNU Nettle is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received copies of the GNU General Public License and the GNU Lesser General Public License along with this program. If not, see http://www.gnu.org/licenses/. >) .file "sha1-compress.asm" .arch armv6 define(<STATE>, <r0>) define(<INPUT>, <r1>) define(<SA>, <r2>) define(<SB>, <r3>) define(<SC>, <r4>) define(<SD>, <r5>) define(<SE>, <r6>) define(<T0>, <r7>) define(<SHIFT>, <r8>) define(<WPREV>, <r10>) define(<W>, <r12>) define(<K>, <lr>) C FIXME: Could avoid a mov with even and odd variants. define(<LOAD>, < ldr T0, [INPUT], #+4 sel W, WPREV, T0 ror W, W, SHIFT mov WPREV, T0 rev W, W str W, [SP,#eval(4*$1)] >) define(<EXPN>, < ldr W, [sp, #+eval(4*$1)] ldr T0, [sp, #+eval(4*(($1 + 2) % 16))] eor W, W, T0 ldr T0, [sp, #+eval(4*(($1 + 8) % 16))] eor W, W, T0 ldr T0, [sp, #+eval(4*(($1 + 13) % 16))] eor W, W, T0 ror W, W, #31 str W, [sp, #+eval(4*$1)] >) C F1(B,C,D) = D^(B&(C^D)) C ROUND1(A,B,C,D,E) define(<ROUND1>, < eor T0, $3, $4 add $5, $5, K and T0, T0, $2 add $5, $5, $1, ror #27 eor T0, T0, $4 add $5, $5, W ror $2, $2, #2 add $5, $5, T0 >) C F2(B,C,D) = B^C^D define(<ROUND2>, < eor T0, $2, $4 add $5, $5, K eor T0, T0, $3 add $5, $5, $1, ror #27 add $5, $5, W ror $2, $2, #2 add $5, $5, T0 >) C F3(B,C,D) = (B&C) | (D & (B|C)) = (B & (C ^ D)) + (C & D) define(<ROUND3>, < eor T0, $3, $4 add $5, $5, K and T0, T0, $2 add $5, $5, $1, ror #27 add $5, $5, T0 add $5, $5, W and T0, $3, $4 ror $2, $2, #2 add $5, $5, T0 >) C void _nettle_sha1_compress(uint32_t *state, const uint8_t *input) .text .align 2 .LK1: .int 0x5A827999 .LK2: .int 0x6ED9EBA1 .LK3: .int 0x8F1BBCDC PROLOGUE(_nettle_sha1_compress) push {r4,r5,r6,r7,r8,r10,lr} sub sp, sp, #64 C Sets SHIFT to 8*low bits of input pointer. Sets up GE flags C as follows, corresponding to bytes to be used from WPREV C SHIFT 0 8 16 24 C CPSR.GE 0000 1110 1100 1000 ands SHIFT, INPUT, #3 and INPUT, INPUT, $-4 ldr WPREV, [INPUT] addne INPUT, INPUT, #4 C Unaligned input lsl SHIFT, SHIFT, #3 mov T0, #0 movne T0, #-1 lsl W, T0, SHIFT uadd8 T0, T0, W C Sets APSR.GE bits ldr K, .LK1 ldm STATE, {SA,SB,SC,SD,SE} LOAD( 0) ROUND1(SA, SB, SC, SD, SE) LOAD( 1) ROUND1(SE, SA, SB, SC, SD) LOAD( 2) ROUND1(SD, SE, SA, SB, SC) LOAD( 3) ROUND1(SC, SD, SE, SA, SB) LOAD( 4) ROUND1(SB, SC, SD, SE, SA) LOAD( 5) ROUND1(SA, SB, SC, SD, SE) LOAD( 6) ROUND1(SE, SA, SB, SC, SD) LOAD( 7) ROUND1(SD, SE, SA, SB, SC) LOAD( 8) ROUND1(SC, SD, SE, SA, SB) LOAD( 9) ROUND1(SB, SC, SD, SE, SA) LOAD(10) ROUND1(SA, SB, SC, SD, SE) LOAD(11) ROUND1(SE, SA, SB, SC, SD) LOAD(12) ROUND1(SD, SE, SA, SB, SC) LOAD(13) ROUND1(SC, SD, SE, SA, SB) LOAD(14) ROUND1(SB, SC, SD, SE, SA) LOAD(15) ROUND1(SA, SB, SC, SD, SE) EXPN( 0) ROUND1(SE, SA, SB, SC, SD) EXPN( 1) ROUND1(SD, SE, SA, SB, SC) EXPN( 2) ROUND1(SC, SD, SE, SA, SB) EXPN( 3) ROUND1(SB, SC, SD, SE, SA) ldr K, .LK2 EXPN( 4) ROUND2(SA, SB, SC, SD, SE) EXPN( 5) ROUND2(SE, SA, SB, SC, SD) EXPN( 6) ROUND2(SD, SE, SA, SB, SC) EXPN( 7) ROUND2(SC, SD, SE, SA, SB) EXPN( 8) ROUND2(SB, SC, SD, SE, SA) EXPN( 9) ROUND2(SA, SB, SC, SD, SE) EXPN(10) ROUND2(SE, SA, SB, SC, SD) EXPN(11) ROUND2(SD, SE, SA, SB, SC) EXPN(12) ROUND2(SC, SD, SE, SA, SB) EXPN(13) ROUND2(SB, SC, SD, SE, SA) EXPN(14) ROUND2(SA, SB, SC, SD, SE) EXPN(15) ROUND2(SE, SA, SB, SC, SD) EXPN( 0) ROUND2(SD, SE, SA, SB, SC) EXPN( 1) ROUND2(SC, SD, SE, SA, SB) EXPN( 2) ROUND2(SB, SC, SD, SE, SA) EXPN( 3) ROUND2(SA, SB, SC, SD, SE) EXPN( 4) ROUND2(SE, SA, SB, SC, SD) EXPN( 5) ROUND2(SD, SE, SA, SB, SC) EXPN( 6) ROUND2(SC, SD, SE, SA, SB) EXPN( 7) ROUND2(SB, SC, SD, SE, SA) ldr K, .LK3 EXPN( 8) ROUND3(SA, SB, SC, SD, SE) EXPN( 9) ROUND3(SE, SA, SB, SC, SD) EXPN(10) ROUND3(SD, SE, SA, SB, SC) EXPN(11) ROUND3(SC, SD, SE, SA, SB) EXPN(12) ROUND3(SB, SC, SD, SE, SA) EXPN(13) ROUND3(SA, SB, SC, SD, SE) EXPN(14) ROUND3(SE, SA, SB, SC, SD) EXPN(15) ROUND3(SD, SE, SA, SB, SC) EXPN( 0) ROUND3(SC, SD, SE, SA, SB) EXPN( 1) ROUND3(SB, SC, SD, SE, SA) EXPN( 2) ROUND3(SA, SB, SC, SD, SE) EXPN( 3) ROUND3(SE, SA, SB, SC, SD) EXPN( 4) ROUND3(SD, SE, SA, SB, SC) EXPN( 5) ROUND3(SC, SD, SE, SA, SB) EXPN( 6) ROUND3(SB, SC, SD, SE, SA) EXPN( 7) ROUND3(SA, SB, SC, SD, SE) EXPN( 8) ROUND3(SE, SA, SB, SC, SD) EXPN( 9) ROUND3(SD, SE, SA, SB, SC) EXPN(10) ROUND3(SC, SD, SE, SA, SB) EXPN(11) ROUND3(SB, SC, SD, SE, SA) ldr K, .LK4 EXPN(12) ROUND2(SA, SB, SC, SD, SE) EXPN(13) ROUND2(SE, SA, SB, SC, SD) EXPN(14) ROUND2(SD, SE, SA, SB, SC) EXPN(15) ROUND2(SC, SD, SE, SA, SB) EXPN( 0) ROUND2(SB, SC, SD, SE, SA) EXPN( 1) ROUND2(SA, SB, SC, SD, SE) EXPN( 2) ROUND2(SE, SA, SB, SC, SD) EXPN( 3) ROUND2(SD, SE, SA, SB, SC) EXPN( 4) ROUND2(SC, SD, SE, SA, SB) EXPN( 5) ROUND2(SB, SC, SD, SE, SA) EXPN( 6) ROUND2(SA, SB, SC, SD, SE) EXPN( 7) ROUND2(SE, SA, SB, SC, SD) EXPN( 8) ROUND2(SD, SE, SA, SB, SC) EXPN( 9) ROUND2(SC, SD, SE, SA, SB) EXPN(10) ROUND2(SB, SC, SD, SE, SA) EXPN(11) ROUND2(SA, SB, SC, SD, SE) EXPN(12) ROUND2(SE, SA, SB, SC, SD) EXPN(13) ROUND2(SD, SE, SA, SB, SC) EXPN(14) ROUND2(SC, SD, SE, SA, SB) EXPN(15) ROUND2(SB, SC, SD, SE, SA) C Use registers we no longer need. ldm STATE, {INPUT,T0,SHIFT,W,K} add SA, SA, INPUT add SB, SB, T0 add SC, SC, SHIFT add SD, SD, W add SE, SE, K add sp, sp, #64 stm STATE, {SA,SB,SC,SD,SE} pop {r4,r5,r6,r7,r8,r10,pc} EPILOGUE(_nettle_sha1_compress) .LK4: .int 0xCA62C1D6
; ; Small C+ Library Functions ; ; Renamed once more and rechristened for ANSIstdio ; ; This outputs a character to the console ; ; 1/4/2000 (Original Aug 98) ; ; ; ; $Id: fputc_cons.asm,v 1.9 2016-07-02 13:52:45 dom Exp $ ; INCLUDE "stdio.def" MODULE fputc_cons_native SECTION code_clib PUBLIC fputc_cons_native ;Print char .fputc_cons_native ld hl,2 add hl,sp ld a,(hl) IF STANDARDESCAPECHARS cp 10 ELSE cp 13 ENDIF jr z,putchar1 call_oz(os_out) ;preserves ix ld l,a ld h,0 ret .putchar1 call_oz(gn_nln) ;preserves ix IF STANDARDESCAPECHARS ld hl,10 ELSE ld hl,13 ENDIF ret
; A127835: (Order of Galois group of Chebyshev polynomial)/(order of polynomial); or A124827(n)/n. ; Submitted by Jon Maiga ; 1,1,2,2,4,2,6,2,6,4,10,4,12,6,8,4,16,6,18,8,12 add $0,1 mov $1,1 lpb $0 mov $3,$0 lpb $3 mov $4,$0 mov $6,$2 cmp $6,0 add $2,$6 mod $4,$2 cmp $4,0 cmp $4,0 mov $5,$2 add $2,1 cmp $5,1 max $4,$5 sub $3,$4 lpe mov $5,1 mov $7,1 lpb $0 dif $0,$2 pow $2,$7 mul $5,$2 lpb $7 sub $5,2 trn $7,3 lpe add $5,1 mul $1,$5 trn $7,8 lpe lpe mov $0,$1
;reverse a string section .data msg1 : db 'Enter string : ' l1 : equ $-msg1 msg2 : db 'Reversed string is : ' l2 : equ $-msg2 newline : db 10 section .bss string : resb 50 str_len : resb 1 temp : resb 1 section .text global _start: _start: mov eax, 4 mov ebx, 1 mov ecx, msg1 mov edx, l1 int 80h mov ebx, string mov byte[str_len], 0 reading: push ebx mov eax, 3 mov ebx, 0 mov ecx, temp mov edx, 1 int 80h pop ebx cmp byte[temp], 10 je end_reading inc byte[str_len] mov al, byte[temp] mov byte[ebx], al inc ebx jmp reading end_reading: mov byte[ebx], 0 mov ebx, string mov eax, 0 movzx edx, byte[str_len] dec edx reverse: mov ch, byte[ebx + eax] mov cl, byte[ebx + edx] mov byte[ebx + eax], cl mov byte[ebx + edx], ch cmp eax, edx jnb print inc eax dec edx jmp reverse print: mov ebx, string print_loop: cmp byte[ebx], 0 je end_print ;assign temp the char in ebx mov al, byte[ebx] mov byte[temp], al push ebx mov eax, 4 mov ebx, 1 mov ecx, temp mov edx, 1 int 80h pop ebx inc ebx jmp print_loop end_print: mov eax, 4 mov ebx, 1 mov ecx, newline mov edx, 1 int 80h mov eax, 1 mov ebx, 0 int 80h
%define BE(a) ( ((((a)>>24)&0xFF) << 0) + ((((a)>>16)&0xFF) << 8) + ((((a)>>8)&0xFF) << 16) + ((((a)>>0)&0xFF) << 24)) ftyp_start: dd BE(ftyp_end - ftyp_start) dd "ftyp" db 0x61, 0x76, 0x69, 0x66 ; brand(32) ('avif') db 0x00, 0x00, 0x00, 0x00 ; version(32) db 0x61, 0x76, 0x69, 0x66 ; compatible_brand(32) ('avif') db 0x6D, 0x69, 0x66, 0x31 ; compatible_brand(32) ('mif1') db 0x6D, 0x69, 0x61, 0x66 ; compatible_brand(32) ('miaf') db 0x4D, 0x41, 0x31, 0x41 ; compatible_brand(32) ('MA1A') ftyp_end: meta_start: dd BE(meta_end - meta_start) dd "meta" db 0x00 ; version(8) db 0x00, 0x00, 0x00 ; flags(24) hdlr_start: dd BE(hdlr_end - hdlr_start) dd "hdlr" db 0x00 ; version(8) db 0x00, 0x00, 0x00 ; flags(24) db 0x00, 0x00, 0x00, 0x00 ; pre_defined(32) db 0x70, 0x69, 0x63, 0x74 ; handler_type(32) ('pict') db 0x00, 0x00, 0x00, 0x00 ; reserved1(32) db 0x00, 0x00, 0x00, 0x00 ; reserved2(32) db 0x00, 0x00, 0x00, 0x00 ; reserved3(32) db 0x6C ; name(8) ('l') db 0x69 ; name(8) ('i') db 0x62 ; name(8) ('b') db 0x61 ; name(8) ('a') db 0x76 ; name(8) ('v') db 0x69 ; name(8) ('i') db 0x66 ; name(8) ('f') db 0x00 ; name(8) hdlr_end: pitm_start: dd BE(pitm_end - pitm_start) dd "pitm" db 0x00 ; version(8) db 0x00, 0x00, 0x00 ; flags(24) db 0x00, 0x01 ; item_ID(16) pitm_end: iloc_start: dd BE(iloc_end - iloc_start) dd "iloc" db 0x00 ; version(8) db 0x00, 0x00, 0x00 ; flags(24) db 0x44 ; offset_size(4) ('D') length_size(4) ('D') db 0x00 ; base_offset_size(4) reserved1(4) db 0x00, 0x01 ; item_count(16) db 0x00, 0x01 ; item_ID(16) db 0x00, 0x00 ; data_reference_index(16) ; base_offset(0) db 0x00, 0x01 ; extent_count(16) dd BE(mdat_start - ftyp_start + 8) ; extent_offset(32) db 0x00, 0x00, 0x00, 0x00 ; extent_length(32) iloc_end: iinf_start: dd BE(iinf_end - iinf_start) dd "iinf" db 0x00 ; version(8) db 0x00, 0x00, 0x00 ; flags(24) db 0x00, 0x01 ; entry_count(16) infe_start: dd BE(infe_end - infe_start) dd "infe" db 0x02 ; version(8) db 0x00, 0x00, 0x00 ; flags(24) db 0x00, 0x01 ; item_ID(16) db 0x00, 0x00 ; item_protection_index(16) db 0x61, 0x76, 0x30, 0x31 ; item_type(32) ('av01') db 0x43 ; item_name(8) ('C') db 0x6F ; item_name(8) ('o') db 0x6C ; item_name(8) ('l') db 0x6F ; item_name(8) ('o') db 0x72 ; item_name(8) ('r') db 0x00 ; item_name(8) infe_end: iinf_end: iprp_start: dd BE(iprp_end - iprp_start) dd "iprp" ipco_start: dd BE(ipco_end - ipco_start) dd "ipco" ispe_start: dd BE(ispe_end - ispe_start) dd "ispe" db 0x00 ; version(8) db 0x00, 0x00, 0x00 ; flags(24) db 0x00, 0x00, 0x00, 0x64 ; image_width(32) db 0x00, 0x00, 0x00, 0x64 ; image_height(32) ispe_end: colr_start: dd BE(colr_end - colr_start) dd "colr" db 0x6E ; (8) ('n') db 0x63 ; (8) ('c') db 0x6C ; (8) ('l') db 0x78 ; (8) ('x') db 0x00 ; (8) db 0x01 ; (8) db 0x00 ; (8) db 0x04 ; (8) db 0x00 ; (8) db 0x01 ; (8) db 0x80 ; (8) colr_end: pixi_start: dd BE(pixi_end - pixi_start) dd "pixi" db 0x00 ; (8) db 0x00 ; (8) db 0x00 ; (8) db 0x00 ; (8) db 0x03 ; (8) db 0x08 ; (8) db 0x08 ; (8) db 0x08 ; (8) pixi_end: av1C_start: dd BE(av1C_end - av1C_start) dd "av1C" db 0x81 ; marker(1) version(7) db 0x2D ; seq_profile(3) ('-') seq_level_idx_0(5) ('-') db 0x00 ; seq_tier_0(1) high_bitdepth(1) twelve_bit(1) monochrome(1) chroma_subsampling_x(1) chroma_subsampling_y(1) chroma_sample_position(2) db 0x00 ; reserved(3) initial_presentation_delay_present(1) reserved(4) ; configOBUs(0) av1C_end: ipco_end: ipma_start: dd BE(ipma_end - ipma_start) dd "ipma" db 0x00 ; version(8) db 0x00, 0x00, 0x01 ; flags(24) db 0x00, 0x00, 0x00, 0x01 ; entry_count(32) db 0x00, 0x01 ; item_ID(16) db 0x04 ; association_count(8) db 0x00, 0x01 ; essential(1) property_index(15) db 0x00, 0x02 ; essential(1) property_index(15) db 0x00, 0x03 ; essential(1) property_index(15) db 0x00, 0x04 ; essential(1) property_index(15) ipma_end: iprp_end: meta_end: mdat_start: dd BE(mdat_end - mdat_start) db "mdat" db 0x00 mdat_end: ; vim: syntax=nasm
; Listing generated by Microsoft (R) Optimizing Compiler Version 17.00.50727.1 include listing.inc INCLUDELIB LIBCMT INCLUDELIB OLDNAMES CONST SEGMENT $SG3516 DB 'dev', 00H CONST ENDS PUBLIC ?sys_open_file@@YAHPEADPEAU_file_@@@Z ; sys_open_file PUBLIC ?sys_read_file@@YAXHPEAEPEAU_file_@@@Z ; sys_read_file PUBLIC ?sys_write_file@@YAXHPEAEPEAU_file_@@@Z ; sys_write_file EXTRN ?strcmp@@YAHPEBD0@Z:PROC ; strcmp EXTRN ?strchr@@YAPEADPEADH@Z:PROC ; strchr EXTRN ?vfs_finddir@@YAPEAU_vfs_node_@@PEAD@Z:PROC ; vfs_finddir EXTRN ?openfs@@YA?AU_vfs_node_@@PEAU1@PEAD@Z:PROC ; openfs EXTRN ?readfs@@YAXPEAU_vfs_node_@@0PEAEI@Z:PROC ; readfs EXTRN ?writefs@@YAXPEAU_vfs_node_@@0PEAEI@Z:PROC ; writefs EXTRN x64_cli:PROC EXTRN ?get_current_thread@@YAPEAU_thread_@@XZ:PROC ; get_current_thread pdata SEGMENT $pdata$?sys_open_file@@YAHPEADPEAU_file_@@@Z DD imagerel $LN12 DD imagerel $LN12+535 DD imagerel $unwind$?sys_open_file@@YAHPEADPEAU_file_@@@Z $pdata$?sys_read_file@@YAXHPEAEPEAU_file_@@@Z DD imagerel $LN6 DD imagerel $LN6+286 DD imagerel $unwind$?sys_read_file@@YAXHPEAEPEAU_file_@@@Z $pdata$?sys_write_file@@YAXHPEAEPEAU_file_@@@Z DD imagerel $LN6 DD imagerel $LN6+286 DD imagerel $unwind$?sys_write_file@@YAXHPEAEPEAU_file_@@@Z pdata ENDS xdata SEGMENT $unwind$?sys_open_file@@YAHPEADPEAU_file_@@@Z DD 041301H DD 0350113H DD 0600b700cH $unwind$?sys_read_file@@YAXHPEAEPEAU_file_@@@Z DD 021501H DD 0150115H $unwind$?sys_write_file@@YAXHPEAEPEAU_file_@@@Z DD 021501H DD 0150115H xdata ENDS ; Function compile flags: /Odtpy ; File e:\xeneva project\xeneva\aurora\aurora\sysserv\sysfile.cpp _TEXT SEGMENT node$ = 32 file$ = 48 fd$ = 176 buffer$ = 184 ufile$ = 192 ?sys_write_file@@YAXHPEAEPEAU_file_@@@Z PROC ; sys_write_file ; 127 : void sys_write_file (int fd, unsigned char* buffer, FILE *ufile) { $LN6: mov QWORD PTR [rsp+24], r8 mov QWORD PTR [rsp+16], rdx mov DWORD PTR [rsp+8], ecx sub rsp, 168 ; 000000a8H ; 128 : x64_cli(); call x64_cli ; 129 : ; 130 : vfs_node_t file; ; 131 : file.size = ufile->size; mov rax, QWORD PTR ufile$[rsp] mov eax, DWORD PTR [rax+4] mov DWORD PTR file$[rsp+32], eax ; 132 : file.eof = ufile->eof; mov rax, QWORD PTR ufile$[rsp] mov eax, DWORD PTR [rax+8] mov DWORD PTR file$[rsp+36], eax ; 133 : file.pos = ufile->pos; mov rax, QWORD PTR ufile$[rsp] mov eax, DWORD PTR [rax+12] mov DWORD PTR file$[rsp+40], eax ; 134 : file.current = ufile->start_cluster; mov rax, QWORD PTR ufile$[rsp] mov eax, DWORD PTR [rax+16] mov DWORD PTR file$[rsp+44], eax ; 135 : file.flags = ufile->flags; mov rax, QWORD PTR ufile$[rsp] mov eax, DWORD PTR [rax+20] mov DWORD PTR file$[rsp+48], eax ; 136 : file.status = ufile->status; mov rax, QWORD PTR ufile$[rsp] mov eax, DWORD PTR [rax+24] mov DWORD PTR file$[rsp+52], eax ; 137 : file.open = 0; mov QWORD PTR file$[rsp+64], 0 ; 138 : file.read = 0; mov QWORD PTR file$[rsp+72], 0 ; 139 : file.read_blk = 0; mov QWORD PTR file$[rsp+88], 0 ; 140 : file.write = 0; mov QWORD PTR file$[rsp+80], 0 ; 141 : file.ioquery = 0; mov QWORD PTR file$[rsp+96], 0 ; 142 : ; 143 : vfs_node_t *node = get_current_thread()->fd[fd]; call ?get_current_thread@@YAPEAU_thread_@@XZ ; get_current_thread movsxd rcx, DWORD PTR fd$[rsp] mov rax, QWORD PTR [rax+rcx*8+272] mov QWORD PTR node$[rsp], rax ; 144 : if (node == NULL) cmp QWORD PTR node$[rsp], 0 jne SHORT $LN3@sys_write_ ; 145 : return; jmp SHORT $LN4@sys_write_ $LN3@sys_write_: ; 146 : ; 147 : if (ufile->flags) mov rax, QWORD PTR ufile$[rsp] cmp DWORD PTR [rax+20], 0 je SHORT $LN2@sys_write_ ; 148 : writefs(node, &file,buffer,file.size); mov r9d, DWORD PTR file$[rsp+32] mov r8, QWORD PTR buffer$[rsp] lea rdx, QWORD PTR file$[rsp] mov rcx, QWORD PTR node$[rsp] call ?writefs@@YAXPEAU_vfs_node_@@0PEAEI@Z ; writefs ; 149 : else jmp SHORT $LN1@sys_write_ $LN2@sys_write_: ; 150 : writefs(node, node, buffer,file.size); mov r9d, DWORD PTR file$[rsp+32] mov r8, QWORD PTR buffer$[rsp] mov rdx, QWORD PTR node$[rsp] mov rcx, QWORD PTR node$[rsp] call ?writefs@@YAXPEAU_vfs_node_@@0PEAEI@Z ; writefs $LN1@sys_write_: $LN4@sys_write_: ; 151 : } add rsp, 168 ; 000000a8H ret 0 ?sys_write_file@@YAXHPEAEPEAU_file_@@@Z ENDP ; sys_write_file _TEXT ENDS ; Function compile flags: /Odtpy ; File e:\xeneva project\xeneva\aurora\aurora\sysserv\sysfile.cpp _TEXT SEGMENT node$ = 32 file$ = 48 fd$ = 176 buffer$ = 184 ufile$ = 192 ?sys_read_file@@YAXHPEAEPEAU_file_@@@Z PROC ; sys_read_file ; 95 : void sys_read_file (int fd, unsigned char* buffer, FILE *ufile) { $LN6: mov QWORD PTR [rsp+24], r8 mov QWORD PTR [rsp+16], rdx mov DWORD PTR [rsp+8], ecx sub rsp, 168 ; 000000a8H ; 96 : x64_cli (); call x64_cli ; 97 : vfs_node_t file; ; 98 : file.size = ufile->size; mov rax, QWORD PTR ufile$[rsp] mov eax, DWORD PTR [rax+4] mov DWORD PTR file$[rsp+32], eax ; 99 : file.eof = ufile->eof; mov rax, QWORD PTR ufile$[rsp] mov eax, DWORD PTR [rax+8] mov DWORD PTR file$[rsp+36], eax ; 100 : file.pos = ufile->pos; mov rax, QWORD PTR ufile$[rsp] mov eax, DWORD PTR [rax+12] mov DWORD PTR file$[rsp+40], eax ; 101 : file.current = ufile->start_cluster; mov rax, QWORD PTR ufile$[rsp] mov eax, DWORD PTR [rax+16] mov DWORD PTR file$[rsp+44], eax ; 102 : file.flags = ufile->flags; mov rax, QWORD PTR ufile$[rsp] mov eax, DWORD PTR [rax+20] mov DWORD PTR file$[rsp+48], eax ; 103 : file.status = ufile->status; mov rax, QWORD PTR ufile$[rsp] mov eax, DWORD PTR [rax+24] mov DWORD PTR file$[rsp+52], eax ; 104 : file.open = 0; mov QWORD PTR file$[rsp+64], 0 ; 105 : file.read = 0; mov QWORD PTR file$[rsp+72], 0 ; 106 : file.read_blk = 0; mov QWORD PTR file$[rsp+88], 0 ; 107 : file.write = 0; mov QWORD PTR file$[rsp+80], 0 ; 108 : file.ioquery = 0; mov QWORD PTR file$[rsp+96], 0 ; 109 : ; 110 : vfs_node_t *node = get_current_thread()->fd[fd]; call ?get_current_thread@@YAPEAU_thread_@@XZ ; get_current_thread movsxd rcx, DWORD PTR fd$[rsp] mov rax, QWORD PTR [rax+rcx*8+272] mov QWORD PTR node$[rsp], rax ; 111 : if (node == NULL) cmp QWORD PTR node$[rsp], 0 jne SHORT $LN3@sys_read_f ; 112 : return; jmp SHORT $LN4@sys_read_f $LN3@sys_read_f: ; 113 : ; 114 : if (ufile->flags > 0){ mov rax, QWORD PTR ufile$[rsp] cmp DWORD PTR [rax+20], 0 jbe SHORT $LN2@sys_read_f ; 115 : readfs(node,&file,buffer,file.size); mov r9d, DWORD PTR file$[rsp+32] mov r8, QWORD PTR buffer$[rsp] lea rdx, QWORD PTR file$[rsp] mov rcx, QWORD PTR node$[rsp] call ?readfs@@YAXPEAU_vfs_node_@@0PEAEI@Z ; readfs ; 116 : }else { jmp SHORT $LN1@sys_read_f $LN2@sys_read_f: ; 117 : readfs(node, node, buffer, file.size); mov r9d, DWORD PTR file$[rsp+32] mov r8, QWORD PTR buffer$[rsp] mov rdx, QWORD PTR node$[rsp] mov rcx, QWORD PTR node$[rsp] call ?readfs@@YAXPEAU_vfs_node_@@0PEAEI@Z ; readfs $LN1@sys_read_f: $LN4@sys_read_f: ; 118 : } ; 119 : } add rsp, 168 ; 000000a8H ret 0 ?sys_read_file@@YAXHPEAEPEAU_file_@@@Z ENDP ; sys_read_file _TEXT ENDS ; Function compile flags: /Odtpy ; File e:\xeneva project\xeneva\aurora\aurora\sysserv\sysfile.cpp _TEXT SEGMENT i$ = 32 fd$ = 36 p$ = 40 node$ = 48 tv136 = 56 tv93 = 64 pathname$ = 72 file$1 = 96 $T2 = 208 $T3 = 312 filename$ = 448 ufile$ = 456 ?sys_open_file@@YAHPEADPEAU_file_@@@Z PROC ; sys_open_file ; 47 : int sys_open_file (char* filename, FILE *ufile) { $LN12: mov QWORD PTR [rsp+16], rdx mov QWORD PTR [rsp+8], rcx push rsi push rdi sub rsp, 424 ; 000001a8H ; 48 : x64_cli(); call x64_cli ; 49 : char* p = strchr (filename, '/'); mov edx, 47 ; 0000002fH mov rcx, QWORD PTR filename$[rsp] call ?strchr@@YAPEADPEADH@Z ; strchr mov QWORD PTR p$[rsp], rax ; 50 : if (p) cmp QWORD PTR p$[rsp], 0 je SHORT $LN9@sys_open_f ; 51 : p++; mov rax, QWORD PTR p$[rsp] inc rax mov QWORD PTR p$[rsp], rax $LN9@sys_open_f: ; 52 : ; 53 : ; 54 : char pathname[16]; ; 55 : int i; ; 56 : for (i = 0; i < 16; i++) { mov DWORD PTR i$[rsp], 0 jmp SHORT $LN8@sys_open_f $LN7@sys_open_f: mov eax, DWORD PTR i$[rsp] inc eax mov DWORD PTR i$[rsp], eax $LN8@sys_open_f: cmp DWORD PTR i$[rsp], 16 jge SHORT $LN6@sys_open_f ; 57 : if ( p[i] == '/' || p[i] == '\0') movsxd rax, DWORD PTR i$[rsp] mov rcx, QWORD PTR p$[rsp] movsx eax, BYTE PTR [rcx+rax] cmp eax, 47 ; 0000002fH je SHORT $LN4@sys_open_f movsxd rax, DWORD PTR i$[rsp] mov rcx, QWORD PTR p$[rsp] movsx eax, BYTE PTR [rcx+rax] test eax, eax jne SHORT $LN5@sys_open_f $LN4@sys_open_f: ; 58 : break; jmp SHORT $LN6@sys_open_f $LN5@sys_open_f: ; 59 : pathname[i] = p[i]; movsxd rax, DWORD PTR i$[rsp] movsxd rcx, DWORD PTR i$[rsp] mov rdx, QWORD PTR p$[rsp] movzx eax, BYTE PTR [rdx+rax] mov BYTE PTR pathname$[rsp+rcx], al ; 60 : } jmp SHORT $LN7@sys_open_f $LN6@sys_open_f: ; 61 : ; 62 : pathname[i] = 0; movsxd rax, DWORD PTR i$[rsp] mov BYTE PTR pathname$[rsp+rax], 0 ; 63 : ; 64 : int fd = -1; mov DWORD PTR fd$[rsp], -1 ; 65 : vfs_node_t *node = vfs_finddir(filename); mov rcx, QWORD PTR filename$[rsp] call ?vfs_finddir@@YAPEAU_vfs_node_@@PEAD@Z ; vfs_finddir mov QWORD PTR node$[rsp], rax ; 66 : if (node) { cmp QWORD PTR node$[rsp], 0 je SHORT $LN3@sys_open_f ; 67 : get_current_thread()->fd[get_current_thread()->fd_current] = node; call ?get_current_thread@@YAPEAU_thread_@@XZ ; get_current_thread mov QWORD PTR tv93[rsp], rax call ?get_current_thread@@YAPEAU_thread_@@XZ ; get_current_thread movsxd rax, DWORD PTR [rax+752] mov rcx, QWORD PTR node$[rsp] mov rdx, QWORD PTR tv93[rsp] mov QWORD PTR [rdx+rax*8+272], rcx ; 68 : fd = get_current_thread()->fd_current; call ?get_current_thread@@YAPEAU_thread_@@XZ ; get_current_thread mov eax, DWORD PTR [rax+752] mov DWORD PTR fd$[rsp], eax ; 69 : get_current_thread()->fd_current++; call ?get_current_thread@@YAPEAU_thread_@@XZ ; get_current_thread add rax, 752 ; 000002f0H mov QWORD PTR tv136[rsp], rax mov rax, QWORD PTR tv136[rsp] mov eax, DWORD PTR [rax] inc eax mov rcx, QWORD PTR tv136[rsp] mov DWORD PTR [rcx], eax $LN3@sys_open_f: ; 70 : } ; 71 : ; 72 : if (!(strcmp(pathname, "dev") == 0)) { lea rdx, OFFSET FLAT:$SG3516 lea rcx, QWORD PTR pathname$[rsp] call ?strcmp@@YAHPEBD0@Z ; strcmp test eax, eax je $LN2@sys_open_f ; 73 : vfs_node_t file = openfs(node, filename); mov r8, QWORD PTR filename$[rsp] mov rdx, QWORD PTR node$[rsp] lea rcx, QWORD PTR $T3[rsp] call ?openfs@@YA?AU_vfs_node_@@PEAU1@PEAD@Z ; openfs lea rcx, QWORD PTR $T2[rsp] mov rdi, rcx mov rsi, rax mov ecx, 104 ; 00000068H rep movsb lea rax, QWORD PTR file$1[rsp] lea rcx, QWORD PTR $T2[rsp] mov rdi, rax mov rsi, rcx mov ecx, 104 ; 00000068H rep movsb ; 74 : if (ufile) { cmp QWORD PTR ufile$[rsp], 0 je SHORT $LN1@sys_open_f ; 75 : ufile->id = fd; mov rax, QWORD PTR ufile$[rsp] mov ecx, DWORD PTR fd$[rsp] mov DWORD PTR [rax], ecx ; 76 : ufile->size = file.size; mov rax, QWORD PTR ufile$[rsp] mov ecx, DWORD PTR file$1[rsp+32] mov DWORD PTR [rax+4], ecx ; 77 : ufile->eof = file.eof; mov rax, QWORD PTR ufile$[rsp] mov ecx, DWORD PTR file$1[rsp+36] mov DWORD PTR [rax+8], ecx ; 78 : ufile->pos = file.pos; mov rax, QWORD PTR ufile$[rsp] mov ecx, DWORD PTR file$1[rsp+40] mov DWORD PTR [rax+12], ecx ; 79 : ufile->start_cluster = file.current; mov rax, QWORD PTR ufile$[rsp] mov ecx, DWORD PTR file$1[rsp+44] mov DWORD PTR [rax+16], ecx ; 80 : ufile->flags = file.flags; mov rax, QWORD PTR ufile$[rsp] mov ecx, DWORD PTR file$1[rsp+48] mov DWORD PTR [rax+20], ecx ; 81 : ufile->status = file.status; mov rax, QWORD PTR ufile$[rsp] mov ecx, DWORD PTR file$1[rsp+52] mov DWORD PTR [rax+24], ecx $LN1@sys_open_f: $LN2@sys_open_f: ; 82 : } ; 83 : } ; 84 : ; 85 : //! return the allocated fd number ; 86 : return fd; mov eax, DWORD PTR fd$[rsp] ; 87 : } add rsp, 424 ; 000001a8H pop rdi pop rsi ret 0 ?sys_open_file@@YAHPEADPEAU_file_@@@Z ENDP ; sys_open_file _TEXT ENDS END
; A147612: If n is a Jacobsthal number then 1 else 0. ; 1,1,0,1,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 mov $11,$0 mov $13,2 lpb $13 clr $0,11 mov $0,$11 sub $13,1 add $0,$13 sub $0,1 mov $5,$0 mul $5,3 trn $5,1 add $6,2 add $6,$5 log $6,2 mov $1,$6 mov $14,$13 lpb $14 mov $12,$1 sub $14,1 lpe lpe lpb $11 mov $11,0 sub $12,$1 lpe mov $1,$12
; void __CALLEE__ sp1_GetTiles_callee(struct sp1_Rect *r, struct sp1_tp *dest) SECTION code_clib SECTION code_temp_sp1 PUBLIC sp1_GetTiles_callee EXTERN asm_sp1_GetTiles sp1_GetTiles_callee: pop af pop hl ex (sp),hl ld d,(hl) inc hl ld e,(hl) inc hl ld b,(hl) inc hl ld c,(hl) pop hl push af jp asm_sp1_GetTiles
; A154252: Expansion of (1-x+8x^2)/((1-x)(1-2x)) . ; 1,2,12,32,72,152,312,632,1272,2552,5112,10232,20472,40952,81912,163832,327672,655352,1310712,2621432,5242872,10485752,20971512,41943032,83886072,167772152,335544312,671088632,1342177272,2684354552,5368709112,10737418232,21474836472,42949672952,85899345912,171798691832,343597383672,687194767352,1374389534712,2748779069432,5497558138872,10995116277752,21990232555512,43980465111032,87960930222072,175921860444152,351843720888312,703687441776632,1407374883553272,2814749767106552,5629499534213112,11258999068426232,22517998136852472,45035996273704952,90071992547409912,180143985094819832,360287970189639672,720575940379279352,1441151880758558712,2882303761517117432,5764607523034234872,11529215046068469752,23058430092136939512,46116860184273879032,92233720368547758072,184467440737095516152,368934881474191032312,737869762948382064632,1475739525896764129272,2951479051793528258552,5902958103587056517112,11805916207174113034232,23611832414348226068472,47223664828696452136952,94447329657392904273912,188894659314785808547832,377789318629571617095672,755578637259143234191352,1511157274518286468382712,3022314549036572936765432,6044629098073145873530872,12089258196146291747061752,24178516392292583494123512,48357032784585166988247032,96714065569170333976494072,193428131138340667952988152,386856262276681335905976312,773712524553362671811952632,1547425049106725343623905272,3094850098213450687247810552,6189700196426901374495621112,12379400392853802748991242232,24758800785707605497982484472,49517601571415210995964968952,99035203142830421991929937912,198070406285660843983859875832,396140812571321687967719751672,792281625142643375935439503352,1584563250285286751870879006712,3169126500570573503741758013432 seq $0,48487 ; a(n) = T(4,n), array T given by A048483. trn $0,5 add $0,1
/* * Copyright © <2010>, Intel Corporation. * * This program is licensed under the terms and conditions of the * Eclipse Public License (EPL), version 1.0. The full text of the EPL is at * http://www.opensource.org/licenses/eclipse-1.0.php. * */ // Module name: WriteURB.asm // // General purpose module to write data to URB using the URB handle/offset in r0 // //---------------------------------------------------------------- // Assume: // - a0.0 and a0.1 is meg desc, has been assign with URB offset and msg size // - MRFs are alrady assigned with data. //---------------------------------------------------------------- // // 16x16 byte pixel block can be saved using just 1 "send" instruction. #if defined(_DEBUG) mov (1) EntrySignature:w 0x3535:w #endif // URB write header: //mov (8) MSGSRC.0:ud r0.0<8;8,1>:ud // Copy parent R0 header //shr (1) Temp2_W:uw URBOffset:uw 1:w // divide by 2, because URB entry is counted by 512bits. Offset is counted by 256bits. //add (1) MSGSRC.0:uw r0.0:uw Temp2_W:uw shr (1) MSGSRC.0:uw URBOffset:uw 1:w // divide by 2, because URB entry is counted by 512bits. Offset is counted by 256bits. //mov (1) MSGSRC.0:uw URBOffset_2:uw //mov (1) MSGSRC.1:ud 0:ud // Reset Handle 1 send null:uw m0 MSGSRC<8;8,1>:uw URBWRITE URBWriteMsgDesc:ud // URB write //send null:ud MRF0 null:ud URBWriteMsgDesc:ud // URB write
/* * Editor UI property grid builder file * * This file is part of the "ForkENGINE" (Copyright (c) 2014 by Lukas Hermanns) * See "LICENSE.txt" for license information. */ #include "UIPropertyGridBuilder.h" #include "../../Core/UIExtensions/UIPropertyGrid.h" #include "../../Language/LanguageLoader.h" namespace Fork { namespace Editor { UIPropertyGridBuilder::UIPropertyGridBuilder(UIPropertyGrid& propGrid) : propGrid_{ &propGrid } { } void UIPropertyGridBuilder::InitCategory(const StringID labelStringID, const std::string& namePrefix) { namePrefix_ = namePrefix; keyCounter_ = 0; propGrid_->AddPropertyCategory(Language::String(labelStringID), namePrefix_); } /* --- Properties --- */ void UIPropertyGridBuilder::Bool(const StringID labelStringID) { propGrid_->AddBoolProperty(Language::String(labelStringID), NextPropID()); } void UIPropertyGridBuilder::Float(const StringID labelStringID) { propGrid_->AddFloatProperty(Language::String(labelStringID), NextPropID()); } void UIPropertyGridBuilder::Int(const StringID labelStringID, bool hasSpin) { propGrid_->AddIntProperty(Language::String(labelStringID), NextPropID(), 0, hasSpin); } void UIPropertyGridBuilder::Int(const StringID labelStringID, long minRange, long maxRange, bool hasSpin) { propGrid_->AddIntProperty(Language::String(labelStringID), NextPropID(), 0, minRange, maxRange, hasSpin); } void UIPropertyGridBuilder::UInt(const StringID labelStringID) { propGrid_->AddUIntProperty(Language::String(labelStringID), NextPropID()); } void UIPropertyGridBuilder::ColorRGB(const StringID labelStringID) { propGrid_->AddColorRGBProperty(Language::String(labelStringID), NextPropID()); } void UIPropertyGridBuilder::ColorRGBA(const StringID labelStringID) { propGrid_->AddColorRGBAProperty(Language::String(labelStringID), NextPropID()); } void UIPropertyGridBuilder::SystemColor(const StringID labelStringID) { propGrid_->AddSystemColorProperty(Language::String(labelStringID), NextPropID()); } void UIPropertyGridBuilder::Enum(const StringID labelStringID, wxPGChoices& choices) { propGrid_->AddEnumProperty(Language::String(labelStringID), NextPropID(), choices); } void UIPropertyGridBuilder::Enum(const StringID labelStringID) { propGrid_->AddEnumProperty(Language::String(labelStringID), NextPropID()); } void UIPropertyGridBuilder::String(const StringID labelStringID) { propGrid_->AddStringProperty(Language::String(labelStringID), NextPropID()); } void UIPropertyGridBuilder::LongString(const StringID labelStringID) { propGrid_->AddLongStringProperty(Language::String(labelStringID), NextPropID()); } void UIPropertyGridBuilder::ArrayString(const StringID labelStringID) { propGrid_->AddArrayStringProperty(Language::String(labelStringID), NextPropID()); } void UIPropertyGridBuilder::File(const StringID labelStringID) { propGrid_->AddFileProperty(Language::String(labelStringID), NextPropID()); } void UIPropertyGridBuilder::Dir(const StringID labelStringID) { propGrid_->AddDirProperty(Language::String(labelStringID), NextPropID()); } void UIPropertyGridBuilder::Vector3(const StringID labelStringID) { propGrid_->AddVector3Property(Language::String(labelStringID), NextPropID()); } void UIPropertyGridBuilder::Vector4(const StringID labelStringID) { propGrid_->AddVector4Property(Language::String(labelStringID), NextPropID()); } void UIPropertyGridBuilder::Asset(const StringID labelStringID) { propGrid_->AddStringProperty(Language::String(labelStringID), NextPropID()); } /* * ======= Private: ======= */ wxString UIPropertyGridBuilder::NextPropID() { return UIPropertyGrid::GetID(namePrefix_, keyCounter_++); } } // /namespace Editor } // /namespace Fork // ========================
INCLUDE "config_private.inc" SECTION smc_driver EXTERN asm_shadow_copy EXTERN asm_shadow_copy_end PUBLIC asm_shadow_relocate ; @feilipu November 2021 ; ; The RAM bank is toggled by outputting 0/1 to 0x0030 ; ; asm_shadow_copy is located in the DATA section and, for ROM builds, ; is copied to both main and shadow RAM banks during initialisation. ; ; The current location of asm_shadow_copy is maintained at base 0x0058. ; The C interfaces use this address to find the location this code. ; ; If desired, this code can be relocated wherever it suits the user. ; This can be done with the C shadow_relocate(void * addr) function, ; which will also update the base address. ; ; On entry: Interrupts disabled unless you know better ; HL = New address (in RAM) ; ; On exit: AF BC DE HL not specified ; IX IY AF' BC' DE' HL' preserved .asm_shadow_relocate ex de,hl ; destination to de push de ; save a copy of destination ld hl,shadow_relocate_continue ; save our return address after copy push hl ld hl,(__IO_RAM_SHADOW_BASE) ; location of stub push hl ; save for jp (__IO_RAM_SHADOW_BASE) ld bc,asm_shadow_copy_end-asm_shadow_copy ; size of stub or a ; write to shadow RAM ret ; copy it by jp (__IO_RAM_SHADOW_BASE) .shadow_relocate_continue pop de ; recover destination ld hl,(__IO_RAM_SHADOW_BASE) ; location of stub ld (__IO_RAM_SHADOW_BASE),de ; write new location to base ld bc,asm_shadow_copy_end-asm_shadow_copy ; size of stub ldir ; copy it ret
; A158620: Partial products of A068601. ; Submitted by Jon Maiga ; 7,182,11466,1421784,305683560,104543777520,53421870312720,38891121587660160,38852230466072499840,51673466519876424787200,89240076679826585607494400,195971208388899181994057702400,537549024610750456209700277683200,1813690409036672039251528736903116800,7427062225005172000735010177618263296000,36481729649225404867610369992460909309952000,212724965584633335783036067426039562186330112000,1458867813979415416800061350407779317473851908096000,11669483644021343918983690741911826760473341412859904000 mov $2,7 lpb $0 mov $1,$0 sub $0,1 add $1,2 pow $1,3 sub $1,1 mul $2,$1 lpe mov $0,$2
vs_3_0 dcl_position v0 dcl_position o0 dcl_position1 o1.xy dcl_position2 o2.xy mul r0, c0.xyxy, v0.xyyx add o0.xz, r0.yy, r0.xy mul r0, c1.xyxy, v0.xyyx add o0.yw, r0.xy, r0.xx mul r0.xy, c0.xy, v0.yx_abs add o1.x, r0.y, r0.x mul r0.xy, c1.xy, v0.yx_abs add o1.y, r0.y, r0.x add r0.xy, v0.xy, v0.xy mul r0.zw, r0.xy, c0.xy mul r0.xy, r0.xy, c1.xy add o2.y, r0.y, r0.x add o2.x, r0.w, r0.z
#pragma once #include <cmath> #include <cstdint> #include <iostream> #include <stdexcept> #include <string> #include <unordered_map> #include <vector> #include <Eigen/Geometry> #include <common_robotics_utilities/math.hpp> #include <common_robotics_utilities/serialization.hpp> #include <common_robotics_utilities/utility.hpp> #include <common_robotics_utilities/voxel_grid.hpp> namespace common_robotics_utilities { namespace voxel_grid { class ChunkRegion { private: Eigen::Vector4d base_ = Eigen::Vector4d(0.0, 0.0, 0.0, 1.0); public: EIGEN_MAKE_ALIGNED_OPERATOR_NEW static uint64_t Serialize( const ChunkRegion& region, std::vector<uint8_t>& buffer) { return serialization::SerializeVector4d(region.Base(), buffer); } static serialization::Deserialized<ChunkRegion> Deserialize( const std::vector<uint8_t>& buffer, const uint64_t starting_offset) { const auto base_deserialized = serialization::DeserializeVector4d(buffer, starting_offset); return serialization::MakeDeserialized( ChunkRegion(base_deserialized.Value()), base_deserialized.BytesRead()); } ChunkRegion() : base_(Eigen::Vector4d(0.0, 0.0, 0.0, 1.0)) {} ChunkRegion(const double base_x, const double base_y, const double base_z) : base_(Eigen::Vector4d(base_x, base_y, base_z, 1.0)) {} ChunkRegion(const Eigen::Vector3d& base) : base_(Eigen::Vector4d(base.x(), base.y(), base.z(), 1.0)) {} ChunkRegion(const Eigen::Vector4d& base) : base_(base) { if (base_(3) != 1.0) { throw std::invalid_argument("base(3) != 1"); } } const Eigen::Vector4d& Base() const { return base_; } bool operator==(const ChunkRegion& other) const { if (math::Equal4d(Base(), other.Base())) { return true; } else { return false; } } }; /// Enums to help us out. enum class DSHVGFillType : uint8_t {FILL_CHUNK, FILL_CELL}; enum class DSHVGFillStatus : uint8_t {NOT_FILLED, CHUNK_FILLED, CELL_FILLED}; enum class DSHVGFoundStatus {NOT_FOUND, FOUND_IN_CHUNK, FOUND_IN_CELL}; enum class DSHVGSetType {SET_CHUNK, SET_CELL}; enum class DSHVGSetStatus {NOT_SET, SET_CHUNK, SET_CELL}; // Forward-declare for use in GridQuery. template<typename T, typename BackingStore=std::vector<T>> class DynamicSpatialHashedVoxelGridChunk; template<typename T> class DynamicSpatialHashedGridQuery { private: template<typename Item, typename BackingStore> friend class DynamicSpatialHashedVoxelGridChunk; // This constructor is private because users should not be able to create // DynamicSpatialHashedGridQuery<T> with a value on their own, creation should // only be possible within a DynamicSpatialHashedVoxelGridBase<T> to which the // DynamicSpatialHashedGridQuery<T> references. DynamicSpatialHashedGridQuery(T& item, const DSHVGFoundStatus found_status) : item_ptr_(std::addressof(item)), found_status_(found_status) { if (HasValue() && (FoundStatus() == DSHVGFoundStatus::NOT_FOUND)) { throw std::invalid_argument("Cannot return value and NOT_FOUND together"); } } T* const item_ptr_ = nullptr; DSHVGFoundStatus found_status_ = DSHVGFoundStatus::NOT_FOUND; public: DynamicSpatialHashedGridQuery() : item_ptr_(nullptr), found_status_(DSHVGFoundStatus::NOT_FOUND) {} T& Value() { if (HasValue()) { return *item_ptr_; } else { throw std::runtime_error( "DynamicSpatialHashedGridQuery does not have value"); } } T& Value() const { if (HasValue()) { return *item_ptr_; } else { throw std::runtime_error( "DynamicSpatialHashedGridQuery does not have value"); } } DSHVGFoundStatus FoundStatus() const { return found_status_; } bool HasValue() const { return item_ptr_ != nullptr; } explicit operator bool() const { return HasValue(); } }; template<typename T, typename BackingStore> class DynamicSpatialHashedVoxelGridChunk { private: ChunkRegion region_; BackingStore data_; GridSizes sizes_; DSHVGFillStatus fill_status_ = DSHVGFillStatus::NOT_FILLED; int64_t GetLocationDataIndex(const Eigen::Vector4d& location) const { const Eigen::Vector4d location_wrt_chunk = location - region_.Base(); // First, make sure the location is in the range this chunk covers if (location_wrt_chunk(0) < 0.0 || location_wrt_chunk(1) < 0.0 || location_wrt_chunk(2) < 0.0 || location_wrt_chunk(0) >= sizes_.XSize() || location_wrt_chunk(1) >= sizes_.YSize() || location_wrt_chunk(2) >= sizes_.ZSize()) { return -1; } // Ok, we're inside the chunk else { const int64_t x_cell = static_cast<int64_t>(location_wrt_chunk(0) / sizes_.CellXSize()); const int64_t y_cell = static_cast<int64_t>(location_wrt_chunk(1) / sizes_.CellYSize()); const int64_t z_cell = static_cast<int64_t>(location_wrt_chunk(2) / sizes_.CellZSize()); if (x_cell < 0 || y_cell < 0 || z_cell < 0 || x_cell >= sizes_.NumXCells() || y_cell >= sizes_.NumYCells() || z_cell >= sizes_.NumZCells()) { return -1; } else { return sizes_.GetDataIndex(x_cell, y_cell, z_cell); } } } T& AccessIndex(const int64_t& data_index) { if ((data_index >= 0) && (data_index < static_cast<int64_t>(data_.size()))) { // Note: do not refactor to use .at(), since not all vector-like // implementations implement it (ex thrust::host_vector<T>). return data_[data_index]; } else { throw std::out_of_range("data_index out of range"); } } const T& AccessIndex(const int64_t& data_index) const { if ((data_index >= 0) && (data_index < static_cast<int64_t>(data_.size()))) { // Note: do not refactor to use .at(), since not all vector-like // implementations implement it (ex thrust::host_vector<T>). return data_[data_index]; } else { throw std::out_of_range("data_index out of range"); } } void SetCellFilledContents(const T& value) { data_.clear(); data_.resize(sizes_.TotalCells(), value); fill_status_ = DSHVGFillStatus::CELL_FILLED; } void SetChunkFilledContents(const T& value) { data_.clear(); data_.resize(1, value); fill_status_ = DSHVGFillStatus::CHUNK_FILLED; } public: EIGEN_MAKE_ALIGNED_OPERATOR_NEW static uint64_t Serialize( const DynamicSpatialHashedVoxelGridChunk<T, BackingStore>& chunk, std::vector<uint8_t>& buffer, const serialization::Serializer<T>& value_serializer) { return chunk.SerializeSelf(buffer, value_serializer); } static serialization::Deserialized< DynamicSpatialHashedVoxelGridChunk<T, BackingStore>> Deserialize( const std::vector<uint8_t>& buffer, const uint64_t starting_offset, const serialization::Deserializer<T>& value_deserializer) { DynamicSpatialHashedVoxelGridChunk<T, BackingStore> temp_chunk; const uint64_t bytes_read = temp_chunk.DeserializeSelf(buffer, starting_offset, value_deserializer); return serialization::MakeDeserialized(temp_chunk, bytes_read); } DynamicSpatialHashedVoxelGridChunk(const ChunkRegion& region, const GridSizes& sizes, const DSHVGFillType fill_type, const T& initial_value) : region_(region), sizes_(sizes) { if (sizes_.Valid()) { if (fill_type == DSHVGFillType::FILL_CELL) { SetCellFilledContents(initial_value); } else if (fill_type == DSHVGFillType::FILL_CHUNK) { SetChunkFilledContents(initial_value); } else { throw std::invalid_argument("Invalid fill_type"); } } else { throw std::invalid_argument("sizes is not valid"); } } DynamicSpatialHashedVoxelGridChunk() : fill_status_(DSHVGFillStatus::NOT_FILLED) {} uint64_t SerializeSelf( std::vector<uint8_t>& buffer, const serialization::Serializer<T>& value_serializer) const { const uint64_t start_buffer_size = buffer.size(); // Serialize the transform ChunkRegion::Serialize(region_, buffer); // Serialize the grid sizes GridSizes::Serialize(sizes_, buffer); // Serialize the data serialization::SerializeVectorLike<T, BackingStore>( data_, buffer, value_serializer); // Serialize the fill status serialization::SerializeMemcpyable<uint8_t>( static_cast<uint8_t>(fill_status_), buffer); // Figure out how many bytes were written const uint64_t end_buffer_size = buffer.size(); const uint64_t bytes_written = end_buffer_size - start_buffer_size; return bytes_written; } uint64_t DeserializeSelf( const std::vector<uint8_t>& buffer, const uint64_t starting_offset, const serialization::Deserializer<T>& value_deserializer) { uint64_t current_position = starting_offset; // Deserialize the transforms const auto region_deserialized = ChunkRegion::Deserialize(buffer, current_position); region_ = region_deserialized.Value(); current_position += region_deserialized.BytesRead(); // Deserialize the cell sizes const auto sizes_deserialized = GridSizes::Deserialize(buffer, current_position); sizes_ = sizes_deserialized.Value(); current_position += sizes_deserialized.BytesRead(); // Deserialize the data const auto data_deserialized = serialization::DeserializeVectorLike<T, BackingStore>( buffer, current_position, value_deserializer); data_ = data_deserialized.Value(); current_position += data_deserialized.BytesRead(); // Deserialize the fill status const auto fill_status_deserialized = serialization::DeserializeMemcpyable<uint8_t>(buffer, current_position); fill_status_ = static_cast<DSHVGFillStatus>(fill_status_deserialized.Value()); current_position += fill_status_deserialized.BytesRead(); // Safety checks if (fill_status_ == DSHVGFillStatus::CELL_FILLED) { if (static_cast<int64_t>(data_.size()) != sizes_.TotalCells()) { throw std::runtime_error("sizes_.NumCells() != data_.size()"); } } else if (fill_status_ == DSHVGFillStatus::CHUNK_FILLED) { if (data_.size() != 1) { throw std::runtime_error("sizes_.NumCells() != 1"); } } else { if (data_.size() != 0) { throw std::runtime_error("sizes_.NumCells() != 0"); } } // Figure out how many bytes were read const uint64_t bytes_read = current_position - starting_offset; return bytes_read; } DSHVGFillStatus FillStatus() const { return fill_status_; } DynamicSpatialHashedGridQuery<const T> GetImmutableInternal( const GridIndex& internal_cell_index) const { if (fill_status_ == DSHVGFillStatus::CELL_FILLED) { if (sizes_.IndexInBounds(internal_cell_index)) { return DynamicSpatialHashedGridQuery<const T>( AccessIndex(sizes_.GetDataIndex(internal_cell_index)), DSHVGFoundStatus::FOUND_IN_CELL); } else { return DynamicSpatialHashedGridQuery<const T>(); } } else if (fill_status_ == DSHVGFillStatus::CHUNK_FILLED) { if (internal_cell_index == GridIndex(0, 0, 0)) { return DynamicSpatialHashedGridQuery<const T>( AccessIndex(0), DSHVGFoundStatus::FOUND_IN_CHUNK); } else { return DynamicSpatialHashedGridQuery<const T>(); } } else { throw std::runtime_error("Chunk is not filled"); } } DynamicSpatialHashedGridQuery<T> GetMutableInternal( const GridIndex& internal_cell_index) const { if (fill_status_ == DSHVGFillStatus::CELL_FILLED) { if (sizes_.IndexInBounds(internal_cell_index)) { return DynamicSpatialHashedGridQuery<T>( AccessIndex(sizes_.GetDataIndex(internal_cell_index)), DSHVGFoundStatus::FOUND_IN_CELL); } else { return DynamicSpatialHashedGridQuery<T>(); } } else if (fill_status_ == DSHVGFillStatus::CHUNK_FILLED) { if (internal_cell_index == GridIndex(0, 0, 0)) { return DynamicSpatialHashedGridQuery<T>( AccessIndex(0), DSHVGFoundStatus::FOUND_IN_CHUNK); } else { return DynamicSpatialHashedGridQuery<T>(); } } else { throw std::runtime_error("Chunk is not filled"); } } DynamicSpatialHashedGridQuery<const T> GetImmutable( const Eigen::Vector4d& location) const { if (fill_status_ == DSHVGFillStatus::CELL_FILLED) { const int64_t data_index = GetLocationDataIndex(location); if (data_index >= 0) { return DynamicSpatialHashedGridQuery<const T>( AccessIndex(data_index), DSHVGFoundStatus::FOUND_IN_CELL); } else { return DynamicSpatialHashedGridQuery<const T>(); } } else if (fill_status_ == DSHVGFillStatus::CHUNK_FILLED) { return DynamicSpatialHashedGridQuery<const T>( AccessIndex(0), DSHVGFoundStatus::FOUND_IN_CHUNK); } else { throw std::runtime_error("Chunk is not filled"); } } DynamicSpatialHashedGridQuery<T> GetMutable( const Eigen::Vector4d& location) { if (fill_status_ == DSHVGFillStatus::CELL_FILLED) { const int64_t data_index = GetLocationDataIndex(location); if (data_index >= 0) { return DynamicSpatialHashedGridQuery<T>( AccessIndex(data_index), DSHVGFoundStatus::FOUND_IN_CELL); } else { throw std::runtime_error("location not in chunk"); } } else if (fill_status_ == DSHVGFillStatus::CHUNK_FILLED) { return DynamicSpatialHashedGridQuery<T>( AccessIndex(0), DSHVGFoundStatus::FOUND_IN_CHUNK); } else { throw std::runtime_error("Chunk is not filled"); } } DSHVGSetStatus SetCellValue(const Eigen::Vector4d& location, const T& value) { if (fill_status_ == DSHVGFillStatus::CHUNK_FILLED) { const T initial_value = AccessIndex(0); SetCellFilledContents(initial_value); fill_status_ = DSHVGFillStatus::CELL_FILLED; } if (fill_status_ == DSHVGFillStatus::CELL_FILLED) { const int64_t data_index = GetLocationDataIndex(location); if (data_index >= 0) { AccessIndex(data_index) = value; return DSHVGSetStatus::SET_CELL; } else { throw std::runtime_error("location not in chunk"); } } else { throw std::runtime_error("Cannot cell set unfilled chunk"); } } DSHVGSetStatus SetCellValue(const Eigen::Vector4d& location, T&& value) { if (fill_status_ == DSHVGFillStatus::CHUNK_FILLED) { const T initial_value = AccessIndex(0); SetCellFilledContents(initial_value); fill_status_ = DSHVGFillStatus::CELL_FILLED; } if (fill_status_ == DSHVGFillStatus::CELL_FILLED) { const int64_t data_index = GetLocationDataIndex(location); if (data_index >= 0) { AccessIndex(data_index) = value; return DSHVGSetStatus::SET_CELL; } else { throw std::runtime_error("location not in chunk"); } } else { throw std::runtime_error("Cannot cell set unfilled chunk"); } } DSHVGSetStatus SetChunkValue(const T& value) { if (fill_status_ != DSHVGFillStatus::NOT_FILLED) { SetChunkFilledContents(value); return DSHVGSetStatus::SET_CHUNK; } else { throw std::runtime_error("Cannot set unfilled chunk"); } } DSHVGSetStatus SetChunkValue(T&& value) { if (fill_status_ != DSHVGFillStatus::NOT_FILLED) { SetChunkFilledContents(value); return DSHVGSetStatus::SET_CHUNK; } else { throw std::runtime_error("Cannot set unfilled chunk"); } } Eigen::Vector4d GetCellLocationInGridFrame( const GridIndex& internal_cell_index) const { Eigen::Vector4d cell_position = sizes_.IndexToLocationInGridFrame(internal_cell_index); // We need to move from position to offset vector cell_position(3) = 0.0; return region_.Base() + cell_position; } Eigen::Vector4d GetChunkCenterInGridFrame() const { const Eigen::Vector4d center_offset(sizes_.XSize() * 0.5, sizes_.YSize() * 0.5, sizes_.ZSize() * 0.5, 0.0); return region_.Base() + center_offset; } }; /// This is the base class for all dynamic spatial hashed voxel grid classes. /// It is pure virtual to force the implementation of certain necessary /// functions (cloning, access, derived-class memeber de/serialization) in /// concrete implementations. This is the class to inherit from if you want a /// DynamicSpatialHashedVoxelGrid-like type. If all you want is a dynamic /// spatial hashed voxel grid of T, see /// DynamicSpatialHashedVoxelGrid<T, BackingStore> below. template<typename T, typename BackingStore=std::vector<T>> class DynamicSpatialHashedVoxelGridBase { private: using GridChunk = DynamicSpatialHashedVoxelGridChunk<T, BackingStore>; using ChunkMapAllocator = Eigen::aligned_allocator<std::pair<ChunkRegion, GridChunk>>; using ChunkMap = std::unordered_map< ChunkRegion, GridChunk, std::hash<ChunkRegion>, std::equal_to<ChunkRegion>, ChunkMapAllocator>; Eigen::Isometry3d origin_transform_ = Eigen::Isometry3d::Identity(); Eigen::Isometry3d inverse_origin_transform_ = Eigen::Isometry3d::Identity(); T default_value_; GridSizes chunk_sizes_; ChunkMap chunks_; bool initialized_ = false; uint64_t BaseSerializeSelf( std::vector<uint8_t>& buffer, const serialization::Serializer<T>& value_serializer) const { const uint64_t start_buffer_size = buffer.size(); // Serialize the transform serialization::SerializeIsometry3d(origin_transform_, buffer); // Serialize the default value value_serializer(default_value_, buffer); // Serialize the chunk sizes GridSizes::Serialize(chunk_sizes_, buffer); // Serialize the data const auto chunk_serializer = [&] (const GridChunk& chunk, std::vector<uint8_t>& serialize_buffer) { return GridChunk::Serialize(chunk, serialize_buffer, value_serializer); }; serialization::SerializeMapLike<ChunkRegion, GridChunk, ChunkMap>( chunks_, buffer, ChunkRegion::Serialize, chunk_serializer); // Serialize the initialized serialization::SerializeMemcpyable<uint8_t>( static_cast<uint8_t>(initialized_), buffer); // Figure out how many bytes were written const uint64_t end_buffer_size = buffer.size(); const uint64_t bytes_written = end_buffer_size - start_buffer_size; return bytes_written; } uint64_t BaseDeserializeSelf( const std::vector<uint8_t>& buffer, const uint64_t starting_offset, const serialization::Deserializer<T>& value_deserializer) { uint64_t current_position = starting_offset; // Deserialize the transforms const auto origin_transform_deserialized = serialization::DeserializeIsometry3d(buffer, current_position); origin_transform_ = origin_transform_deserialized.Value(); current_position += origin_transform_deserialized.BytesRead(); inverse_origin_transform_ = origin_transform_.inverse(); // Deserialize the default value const auto default_value_deserialized = value_deserializer(buffer, current_position); default_value_ = default_value_deserialized.Value(); current_position += default_value_deserialized.BytesRead(); // Deserialize the chunk sizes const auto chunk_sizes_deserialized = GridSizes::Deserialize(buffer, current_position); chunk_sizes_ = chunk_sizes_deserialized.Value(); current_position += chunk_sizes_deserialized.BytesRead(); // Deserialize the data const auto chunk_deserializer = [&] (const std::vector<uint8_t>& deserialize_buffer, const uint64_t offset) { return GridChunk::Deserialize( deserialize_buffer, offset, value_deserializer); }; const auto chunks_deserialized = serialization::DeserializeMapLike<ChunkRegion, GridChunk, ChunkMap>( buffer, current_position, ChunkRegion::Deserialize, chunk_deserializer); chunks_ = chunks_deserialized.Value(); current_position += chunks_deserialized.BytesRead(); // Deserialize the initialized const auto initialized_deserialized = serialization::DeserializeMemcpyable<uint8_t>(buffer, current_position); initialized_ = static_cast<bool>(initialized_deserialized.Value()); current_position += initialized_deserialized.BytesRead(); // Safety checks if (chunk_sizes_.Valid() != initialized_) { throw std::runtime_error("sizes_.Valid() != initialized_"); } if (chunks_.size() > 0 && !chunk_sizes_.Valid()) { throw std::runtime_error("chunks.size() > 0 with invalid chunk sizes"); } // Figure out how many bytes were read const uint64_t bytes_read = current_position - starting_offset; return bytes_read; } ChunkRegion GetContainingChunkRegion( const Eigen::Vector4d& grid_location) const { if (chunk_sizes_.Valid()) { // Given a location in the grid frame, figure out which chunk region // contains it. const double raw_x_chunk_num = grid_location(0) / chunk_sizes_.XSize(); const double raw_y_chunk_num = grid_location(1) / chunk_sizes_.YSize(); const double raw_z_chunk_num = grid_location(2) / chunk_sizes_.ZSize(); const double region_base_x = std::floor(raw_x_chunk_num) * chunk_sizes_.XSize(); const double region_base_y = std::floor(raw_y_chunk_num) * chunk_sizes_.YSize(); const double region_base_z = std::floor(raw_z_chunk_num) * chunk_sizes_.ZSize(); return ChunkRegion(region_base_x, region_base_y, region_base_z); } else { throw std::runtime_error("chunk_sizes_ is not valid"); } } void AllocateChunkAt( const ChunkRegion& chunk_region, const DSHVGFillType fill_type) { const auto result = chunks_.emplace( chunk_region, GridChunk(chunk_region, chunk_sizes_, fill_type, default_value_)); if (result.second != true) { throw std::runtime_error( "Attempted to allocate new chunk over existing chunk"); } } protected: // These are pure-virtual in the base class to force their implementation in // derived classes. /// Do the work necessary for Clone() to copy the current object. virtual DynamicSpatialHashedVoxelGridBase< T, BackingStore>* DoClone() const = 0; /// Serialize any derived-specific members into the provided buffer. virtual uint64_t DerivedSerializeSelf( std::vector<uint8_t>& buffer, const serialization::Serializer<T>& value_serializer) const = 0; /// Deserialize any derived-specific members from the provided buffer. virtual uint64_t DerivedDeserializeSelf( const std::vector<uint8_t>& buffer, const uint64_t starting_offset, const serialization::Deserializer<T>& value_deserializer) = 0; /// Callback on any mutable access to the grid. Return true/false to allow or /// disallow access to the grid. For example, this can be used to prohibit /// changes to a non-const grid, or to invalidate a cache if voxels are /// modified. virtual bool OnMutableAccess(const Eigen::Vector4d& location) = 0; public: EIGEN_MAKE_ALIGNED_OPERATOR_NEW DynamicSpatialHashedVoxelGridBase(const GridSizes& chunk_sizes, const T& default_value, const size_t expected_chunks) : DynamicSpatialHashedVoxelGridBase<T, BackingStore>( Eigen::Isometry3d::Identity(), chunk_sizes, default_value, expected_chunks) {} DynamicSpatialHashedVoxelGridBase(const Eigen::Isometry3d& origin_transform, const GridSizes& chunk_sizes, const T& default_value, const size_t expected_chunks) { if (chunk_sizes.Valid()) { origin_transform_ = origin_transform; inverse_origin_transform_ = origin_transform_.inverse(); chunk_sizes_ = chunk_sizes; default_value_ = default_value; chunks_.reserve(expected_chunks); initialized_ = true; } else { throw std::invalid_argument("chunk_sizes is not valid"); } } DynamicSpatialHashedVoxelGridBase() { origin_transform_.setIdentity(); inverse_origin_transform_ = origin_transform_.inverse(); initialized_ = false; } virtual ~DynamicSpatialHashedVoxelGridBase() {} DynamicSpatialHashedVoxelGridBase<T, BackingStore>* Clone() const { return DoClone(); } uint64_t SerializeSelf( std::vector<uint8_t>& buffer, const serialization::Serializer<T>& value_serializer) const { return BaseSerializeSelf(buffer, value_serializer) + DerivedSerializeSelf(buffer, value_serializer); } uint64_t DeserializeSelf( const std::vector<uint8_t>& buffer, const uint64_t starting_offset, const serialization::Deserializer<T>& value_deserializer) { uint64_t current_position = starting_offset; current_position += BaseDeserializeSelf(buffer, starting_offset, value_deserializer); current_position += DerivedDeserializeSelf(buffer, current_position, value_deserializer); // Figure out how many bytes were read const uint64_t bytes_read = current_position - starting_offset; return bytes_read; } bool IsInitialized() const { return initialized_; } DynamicSpatialHashedGridQuery<const T> GetImmutable( const double x, const double y, const double z) const { return GetImmutable4d(Eigen::Vector4d(x, y, z, 1.0)); } DynamicSpatialHashedGridQuery<const T> GetImmutable3d( const Eigen::Vector3d& location) const { return GetImmutable4d( Eigen::Vector4d(location.x(), location.y(), location.z(), 1.0)); } DynamicSpatialHashedGridQuery<const T> GetImmutable4d( const Eigen::Vector4d& location) const { const Eigen::Vector4d grid_frame_location = inverse_origin_transform_ * location; const ChunkRegion region = GetContainingChunkRegion(grid_frame_location); auto found_chunk_itr = chunks_.find(region); if (found_chunk_itr != chunks_.end()) { return found_chunk_itr->second.GetImmutable(grid_frame_location); } else { return DynamicSpatialHashedGridQuery<const T>(); } } DynamicSpatialHashedGridQuery<T> GetMutable( const double x, const double y, const double z) { return GetMutable4d(Eigen::Vector4d(x, y, z, 1.0)); } DynamicSpatialHashedGridQuery<T> GetMutable3d( const Eigen::Vector3d& location) { return GetMutable4d( Eigen::Vector4d(location.x(), location.y(), location.z(), 1.0)); } DynamicSpatialHashedGridQuery<T> GetMutable4d( const Eigen::Vector4d& location) { const Eigen::Vector4d grid_frame_location = inverse_origin_transform_ * location; const ChunkRegion region = GetContainingChunkRegion(grid_frame_location); auto found_chunk_itr = chunks_.find(region); if (found_chunk_itr != chunks_.end() && OnMutableAccess(grid_frame_location)) { return found_chunk_itr->second.GetMutable(grid_frame_location); } else { return DynamicSpatialHashedGridQuery<T>(); } } DSHVGSetStatus SetValue( const double x, const double y, const double z, const DSHVGSetType set_type, const T& value) { return SetValue4d(Eigen::Vector4d(x, y, z, 1.0), set_type, value); } DSHVGSetStatus SetValue3d(const Eigen::Vector3d& location, const DSHVGSetType set_type, const T& value) { return SetValue4d( Eigen::Vector4d(location.x(), location.y(), location.z(), 1.0), set_type, value); } DSHVGSetStatus SetValue4d(const Eigen::Vector4d& location, const DSHVGSetType set_type, const T& value) { const Eigen::Vector4d grid_frame_location = inverse_origin_transform_ * location; if (OnMutableAccess(grid_frame_location)) { const ChunkRegion region = GetContainingChunkRegion(grid_frame_location); auto found_chunk_itr = chunks_.find(region); if (found_chunk_itr != chunks_.end()) { if (set_type == DSHVGSetType::SET_CELL) { return found_chunk_itr->second.SetCellValue( grid_frame_location, value); } else { return found_chunk_itr->second.SetChunkValue(value); } } else { const DSHVGFillType fill_type = (set_type == DSHVGSetType::SET_CELL) ? DSHVGFillType::FILL_CELL : DSHVGFillType::FILL_CHUNK; AllocateChunkAt(region, fill_type); return SetValue4d(location, set_type, value); } } else { return DSHVGSetStatus::NOT_SET; } } DSHVGSetStatus SetValue( const double x, const double y, const double z, const DSHVGSetType set_type, T&& value) { return SetValue4d(Eigen::Vector4d(x, y, z, 1.0), set_type, value); } DSHVGSetStatus SetValue3d(const Eigen::Vector3d& location, const DSHVGSetType set_type, T&& value) { return SetValue4d( Eigen::Vector4d(location.x(), location.y(), location.z(), 1.0), set_type, value); } DSHVGSetStatus SetValue4d(const Eigen::Vector4d& location, const DSHVGSetType set_type, T&& value) { const Eigen::Vector4d grid_frame_location = inverse_origin_transform_ * location; if (OnMutableAccess(grid_frame_location)) { const ChunkRegion region = GetContainingChunkRegion(grid_frame_location); auto found_chunk_itr = chunks_.find(region); if (found_chunk_itr != chunks_.end()) { if (set_type == DSHVGSetType::SET_CELL) { return found_chunk_itr->second.SetCellValue( grid_frame_location, value); } else { return found_chunk_itr->second.SetChunkValue(value); } } else { const DSHVGFillType fill_type = (set_type == DSHVGSetType::SET_CELL) ? DSHVGFillType::FILL_CELL : DSHVGFillType::FILL_CHUNK; AllocateChunkAt(region, fill_type); return SetValue4d(location, set_type, value); } } else { return DSHVGSetStatus::NOT_SET; } } const GridSizes& GetChunkGridSizes() const { return chunk_sizes_; } Eigen::Vector3d GetCellSizes() const { return chunk_sizes_.CellSizes(); } Eigen::Vector3d GetChunkSizes() const { return chunk_sizes_.Sizes(); } Eigen::Matrix<int64_t, 3, 1> GetChunkNumCells() const { return chunk_sizes_.NumCells(); } const T& GetDefaultValue() const { return default_value_; } void SetDefaultValue(const T& default_value) { default_value_ = default_value; } const Eigen::Isometry3d& GetOriginTransform() const { return origin_transform_; } const Eigen::Isometry3d& GetInverseOriginTransform() const { return inverse_origin_transform_; } void UpdateOriginTransform(const Eigen::Isometry3d& origin_transform) { origin_transform_ = origin_transform; inverse_origin_transform_ = origin_transform_.inverse(); } bool HasUniformCellSize() const { return chunk_sizes_.UniformCellSize(); } const ChunkMap& GetImmutableInternalChunks() const { return chunks_; } ChunkMap& GetMutableInternalChunks() const { return chunks_; } }; /// If you want a DynamicSpatialHashedVoxelGrid<T> this is the class to use. /// Since you should never inherit from it, this class is final. template<typename T, typename BackingStore=std::vector<T>> class DynamicSpatialHashedVoxelGrid final : public DynamicSpatialHashedVoxelGridBase<T, BackingStore> { private: DynamicSpatialHashedVoxelGridBase<T, BackingStore>* DoClone() const override { return new DynamicSpatialHashedVoxelGrid<T, BackingStore>( static_cast< const DynamicSpatialHashedVoxelGrid<T, BackingStore>&>(*this)); } uint64_t DerivedSerializeSelf( std::vector<uint8_t>& buffer, const serialization::Serializer<T>& value_serializer) const override { UNUSED(buffer); UNUSED(value_serializer); return 0; } uint64_t DerivedDeserializeSelf( const std::vector<uint8_t>& buffer, const uint64_t starting_offset, const serialization::Deserializer<T>& value_deserializer) override { UNUSED(buffer); UNUSED(starting_offset); UNUSED(value_deserializer); return 0; } bool OnMutableAccess(const Eigen::Vector4d& location) override { UNUSED(location); return true; } public: static uint64_t Serialize( const DynamicSpatialHashedVoxelGrid<T, BackingStore>& grid, std::vector<uint8_t>& buffer, const serialization::Serializer<T>& value_serializer) { return grid.SerializeSelf(buffer, value_serializer); } static serialization::Deserialized< DynamicSpatialHashedVoxelGrid<T, BackingStore>> Deserialize( const std::vector<uint8_t>& buffer, const uint64_t starting_offset, const serialization::Deserializer<T>& value_deserializer) { DynamicSpatialHashedVoxelGrid<T, BackingStore> temp_grid; const uint64_t bytes_read = temp_grid.DeserializeSelf(buffer, starting_offset, value_deserializer); return serialization::MakeDeserialized(temp_grid, bytes_read); } DynamicSpatialHashedVoxelGrid(const GridSizes& chunk_sizes, const T& default_value, const size_t expected_chunks) : DynamicSpatialHashedVoxelGridBase<T, BackingStore>( Eigen::Isometry3d::Identity(), chunk_sizes, default_value, expected_chunks) {} DynamicSpatialHashedVoxelGrid(const Eigen::Isometry3d& origin_transform, const GridSizes& chunk_sizes, const T& default_value, const size_t expected_chunks) : DynamicSpatialHashedVoxelGridBase<T, BackingStore>( origin_transform, chunk_sizes, default_value, expected_chunks) {} DynamicSpatialHashedVoxelGrid() : DynamicSpatialHashedVoxelGridBase<T, BackingStore>() {} }; } // namespace voxel_grid } // namespace common_robotics_utilities namespace std { template <> struct hash<common_robotics_utilities::voxel_grid::ChunkRegion> { std::size_t operator()( const common_robotics_utilities::voxel_grid::ChunkRegion& region) const { const Eigen::Vector4d& base = region.Base(); std::size_t hash_val = 0; common_robotics_utilities::utility::hash_combine( hash_val, base(0), base(1), base(2)); return hash_val; } }; }
#include "SampleAnalyzer/User/Analyzer/user.h" using namespace MA5; bool user::Initialize(const MA5::Configuration& cfg, const std::map<std::string,std::string>& parameters) { // Initializing PhysicsService for MC PHYSICS->mcConfig().Reset(); // definition of the multiparticle "hadronic" PHYSICS->mcConfig().AddHadronicId(-5); PHYSICS->mcConfig().AddHadronicId(-4); PHYSICS->mcConfig().AddHadronicId(-3); PHYSICS->mcConfig().AddHadronicId(-2); PHYSICS->mcConfig().AddHadronicId(-1); PHYSICS->mcConfig().AddHadronicId(1); PHYSICS->mcConfig().AddHadronicId(2); PHYSICS->mcConfig().AddHadronicId(3); PHYSICS->mcConfig().AddHadronicId(4); PHYSICS->mcConfig().AddHadronicId(5); PHYSICS->mcConfig().AddHadronicId(21); // definition of the multiparticle "invisible" PHYSICS->mcConfig().AddInvisibleId(-16); PHYSICS->mcConfig().AddInvisibleId(-14); PHYSICS->mcConfig().AddInvisibleId(-12); PHYSICS->mcConfig().AddInvisibleId(12); PHYSICS->mcConfig().AddInvisibleId(14); PHYSICS->mcConfig().AddInvisibleId(16); PHYSICS->mcConfig().AddInvisibleId(1000022); // ===== Signal region ===== // Manager()->AddRegionSelection("myregion"); // ===== Selections ===== // Manager()->AddCut("1_( sdETA ( jets[1] jets[2] ) > 2.6 or sdETA ( jets[1] jets[2] ) < -2.6 ) and M ( jets[1] jets[2] ) > 1250.0"); Manager()->AddCut("2_PT ( a[1] ) > 100.0 and M ( a[1] a[2] ) > 700.0"); // ===== Histograms ===== // // No problem during initialization return true; } bool user::Execute(SampleFormat& sample, const EventFormat& event) { MAfloat32 __event_weight__ = 1.0; if (weighted_events_ && event.mc()!=0) __event_weight__ = event.mc()->weight(); if (sample.mc()!=0) sample.mc()->addWeightedEvents(__event_weight__); Manager()->InitializeForNewEvent(__event_weight__); // Clearing particle containers { _P_jets_I1I_PTorderingfinalstate_REG_.clear(); _P_jets_I2I_PTorderingfinalstate_REG_.clear(); _P_a_I1I_PTorderingfinalstate_REG_.clear(); _P_a_I2I_PTorderingfinalstate_REG_.clear(); _P_jetsPTorderingfinalstate_REG_.clear(); _P_aPTorderingfinalstate_REG_.clear(); } // Filling particle containers { for (MAuint32 i=0;i<event.mc()->particles().size();i++) { if (isP__jetsPTorderingfinalstate((&(event.mc()->particles()[i])))) _P_jetsPTorderingfinalstate_REG_.push_back(&(event.mc()->particles()[i])); if (isP__aPTorderingfinalstate((&(event.mc()->particles()[i])))) _P_aPTorderingfinalstate_REG_.push_back(&(event.mc()->particles()[i])); } } // Sorting particles // Sorting particle collection according to PTordering // for getting 1th particle _P_jets_I1I_PTorderingfinalstate_REG_=SORTER->rankFilter(_P_jetsPTorderingfinalstate_REG_,1,PTordering); // Sorting particle collection according to PTordering // for getting 2th particle _P_jets_I2I_PTorderingfinalstate_REG_=SORTER->rankFilter(_P_jetsPTorderingfinalstate_REG_,2,PTordering); // Sorting particle collection according to PTordering // for getting 1th particle _P_a_I1I_PTorderingfinalstate_REG_=SORTER->rankFilter(_P_aPTorderingfinalstate_REG_,1,PTordering); // Sorting particle collection according to PTordering // for getting 2th particle _P_a_I2I_PTorderingfinalstate_REG_=SORTER->rankFilter(_P_aPTorderingfinalstate_REG_,2,PTordering); // Event selection number 1 // * Cut: select ( sdETA ( jets[1] jets[2] ) > 2.6 or sdETA ( jets[1] jets[2] ) < -2.6 ) and M ( jets[1] jets[2] ) > 1250.0, regions = [] { std::vector<MAbool> filter(3,false); { { MAuint32 ind[2]; std::vector<std::set<const MCParticleFormat*> > combis; for (ind[0]=0;ind[0]<_P_jets_I1I_PTorderingfinalstate_REG_.size();ind[0]++) { for (ind[1]=0;ind[1]<_P_jets_I2I_PTorderingfinalstate_REG_.size();ind[1]++) { if (_P_jets_I2I_PTorderingfinalstate_REG_[ind[1]]==_P_jets_I1I_PTorderingfinalstate_REG_[ind[0]]) continue; // Checking if consistent combination std::set<const MCParticleFormat*> mycombi; for (MAuint32 i=0;i<2;i++) { mycombi.insert(_P_jets_I1I_PTorderingfinalstate_REG_[ind[i]]); mycombi.insert(_P_jets_I2I_PTorderingfinalstate_REG_[ind[i]]); } MAbool matched=false; for (MAuint32 i=0;i<combis.size();i++) if (combis[i]==mycombi) {matched=true; break;} if (matched) continue; else combis.push_back(mycombi); if ((_P_jets_I1I_PTorderingfinalstate_REG_[ind[0]]->eta()-_P_jets_I2I_PTorderingfinalstate_REG_[ind[1]]->eta())>2.6) {filter[0]=true; break;} } } } } { { MAuint32 ind[2]; std::vector<std::set<const MCParticleFormat*> > combis; for (ind[0]=0;ind[0]<_P_jets_I1I_PTorderingfinalstate_REG_.size();ind[0]++) { for (ind[1]=0;ind[1]<_P_jets_I2I_PTorderingfinalstate_REG_.size();ind[1]++) { if (_P_jets_I2I_PTorderingfinalstate_REG_[ind[1]]==_P_jets_I1I_PTorderingfinalstate_REG_[ind[0]]) continue; // Checking if consistent combination std::set<const MCParticleFormat*> mycombi; for (MAuint32 i=0;i<2;i++) { mycombi.insert(_P_jets_I1I_PTorderingfinalstate_REG_[ind[i]]); mycombi.insert(_P_jets_I2I_PTorderingfinalstate_REG_[ind[i]]); } MAbool matched=false; for (MAuint32 i=0;i<combis.size();i++) if (combis[i]==mycombi) {matched=true; break;} if (matched) continue; else combis.push_back(mycombi); if ((_P_jets_I1I_PTorderingfinalstate_REG_[ind[0]]->eta()-_P_jets_I2I_PTorderingfinalstate_REG_[ind[1]]->eta())<-2.6) {filter[1]=true; break;} } } } } { { MAuint32 ind[2]; std::vector<std::set<const MCParticleFormat*> > combis; for (ind[0]=0;ind[0]<_P_jets_I1I_PTorderingfinalstate_REG_.size();ind[0]++) { for (ind[1]=0;ind[1]<_P_jets_I2I_PTorderingfinalstate_REG_.size();ind[1]++) { if (_P_jets_I2I_PTorderingfinalstate_REG_[ind[1]]==_P_jets_I1I_PTorderingfinalstate_REG_[ind[0]]) continue; // Checking if consistent combination std::set<const MCParticleFormat*> mycombi; for (MAuint32 i=0;i<2;i++) { mycombi.insert(_P_jets_I1I_PTorderingfinalstate_REG_[ind[i]]); mycombi.insert(_P_jets_I2I_PTorderingfinalstate_REG_[ind[i]]); } MAbool matched=false; for (MAuint32 i=0;i<combis.size();i++) if (combis[i]==mycombi) {matched=true; break;} if (matched) continue; else combis.push_back(mycombi); ParticleBaseFormat q; q+=_P_jets_I1I_PTorderingfinalstate_REG_[ind[0]]->momentum(); q+=_P_jets_I2I_PTorderingfinalstate_REG_[ind[1]]->momentum(); if (q.m()>1250.0) {filter[2]=true; break;} } } } } MAbool filter_global = ((filter[0] || filter[1]) && filter[2]); if(!Manager()->ApplyCut(filter_global, "1_( sdETA ( jets[1] jets[2] ) > 2.6 or sdETA ( jets[1] jets[2] ) < -2.6 ) and M ( jets[1] jets[2] ) > 1250.0")) return true; } // Event selection number 2 // * Cut: select PT ( a[1] ) > 100.0 and M ( a[1] a[2] ) > 700.0, regions = [] { std::vector<MAbool> filter(2,false); { { MAuint32 ind[1]; for (ind[0]=0;ind[0]<_P_a_I1I_PTorderingfinalstate_REG_.size();ind[0]++) { if (_P_a_I1I_PTorderingfinalstate_REG_[ind[0]]->pt()>100.0) {filter[0]=true; break;} } } } { { MAuint32 ind[2]; std::vector<std::set<const MCParticleFormat*> > combis; for (ind[0]=0;ind[0]<_P_a_I1I_PTorderingfinalstate_REG_.size();ind[0]++) { for (ind[1]=0;ind[1]<_P_a_I2I_PTorderingfinalstate_REG_.size();ind[1]++) { if (_P_a_I2I_PTorderingfinalstate_REG_[ind[1]]==_P_a_I1I_PTorderingfinalstate_REG_[ind[0]]) continue; // Checking if consistent combination std::set<const MCParticleFormat*> mycombi; for (MAuint32 i=0;i<2;i++) { mycombi.insert(_P_a_I1I_PTorderingfinalstate_REG_[ind[i]]); mycombi.insert(_P_a_I2I_PTorderingfinalstate_REG_[ind[i]]); } MAbool matched=false; for (MAuint32 i=0;i<combis.size();i++) if (combis[i]==mycombi) {matched=true; break;} if (matched) continue; else combis.push_back(mycombi); ParticleBaseFormat q; q+=_P_a_I1I_PTorderingfinalstate_REG_[ind[0]]->momentum(); q+=_P_a_I2I_PTorderingfinalstate_REG_[ind[1]]->momentum(); if (q.m()>700.0) {filter[1]=true; break;} } } } } MAbool filter_global = (filter[0] && filter[1]); if(!Manager()->ApplyCut(filter_global, "2_PT ( a[1] ) > 100.0 and M ( a[1] a[2] ) > 700.0")) return true; } return true; } void user::Finalize(const SampleFormat& summary, const std::vector<SampleFormat>& files) { }
; A049669: a(n) = Fibonacci(9*n)/34. ; Submitted by Jamie Morken(m4) ; 0,1,76,5777,439128,33379505,2537281508,192866774113,14660412114096,1114384187445409,84707858657965180,6438911642192799089,489441992665310695944,37204030354205805690833,2827995748912306543199252,214964880947689503088833985,16340158947773314541294582112,1242067044911719594641477074497,94413435572238462507293552243884,7176663170535034870148951447609681,545520814396234888593827603570579640,41466758557284386568001046822811662321,3152019171168009614056673386137256916036 mul $0,9 seq $0,45 ; Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1. div $0,34
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Copyright(c) 2011-2016 Intel Corporation All rights reserved. ; ; Redistribution and use in source and binary forms, with or without ; modification, are permitted provided that the following conditions ; are met: ; * Redistributions of source code must retain the above copyright ; notice, this list of conditions and the following disclaimer. ; * Redistributions in binary form must reproduce the above copyright ; notice, this list of conditions and the following disclaimer in ; the documentation and/or other materials provided with the ; distribution. ; * Neither the name of Intel Corporation nor the names of its ; contributors may be used to endorse or promote products derived ; from this software without specific prior written permission. ; ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; %include "sha256_job.asm" %include "sha256_mb_mgr_datastruct.asm" %include "reg_sizes.asm" %ifdef HAVE_AS_KNOWS_AVX512 extern sha256_mb_x16_avx512 extern sha256_opt_x1 [bits 64] default rel section .text %ifidn __OUTPUT_FORMAT__, elf64 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; LINUX register definitions %define arg1 rdi ; rcx %define arg2 rsi ; rdx %define tmp4 rdx ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; %else ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; WINDOWS register definitions %define arg1 rcx %define arg2 rdx %define tmp4 rsi ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; %endif ; Common register definitions %define state arg1 %define job arg2 %define len2 arg2 ; idx must be a register not clobberred by sha256_mb_x16_avx2 and sha256_opt_x1 %define idx rbp %define num_lanes_inuse r9 %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 ; STACK_SPACE needs to be an odd multiple of 8 _XMM_SAVE_SIZE equ 10*16 _GPR_SAVE_SIZE equ 8*8 _ALIGN_SIZE equ 8 _XMM_SAVE equ 0 _GPR_SAVE equ _XMM_SAVE + _XMM_SAVE_SIZE STACK_SPACE equ _GPR_SAVE + _GPR_SAVE_SIZE + _ALIGN_SIZE %define APPEND(a,b) a %+ b ; SHA256_JOB* sha256_mb_mgr_flush_avx512(SHA256_MB_JOB_MGR *state) ; arg 1 : rcx : state mk_global sha256_mb_mgr_flush_avx512, function sha256_mb_mgr_flush_avx512: endbranch sub rsp, STACK_SPACE mov [rsp + _GPR_SAVE + 8*0], rbx mov [rsp + _GPR_SAVE + 8*3], rbp mov [rsp + _GPR_SAVE + 8*4], r12 mov [rsp + _GPR_SAVE + 8*5], r13 mov [rsp + _GPR_SAVE + 8*6], r14 mov [rsp + _GPR_SAVE + 8*7], r15 %ifidn __OUTPUT_FORMAT__, win64 mov [rsp + _GPR_SAVE + 8*1], rsi mov [rsp + _GPR_SAVE + 8*2], rdi 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 mov DWORD(num_lanes_inuse), [state + _num_lanes_inuse] cmp num_lanes_inuse, 0 jz return_null ; find a lane with a non-null job xor idx, idx %assign I 1 %rep 15 cmp qword [state + _ldata + I * _LANE_DATA_size + _job_in_lane], 0 cmovne idx, [APPEND(lane_,I)] %assign I (I+1) %endrep ; copy idx to empty lanes copy_lane_data: mov tmp, [state + _args + _data_ptr + 8*idx] %assign I 0 %rep 16 cmp qword [state + _ldata + I * _LANE_DATA_size + _job_in_lane], 0 jne APPEND(skip_,I) mov [state + _args + _data_ptr + 8*I], tmp mov dword [state + _lens + 4*I], 0xFFFFFFFF APPEND(skip_,I): %assign I (I+1) %endrep ; Find min length vmovdqu ymm0, [state + _lens + 0*32] vmovdqu ymm1, [state + _lens + 1*32] vpminud ymm2, ymm0, ymm1 ; ymm2 has {H1,G1,F1,E1,D1,C1,B1,A1} vpalignr ymm3, ymm3, ymm2, 8 ; ymm3 has {x,x,H1,G1,x,x,D1,C1} vpminud ymm2, ymm2, ymm3 ; ymm2 has {x,x,H2,G2,x,x,D2,C2} vpalignr ymm3, ymm3, ymm2, 4 ; ymm3 has {x,x, x,H2,x,x, x,D2} vpminud ymm2, ymm2, ymm3 ; ymm2 has {x,x, x,G3,x,x, x,C3} vperm2i128 ymm3, ymm2, ymm2, 1 ; ymm3 has {x,x, x, x,x,x, x,C3} vpminud ymm2, ymm2, ymm3 ; ymm2 has min value in low dword vmovd DWORD(idx), xmm2 mov len2, idx and idx, 0xF shr len2, 4 jz len_is_0 ; compare with sha-sb threshold, if num_lanes_inuse <= threshold, using sb func cmp dword [state + _num_lanes_inuse], SHA256_SB_THRESHOLD_AVX512 ja mb_processing ; lensN-len2=idx mov [state + _lens + idx*4], DWORD(idx) mov r10, idx or r10, 0x4000 ; avx2 has 8 lanes *4, r10b is idx, r10b2 is 32 ; "state" and "args" are the same address, arg1 ; len is arg2, idx and nlane in r10 call sha256_opt_x1 ; state and idx are intact jmp len_is_0 mb_processing: vpand ymm2, ymm2, [rel clear_low_nibble] vpshufd ymm2, ymm2, 0 vpsubd ymm0, ymm0, ymm2 vpsubd ymm1, ymm1, ymm2 vmovdqu [state + _lens + 0*32], ymm0 vmovdqu [state + _lens + 1*32], ymm1 ; "state" and "args" are the same address, arg1 ; len is arg2 call sha256_mb_x16_avx512 ; state and idx are intact len_is_0: ; process completed job "idx" imul lane_data, idx, _LANE_DATA_size lea lane_data, [state + _ldata + lane_data] mov job_rax, [lane_data + _job_in_lane] mov qword [lane_data + _job_in_lane], 0 mov dword [job_rax + _status], STS_COMPLETED mov unused_lanes, [state + _unused_lanes] shl unused_lanes, 4 or unused_lanes, idx mov [state + _unused_lanes], unused_lanes mov DWORD(num_lanes_inuse), [state + _num_lanes_inuse] sub num_lanes_inuse, 1 mov [state + _num_lanes_inuse], DWORD(num_lanes_inuse) vmovd xmm0, [state + _args_digest + 4*idx + 0*4*16] vpinsrd xmm0, [state + _args_digest + 4*idx + 1*4*16], 1 vpinsrd xmm0, [state + _args_digest + 4*idx + 2*4*16], 2 vpinsrd xmm0, [state + _args_digest + 4*idx + 3*4*16], 3 vmovd xmm1, [state + _args_digest + 4*idx + 4*4*16] vpinsrd xmm1, [state + _args_digest + 4*idx + 5*4*16], 1 vpinsrd xmm1, [state + _args_digest + 4*idx + 6*4*16], 2 vpinsrd xmm1, [state + _args_digest + 4*idx + 7*4*16], 3 vmovdqa [job_rax + _result_digest + 0*16], xmm0 vmovdqa [job_rax + _result_digest + 1*16], xmm1 return: %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] mov rsi, [rsp + _GPR_SAVE + 8*1] mov rdi, [rsp + _GPR_SAVE + 8*2] %endif mov rbx, [rsp + _GPR_SAVE + 8*0] mov rbp, [rsp + _GPR_SAVE + 8*3] mov r12, [rsp + _GPR_SAVE + 8*4] mov r13, [rsp + _GPR_SAVE + 8*5] mov r14, [rsp + _GPR_SAVE + 8*6] mov r15, [rsp + _GPR_SAVE + 8*7] add rsp, STACK_SPACE ret return_null: xor job_rax, job_rax jmp return section .data align=16 align 16 clear_low_nibble: dq 0x00000000FFFFFFF0, 0x0000000000000000 dq 0x00000000FFFFFFF0, 0x0000000000000000 lane_1: dq 1 lane_2: dq 2 lane_3: dq 3 lane_4: dq 4 lane_5: dq 5 lane_6: dq 6 lane_7: dq 7 lane_8: dq 8 lane_9: dq 9 lane_10: dq 10 lane_11: dq 11 lane_12: dq 12 lane_13: dq 13 lane_14: dq 14 lane_15: dq 15 %else %ifidn __OUTPUT_FORMAT__, win64 global no_sha256_mb_mgr_flush_avx512 no_sha256_mb_mgr_flush_avx512: %endif %endif ; HAVE_AS_KNOWS_AVX512
; A036464: Number of ways to place two nonattacking queens on an n X n board. ; 0,0,8,44,140,340,700,1288,2184,3480,5280,7700,10868,14924,20020,26320,34000,43248,54264,67260,82460,100100,120428,143704,170200,200200,234000,271908,314244,361340,413540,471200,534688,604384,680680,763980,854700,953268,1060124,1175720,1300520,1435000,1579648,1734964,1901460,2079660,2270100,2473328,2689904,2920400,3165400,3425500,3701308,3993444,4302540,4629240,4974200,5338088,5721584,6125380,6550180,6996700,7465668,7957824,8473920,9014720,9581000,10173548,10793164,11440660,12116860,12822600,13558728,14326104,15125600,15958100,16824500,17725708,18662644,19636240,20647440,21697200,22786488,23916284,25087580,26301380,27558700,28860568,30208024,31602120,33043920,34534500,36074948,37666364,39309860,41006560,42757600,44564128,46427304,48348300 mov $1,$0 add $0,1 pow $1,2 sub $1,$0 bin $0,2 add $1,$0 mul $1,$0 mov $0,$1 div $0,6 mul $0,4
// Copyright (C) 2018 Ian Dunn // For conditions of distribution and use, see the LICENSE file #include "Application.hpp" int main(int argc, char ** argv) { Application app; app.ReadArguments(argc, argv); return app.Run(); }
.global s_prepare_buffers s_prepare_buffers: push %r11 push %r15 push %rax push %rbp push %rcx push %rdi push %rdx push %rsi lea addresses_WC_ht+0x43ce, %rdx nop and $48255, %r11 movb (%rdx), %al nop and $57668, %rbp lea addresses_A_ht+0x150ce, %rsi lea addresses_WC_ht+0x7d0e, %rdi add $17230, %r15 mov $48, %rcx rep movsl nop cmp %rsi, %rsi lea addresses_WT_ht+0x23ce, %rax nop nop inc %rcx mov (%rax), %r11 nop nop nop nop cmp %rdi, %rdi lea addresses_UC_ht+0x15b6e, %rdi nop nop and $23067, %rsi mov (%rdi), %r11w nop nop add %rdx, %rdx pop %rsi pop %rdx pop %rdi pop %rcx pop %rbp pop %rax pop %r15 pop %r11 ret .global s_faulty_load s_faulty_load: push %r12 push %r8 push %r9 push %rax push %rdi push %rdx // Store lea addresses_WT+0x1fcee, %rdx nop nop nop nop add $19687, %r12 mov $0x5152535455565758, %rax movq %rax, %xmm0 movups %xmm0, (%rdx) nop dec %rdi // Faulty Load lea addresses_PSE+0x16e8e, %r9 nop nop nop nop nop dec %rax vmovups (%r9), %ymm0 vextracti128 $0, %ymm0, %xmm0 vpextrq $1, %xmm0, %r12 lea oracles, %r8 and $0xff, %r12 shlq $12, %r12 mov (%r8,%r12,1), %r12 pop %rdx pop %rdi pop %rax pop %r9 pop %r8 pop %r12 ret /* <gen_faulty_load> [REF] {'src': {'type': 'addresses_PSE', 'same': False, 'size': 1, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'dst': {'type': 'addresses_WT', 'same': False, 'size': 16, 'congruent': 4, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} [Faulty Load] {'src': {'type': 'addresses_PSE', 'same': True, 'size': 32, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'type': 'addresses_WC_ht', 'same': True, 'size': 1, 'congruent': 6, 'NT': True, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_A_ht', 'congruent': 5, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 2, 'same': False}, 'OP': 'REPM'} {'src': {'type': 'addresses_WT_ht', 'same': False, 'size': 8, 'congruent': 1, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_UC_ht', 'same': False, 'size': 2, 'congruent': 5, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'33': 21829} 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 */
; ; ZX IF1 & Microdrive functions ; ; remove a given file in the given drive ; ; int if1_remove (int drive, char *filename); ; ; $Id: if1_remove_file.asm,v 1.3 2016/07/01 22:08:20 dom Exp $ ; SECTION code_clib PUBLIC if1_remove_file PUBLIC _if1_remove_file EXTERN if1_setname EXTERN if1_rommap EXTERN ERASEM if1_remove_file: _if1_remove_file: rst 8 defb 31h ; Create Interface 1 system vars if required pop af pop de ;filename pop bc ;driveno push bc push de push af ld a,c ld ($5cd6),a push de ld hl,filename ; filename location push hl call if1_setname ld ($5cda),hl ; length pop de ld ($5cdc),hl ; pointer to filename call if1_rommap call ERASEM call 1 ; unpage ei ld hl,0 ret SECTION bss_clib ; parameters and variables filename: defs 10
#include "feature_parallel_dataset_builder.h" #include "compressed_index_builder.h" #include "feature_layout_feature_parallel.h" #include "dataset_helpers.h" #include <catboost/libs/helpers/vector_helpers.h> namespace NCatboostCuda { TFeatureParallelDataSetsHolder TFeatureParallelDataSetHoldersBuilder::BuildDataSet(const ui32 permutationCount, NPar::ILocalExecutor* localExecutor) { TFeatureParallelDataSetsHolder dataSetsHolder(DataProvider, FeaturesManager); Y_ASSERT(dataSetsHolder.CompressedIndex); TSharedCompressedIndexBuilder<TDataSetLayout> compressedIndexBuilder(*dataSetsHolder.CompressedIndex, localExecutor); dataSetsHolder.CtrTargets = BuildCtrTarget(FeaturesManager, DataProvider, LinkedTest); auto& ctrsTarget = *dataSetsHolder.CtrTargets; { dataSetsHolder.LearnCatFeaturesDataSet = MakeHolder<TCompressedCatFeatureDataSet>(CatFeaturesStorage); BuildCompressedCatFeatures(DataProvider, *dataSetsHolder.LearnCatFeaturesDataSet, localExecutor); if (LinkedTest) { dataSetsHolder.TestCatFeaturesDataSet = MakeHolder<TCompressedCatFeatureDataSet>(CatFeaturesStorage); BuildCompressedCatFeatures(*LinkedTest, *dataSetsHolder.TestCatFeaturesDataSet, localExecutor); } } TAtomicSharedPtr<TPermutationScope> permutationIndependentScope = new TPermutationScope; dataSetsHolder.PermutationDataSets.resize(permutationCount); const auto learnWeights = NCB::GetWeights(*DataProvider.TargetData); const bool isTrivialLearnWeights = AreEqualTo(learnWeights, 1.0f); { const auto learnMapping = NCudaLib::TMirrorMapping(ctrsTarget.LearnSlice.Size()); if (isTrivialLearnWeights == ctrsTarget.IsTrivialWeights()) { dataSetsHolder.DirectWeights = ctrsTarget.Weights.SliceView(ctrsTarget.LearnSlice); } else { dataSetsHolder.DirectWeights.Reset(learnMapping); dataSetsHolder.DirectWeights.Write(learnWeights); } if (isTrivialLearnWeights && ctrsTarget.IsTrivialWeights()) { dataSetsHolder.DirectTarget = ctrsTarget.WeightedTarget.SliceView(ctrsTarget.LearnSlice); } else { dataSetsHolder.DirectTarget.Reset(learnMapping); dataSetsHolder.DirectTarget.Write(*DataProvider.TargetData->GetOneDimensionalTarget()); } } for (ui32 permutationId = 0; permutationId < permutationCount; ++permutationId) { TDataPermutation permutation = NCatboostCuda::GetPermutation(DataProvider, permutationId, DataProviderPermutationBlockSize); const auto targetsMapping = NCudaLib::TMirrorMapping(ctrsTarget.LearnSlice.Size()); TMirrorBuffer<ui32> indices; indices.Reset(targetsMapping); permutation.WriteOrder(indices); TMirrorBuffer<ui32> inverseIndices; TMirrorBuffer<float> targets; TMirrorBuffer<float> weights; if (permutation.IsIdentity()) { inverseIndices = indices.CopyView(); targets = dataSetsHolder.DirectTarget.CopyView(); } else { inverseIndices.Reset(targetsMapping); permutation.WriteInversePermutation(inverseIndices); targets.Reset(dataSetsHolder.DirectTarget.GetMapping()); Gather(targets, dataSetsHolder.DirectTarget, indices); } if (isTrivialLearnWeights) { weights = dataSetsHolder.DirectWeights.CopyView(); } else { weights.Reset(dataSetsHolder.DirectTarget.GetMapping()); Gather(weights, dataSetsHolder.DirectWeights, indices); } dataSetsHolder.PermutationDataSets[permutationId] = THolder<TFeatureParallelDataSet>(new TFeatureParallelDataSet(DataProvider, dataSetsHolder.CompressedIndex, permutationIndependentScope, new TPermutationScope(), *dataSetsHolder.LearnCatFeaturesDataSet, dataSetsHolder.GetCtrTargets(), TTarget<NCudaLib::TMirrorMapping>(std::move(targets), std::move(weights), std::move(indices)), std::move(inverseIndices), std::move(permutation))); } if (LinkedTest != nullptr) { BuildTestTargetAndIndices(dataSetsHolder, ctrsTarget); } auto allFeatures = GetLearnFeatureIds(FeaturesManager); TVector<ui32> permutationIndependent; TVector<ui32> permutationDependent; { SplitByPermutationDependence(FeaturesManager, allFeatures, permutationCount, &permutationIndependent, &permutationDependent); } auto learnMapping = dataSetsHolder.PermutationDataSets[0]->GetSamplesMapping(); TBinarizationInfoProvider learnBinarizationInfo(FeaturesManager, &DataProvider); const ui32 permutationIndependentCompressedDataSetId = compressedIndexBuilder.AddDataSet(learnBinarizationInfo, {"Learn permutation-independent features"}, learnMapping, permutationIndependent); for (ui32 permutationId = 0; permutationId < permutationCount; ++permutationId) { auto& dataSet = *dataSetsHolder.PermutationDataSets[permutationId]; if (permutationDependent.size()) { const auto& permutation = dataSet.GetCtrsEstimationPermutation(); TVector<ui32> gatherIndices; permutation.FillOrder(gatherIndices); auto composedSubsetIndexing = TDatasetPermutationOrderAndSubsetIndexing::ConstructShared( DataProvider.ObjectsData->GetFeaturesArraySubsetIndexing(), std::move(gatherIndices) ); TDataSetDescription description; description.Name = TStringBuilder() << "Learn permutation dependent features #" << permutationId; dataSet.PermutationDependentFeatures = compressedIndexBuilder.AddDataSet( learnBinarizationInfo, description, learnMapping, permutationDependent, composedSubsetIndexing ); } dataSet.PermutationIndependentFeatures = permutationIndependentCompressedDataSetId; } ui32 testDataSetId = -1; if (LinkedTest) { TDataSetDescription description; description.Name = "Test dataset"; TBinarizationInfoProvider testBinarizationInfo(FeaturesManager, LinkedTest); auto testMapping = dataSetsHolder.TestDataSet->GetSamplesMapping(); testDataSetId = compressedIndexBuilder.AddDataSet(testBinarizationInfo, description, testMapping, allFeatures); dataSetsHolder.TestDataSet->PermutationIndependentFeatures = testDataSetId; } compressedIndexBuilder.PrepareToWrite(); { TFloatAndOneHotFeaturesWriter<TFeatureParallelLayout> floatFeaturesWriter(FeaturesManager, compressedIndexBuilder, DataProvider, permutationIndependentCompressedDataSetId, /*skipExclusiveBundles=*/ false, localExecutor); floatFeaturesWriter.Write(permutationIndependent); } if (LinkedTest) { TFloatAndOneHotFeaturesWriter<TFeatureParallelLayout> floatFeaturesWriter(FeaturesManager, compressedIndexBuilder, *LinkedTest, testDataSetId, /*skipExclusiveBundles=*/ true, localExecutor); floatFeaturesWriter.Write(permutationIndependent); } { TBatchedBinarizedCtrsCalcer ctrsCalcer(FeaturesManager, ctrsTarget, DataProvider, dataSetsHolder.PermutationDataSets[0]->GetTarget().GetIndices(), LinkedTest, LinkedTest ? &dataSetsHolder.TestDataSet->GetTarget().GetIndices() : nullptr, localExecutor); TCtrsWriter<TFeatureParallelLayout> ctrsWriter(FeaturesManager, compressedIndexBuilder, ctrsCalcer, permutationIndependentCompressedDataSetId, testDataSetId); ctrsWriter.Write(permutationIndependent); } { TEstimatorsExecutor estimatorsExecutor(FeaturesManager, Estimators, dataSetsHolder.PermutationDataSets[0]->CtrsEstimationPermutation, localExecutor ); TMaybe<ui32> testId; if (LinkedTest) { testId = testDataSetId; } TEstimatedFeaturesWriter<TFeatureParallelLayout> writer(FeaturesManager, compressedIndexBuilder, estimatorsExecutor, permutationIndependentCompressedDataSetId, testId); writer.Write(permutationIndependent); } if (!permutationDependent.empty()) { for (ui32 permutationId = 0; permutationId < permutationCount; ++permutationId) { auto& ds = *dataSetsHolder.PermutationDataSets[permutationId]; //link common datasets if (permutationId > 0) { ds.PermutationIndependentFeatures = permutationIndependentCompressedDataSetId; } const NCB::TTrainingDataProvider* linkedTest = permutationId == 0 ? LinkedTest : nullptr; const TMirrorBuffer<const ui32>* testIndices = (permutationId == 0 && linkedTest) ? &dataSetsHolder.TestDataSet->GetTarget().GetIndices() : nullptr; { TBatchedBinarizedCtrsCalcer ctrsCalcer(FeaturesManager, ctrsTarget, DataProvider, ds.GetIndices(), linkedTest, testIndices, localExecutor); TCtrsWriter<TFeatureParallelLayout> ctrsWriter(FeaturesManager, compressedIndexBuilder, ctrsCalcer, ds.PermutationDependentFeatures, testDataSetId); ctrsWriter.Write(permutationDependent); } CATBOOST_DEBUG_LOG << "Ctr computation for permutation #" << permutationId << " is finished" << Endl; { TEstimatorsExecutor estimatorsExecutor(FeaturesManager, Estimators, dataSetsHolder.PermutationDataSets[permutationId]->CtrsEstimationPermutation, localExecutor ); TMaybe<ui32> testId; if (LinkedTest && permutationId == 0) { testId = testDataSetId; } TEstimatedFeaturesWriter<TFeatureParallelLayout> writer(FeaturesManager, compressedIndexBuilder, estimatorsExecutor, ds.PermutationDependentFeatures, testId); writer.Write(permutationDependent); CATBOOST_DEBUG_LOG << "Feature estimators for permutation #" << permutationId << " is finished" << Endl; } } } compressedIndexBuilder.Finish(); return dataSetsHolder; } void TFeatureParallelDataSetHoldersBuilder::BuildTestTargetAndIndices(TFeatureParallelDataSetsHolder& dataSetsHolder, const TCtrTargets<NCudaLib::TMirrorMapping>& ctrsTarget) { const auto testMapping = NCudaLib::TMirrorMapping(ctrsTarget.TestSlice.Size()); TMirrorBuffer<ui32> indices; indices.Reset(testMapping); MakeSequence(indices); TMirrorBuffer<ui32> inverseIndices = indices.CopyView(); auto targets = TMirrorBuffer<float>::CopyMapping(indices); targets.Write(*LinkedTest->TargetData->GetOneDimensionalTarget()); auto weights = TMirrorBuffer<float>::CopyMapping(indices); weights.Write(GetWeights(*LinkedTest->TargetData)); dataSetsHolder.TestDataSet.Reset(new TFeatureParallelDataSet(*LinkedTest, dataSetsHolder.CompressedIndex, new TPermutationScope(), new TPermutationScope(), *dataSetsHolder.TestCatFeaturesDataSet, dataSetsHolder.GetCtrTargets(), TTarget<NCudaLib::TMirrorMapping>(std::move(targets), std::move(weights), std::move(indices)), std::move(inverseIndices), GetPermutation(*LinkedTest, 0u, 1u)) ); dataSetsHolder.TestDataSet->LinkedHistoryForCtrs = dataSetsHolder.PermutationDataSets[0].Get(); } void TFeatureParallelDataSetHoldersBuilder::BuildCompressedCatFeatures(const NCB::TTrainingDataProvider& dataProvider, TCompressedCatFeatureDataSet& dataset, NPar::ILocalExecutor* localExecutor) { TCompressedCatFeatureDataSetBuilder builder(dataProvider, FeaturesManager, dataset, localExecutor); for (ui32 catFeature : FeaturesManager.GetCatFeatureIds()) { if (FeaturesManager.UseForTreeCtr(catFeature)) { builder.Add(catFeature); } } builder.Finish(); } }
;; ;; 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. ;; ;; In System V AMD64 ABI ;; callee saves: RBX, RBP, R12-R15 ;; Windows x64 ABI ;; callee saves: RBX, RBP, RDI, RSI, RSP, R12-R15 ;; ;; Linux/Windows clobbers: xmm0 - xmm15 ;; %include "include/os.asm" %include "include/imb_job.asm" %include "include/mb_mgr_datastruct.asm" %include "include/reg_sizes.asm" %include "include/memcpy.asm" ;%define DO_DBGPRINT %include "include/dbgprint.asm" extern sha256_ni %ifdef LINUX %define arg1 rdi %define arg2 rsi %define reg3 rcx %define reg4 rdx %else %define arg1 rcx %define arg2 rdx %define reg3 rdi %define reg4 rsi %endif %define state arg1 %define job arg2 %define len2 arg2 ; idx needs to be in rbx, rbp, r13-r15 %define last_len rbp %define idx rbp %define p r11 %define start_offset r11 %define unused_lanes rbx %define tmp4 rbx %define job_rax rax %define len rax %define size_offset reg3 %define tmp2 reg3 %define lane reg4 %define extra_blocks r8 %define tmp r9 %define p2 r9 %define lane_data r10 %define bswap_xmm4 xmm4 struc STACK _gpr_save: resq 4 ; rbx, rbp, rsi (win), rdi (win) _rsp_save: resq 1 endstruc section .data default rel align 16 byteswap: dq 0x0405060700010203 dq 0x0c0d0e0f08090a0b section .text %ifdef SHA224 ; JOB* submit_job_hmac_sha_224_ni_sse(MB_MGR_HMAC_SHA_256_OOO *state, IMB_JOB *job) ; arg 1 : state ; arg 2 : job MKGLOBAL(submit_job_hmac_sha_224_ni_sse,function,internal) submit_job_hmac_sha_224_ni_sse: %else ; JOB* submit_job_hmac_sha_256_ni_sse(MB_MGR_HMAC_SHA_256_OOO *state, IMB_JOB *job) ; arg 1 : state ; arg 2 : job MKGLOBAL(submit_job_hmac_sha_256_ni_sse,function,internal) submit_job_hmac_sha_256_ni_sse: %endif mov rax, rsp sub rsp, STACK_size and rsp, -16 mov [rsp + _gpr_save + 8*0], rbx mov [rsp + _gpr_save + 8*1], rbp %ifndef LINUX mov [rsp + _gpr_save + 8*2], rsi mov [rsp + _gpr_save + 8*3], rdi %endif mov [rsp + _rsp_save], rax ; original SP DBGPRINTL "enter sha256-ni-sse submit" mov unused_lanes, [state + _unused_lanes_sha256] movzx lane, BYTE(unused_lanes) DBGPRINTL64 "lane: ", lane shr unused_lanes, 8 imul lane_data, lane, _HMAC_SHA1_LANE_DATA_size ; SHA1 & SHA256 lane data is the same lea lane_data, [state + _ldata_sha256 + lane_data] mov [state + _unused_lanes_sha256], unused_lanes mov len, [job + _msg_len_to_hash_in_bytes] DBGPRINTL64 "length: ", len mov tmp, len shr tmp, 6 ; divide by 64, len in terms of blocks mov [lane_data + _job_in_lane], job mov dword [lane_data + _outer_done], 0 mov [state + _lens_sha256 + 2*lane], WORD(tmp) mov last_len, len and last_len, 63 lea extra_blocks, [last_len + 9 + 63] shr extra_blocks, 6 mov [lane_data + _extra_blocks], DWORD(extra_blocks) mov p, [job + _src] add p, [job + _hash_start_src_offset_in_bytes] mov [state + _args_data_ptr_sha256 + 8*lane], p cmp len, 64 jb copy_lt64 fast_copy: add p, len movdqu xmm0, [p - 64 + 0*16] movdqu xmm1, [p - 64 + 1*16] movdqu xmm2, [p - 64 + 2*16] movdqu xmm3, [p - 64 + 3*16] movdqa [lane_data + _extra_block + 0*16], xmm0 movdqa [lane_data + _extra_block + 1*16], xmm1 movdqa [lane_data + _extra_block + 2*16], xmm2 movdqa [lane_data + _extra_block + 3*16], xmm3 end_fast_copy: mov size_offset, extra_blocks shl size_offset, 6 sub size_offset, last_len add size_offset, 64-8 mov [lane_data + _size_offset], DWORD(size_offset) mov start_offset, 64 sub start_offset, last_len mov [lane_data + _start_offset], DWORD(start_offset) lea tmp, [8*64 + 8*len] bswap tmp mov [lane_data + _extra_block + size_offset], tmp mov tmp, [job + _auth_key_xor_ipad] movdqu xmm0, [tmp] movdqu xmm1, [tmp + 4*4] %if SHA256NI_DIGEST_ROW_SIZE != 32 %error "Below code has been optimized for SHA256NI_DIGEST_ROW_SIZE = 32!" %endif lea tmp, [lane*8] ; x8 here plus x4 scale factor give x32 movdqu [state + _args_digest_sha256 + tmp*4], xmm0 movdqu [state + _args_digest_sha256 + tmp*4 + 4*4], xmm1 DBGPRINTL "args digest:" DBGPRINT_XMM xmm0 DBGPRINT_XMM xmm1 test len, ~63 jnz ge64_bytes lt64_bytes: mov [state + _lens_sha256 + 2*lane], WORD(extra_blocks) lea tmp, [lane_data + _extra_block + start_offset] mov [state + _args_data_ptr_sha256 + 8*lane], tmp mov dword [lane_data + _extra_blocks], 0 ge64_bytes: cmp unused_lanes, 0xff jne return_null jmp start_loop align 16 start_loop: ; Find min length - only two lanes available xor len2, len2 mov tmp, 0x10000 mov WORD(len2), word [state + _lens_sha256 + 0*2] ; [0:15] - lane 0 length, [16:31] - lane index (0) mov WORD(tmp), word [state + _lens_sha256 + 1*2] ; [0:15] - lane 1 length, [16:31] - lane index (1) cmp WORD(len2), WORD(tmp) cmovg DWORD(len2), DWORD(tmp) ; move if lane 0 length is greater than lane 1 length mov idx, len2 ; retrieve index & length from [16:31] and [0:15] bit fields shr DWORD(idx), 16 and DWORD(len2), 0xffff je len_is_0 sub word [state + _lens_sha256 + 0*2], WORD(len2) sub word [state + _lens_sha256 + 1*2], WORD(len2) ; "state" and "args" are the same address, arg1 ; len is arg2 call sha256_ni ; state is intact len_is_0: ; process completed job "idx" imul lane_data, idx, _HMAC_SHA1_LANE_DATA_size lea lane_data, [state + _ldata_sha256 + lane_data] mov DWORD(extra_blocks), [lane_data + _extra_blocks] cmp extra_blocks, 0 jne proc_extra_blocks movdqa bswap_xmm4, [rel byteswap] cmp dword [lane_data + _outer_done], 0 jne end_loop proc_outer: mov dword [lane_data + _outer_done], 1 mov DWORD(size_offset), [lane_data + _size_offset] mov qword [lane_data + _extra_block + size_offset], 0 mov word [state + _lens_sha256 + 2*idx], 1 lea tmp, [lane_data + _outer_block] mov job, [lane_data + _job_in_lane] mov [state + _args_data_ptr_sha256 + PTR_SZ*idx], tmp %if SHA256NI_DIGEST_ROW_SIZE != 32 %error "Below code has been optimized for SHA256NI_DIGEST_ROW_SIZE = 32!" %endif lea tmp4, [idx*8] ; x8 here + scale factor x4 below give x32 movdqu xmm0, [state + _args_digest_sha256 + tmp4*4] movdqu xmm1, [state + _args_digest_sha256 + tmp4*4 + 4*4] pshufb xmm0, bswap_xmm4 pshufb xmm1, bswap_xmm4 movdqa [lane_data + _outer_block], xmm0 movdqa [lane_data + _outer_block + 4*4], xmm1 %ifdef SHA224 ;; overwrite top 4 bytes with 0x80 mov dword [lane_data + _outer_block + 7*4], 0x80 %endif mov tmp, [job + _auth_key_xor_opad] movdqu xmm0, [tmp] movdqu xmm1, [tmp + 4*4] movdqu [state + _args_digest_sha256 + tmp4*4], xmm0 movdqu [state + _args_digest_sha256 + tmp4*4 + 4*4], xmm1 jmp start_loop align 16 proc_extra_blocks: mov DWORD(start_offset), [lane_data + _start_offset] mov [state + _lens_sha256 + 2*idx], WORD(extra_blocks) lea tmp, [lane_data + _extra_block + start_offset] mov [state + _args_data_ptr_sha256 + PTR_SZ*idx], tmp mov dword [lane_data + _extra_blocks], 0 jmp start_loop align 16 copy_lt64: ;; less than one message block of data ;; beginning of source block ;; destination extrablock but backwards by len from where 0x80 pre-populated ;; p2 clobbers unused_lanes, undo before exit lea p2, [lane_data + _extra_block + 64] sub p2, len memcpy_sse_64_1 p2, p, len, tmp4, tmp2, xmm0, xmm1, xmm2, xmm3 mov unused_lanes, [state + _unused_lanes_sha256] jmp end_fast_copy return_null: xor job_rax, job_rax jmp return align 16 end_loop: mov job_rax, [lane_data + _job_in_lane] mov unused_lanes, [state + _unused_lanes_sha256] mov qword [lane_data + _job_in_lane], 0 or dword [job_rax + _status], IMB_STATUS_COMPLETED_AUTH shl unused_lanes, 8 or unused_lanes, idx mov [state + _unused_lanes_sha256], unused_lanes mov p, [job_rax + _auth_tag_output] ; copy 16 bytes for SHA256, 14 for SHA224 %if SHA256NI_DIGEST_ROW_SIZE != 32 %error "Below code has been optimized for SHA256NI_DIGEST_ROW_SIZE = 32!" %endif shl idx, 5 %ifdef SHA224 cmp qword [job_rax + _auth_tag_output_len_in_bytes], 14 jne copy_full_digest %else cmp qword [job_rax + _auth_tag_output_len_in_bytes], 16 jne copy_full_digest %endif movdqu xmm0, [state + _args_digest_sha256 + idx] pshufb xmm0, bswap_xmm4 %ifdef SHA224 ;; SHA224 movq [p + 0*4], xmm0 pextrd [p + 2*4], xmm0, 2 pextrw [p + 3*4], xmm0, 6 %else ;; SHA256 movdqu [p], xmm0 %endif jmp clear_ret copy_full_digest: movdqu xmm0, [state + _args_digest_sha256 + idx] movdqu xmm1, [state + _args_digest_sha256 + idx + 16] pshufb xmm0, bswap_xmm4 pshufb xmm1, bswap_xmm4 %ifdef SHA224 ;; SHA224 movdqu [p], xmm0 movq [p + 16], xmm1 pextrd [p + 16 + 8], xmm1, 2 %else ;; SHA256 movdqu [p], xmm0 movdqu [p + 16], xmm1 %endif clear_ret: %ifdef SAFE_DATA pxor xmm0, xmm0 ;; Clear digest, outer_block (28B/32B) and extra_block (64B) of returned job movdqa [state + _args_digest_sha256 + idx], xmm0 movdqa [state + _args_digest_sha256 + idx + 16], xmm0 shr idx, 5 ;; Restore lane idx to 0 or 1 imul lane_data, idx, _HMAC_SHA1_LANE_DATA_size lea lane_data, [state + _ldata_sha256 + lane_data] ;; Clear first 64 bytes of extra_block %assign offset 0 %rep 4 movdqa [lane_data + _extra_block + offset], xmm0 %assign offset (offset + 16) %endrep ;; Clear first 28 bytes (SHA-224) or 32 bytes (SHA-256) of outer_block movdqa [lane_data + _outer_block], xmm0 %ifdef SHA224 mov qword [lane_data + _outer_block + 16], 0 mov dword [lane_data + _outer_block + 24], 0 %else movdqa [lane_data + _outer_block + 16], xmm0 %endif %endif ;; SAFE_DATA return: mov rbx, [rsp + _gpr_save + 8*0] mov rbp, [rsp + _gpr_save + 8*1] %ifndef LINUX mov rsi, [rsp + _gpr_save + 8*2] mov rdi, [rsp + _gpr_save + 8*3] %endif mov rsp, [rsp + _rsp_save] ; original SP ret %ifdef LINUX section .note.GNU-stack noalloc noexec nowrite progbits %endif
.filenamespace DemonsMadeMeDoADemo_DMS :BasicUpstart2(mainStartup) //---------------------------------------------------------- // Variables //---------------------------------------------------------- .const D = 0 .const A = 1 .const M = 2 .const O = 3 .const N = 4 .const EE = 5 .const S = 6 .const Sp = 7 .var debug = false .var music = LoadSid("Nevernever201708230d.sid") .const irqpointer = $0314 .const scrollLine = 24 //---------------------------------------------------------- //---------------------------------------------------------- // Main Startup Code //---------------------------------------------------------- mainStartup: * = mainStartup "Main Startup" sei :SetupIRQ(examplePart.partIrqStart, examplePart.partIrqStartLine, false) :FillScreen($0400,$20,$d800,BLACK) :CopyLogo(logo, logo + $300, $d800, $e800) jsr examplePart.partInit cli jmp examplePart.partJump examplePart: { .pc = $0b00 "ExamplePart" //---------------------------------------------------------- .label partIrqStartLine = $14 .label spriteIrqStartLine = $1b .label scrollIrqStartLine = $96 .label musicIrqStartLine = $A9 .label scrollTopSpritesStartLine = $bf .label openBordersLine = $fa //---------------------------------------------------------- partInit: // init music ldx #0 ldy #0 lda #music.startSong-1 jsr music.init // init sprites lda #%01111111 // set sprites 0-7 on sta $d015 .for (var i = 0; i < 7; i++) { lda #$C0 + i sta $07F8 + i } lda #$ff // stretch sprite x sta $d01d lda #0 sta spriteXPtr // sprite x ptr sta spriteYPtr // sprite y ptr sta spriteXLocPtr // sprite x loc ptr // init scroll sta scrollTextSmooth lda #<scrollText sta scrollTextPtr lda #>scrollText sta scrollTextPtr + 1 ldx #0 !: lda (scrollPalette), x sta $d800 + (40 * scrollLine), x inx cpx #40 bne !- lda $d016 and #%11110111 sta $d016 rts //---------------------------------------------------------- partIrqStart: { // reset smooth scroll... lda #$1b sta $d011 lda #0 sta $d015 DebugRaster(1) lda $d016 and #%11111000 sta $d016 .for (var i = 0; i < 8; i++) { lda #$C0 + i sta $07F8 + i } lda #0 sta $d020 sta $d021 :EndIRQ(SpriteIrqStart,spriteIrqStartLine,false) } SpriteIrqStart: { DebugRaster(2) lda #$ff sta $d015 dec spriteXPtr // sprite x ptr dec spriteYPtr // sprite y ptr dec spriteYPtr dec spriteXLocPtr // sprite x loc ptr dec spriteXLocPtr dec spriteXLocPtr ldy #0 sty spriteHiLoTmp .for (var j=0; j<7; j++) { lda spriteXPtr adc #23 * j tax lda sinTblX, x ldx spriteXLocPtr adc sinTblY, x sta $d000 + j * 2 bcc no_overflow tya ora #1 << j tay no_overflow: lda spriteYPtr adc #17 * j tax lda sinTblY, x adc #40 sta $d001 + j * 2 txa ror clc ror clc tax lda spritePalette, x sta $d027 + j lda spriteHiLo, x cmp #1 bne !+ lda spriteHiLoTmp ora #1 << j sta spriteHiLoTmp !: } tya sta $d010 lda spriteHiLoTmp sta $d01B DebugRaster(0) :EndIRQ(scrollIrqStart,scrollIrqStartLine,false) } scrollIrqStart: { DebugRaster(1) dec scrollTextSmooth lda scrollTextSmooth and #%00000111 tax lda $d016 and #%11111000 sta $d016 txa ora $d016 sta $d016 txa cmp #7 bne onlysmooth lda scrollTextPtr adc #0 sta scrollTextPtr bcc !+ lda scrollTextPtr + 1 adc #0 sta scrollTextPtr + 1 !: onlysmooth: ldy #0 ldx #40 !: lda (scrollTextPtr), y sta $0400 + (40 * scrollLine), y iny dex bne !- lda (scrollTextPtr), y cmp #0 bne !+ lda #<scrollText sta scrollTextPtr lda #>scrollText sta scrollTextPtr + 1 !: DebugRaster(0) :EndIRQ(musicIrqStart,musicIrqStartLine,false) } musicIrqStart: { DebugRaster(4) jsr music.play DebugRaster(0) :EndIRQ(scrollTopSprites,scrollTopSpritesStartLine,false) } openBorders: { lda #0 sta $d015 lda #0 sta $d011 :EndIRQ(partIrqStart,partIrqStartLine,false) } partJump: jmp * } * = $4000 "scrollText" sinTblX: .byte 100,102,104,107,109,112,114,117,119,121,124,126,129,131,133,135,138,140,142,144,147,149,151,153,155,157,159,161,163,165,167,168,170,172,174,175,177,178,180,181,183,184,185,187,188,189,190,191,192,193,194,194,195,196,197,197,198,198,198,199,199,199,199,199,200,199,199,199,199,199,198,198,198,197,197,196,195,194,194,193,192,191,190,189,188,187,185,184,183,181,180,178,177,175,174,172,170,168,167,165,163,161,159,157,155,153,151,149,147,144,142,140,138,135,133,131,129,126,124,121,119,117,114,112,109,107,104,102,100,97,95,92,90,87,85,82,80,78,75,73,70,68,66,64,61,59,57,55,52,50,48,46,44,42,40,38,36,34,32,31,29,27,25,24,22,21,19,18,16,15,14,12,11,10,9,8,7,6,5,5,4,3,2,2,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,2,2,3,4,5,5,6,7,8,9,10,11,12,14,15,16,18,19,21,22,24,25,27,29,31,32,34,36,38,40,42,44,46,48,50,52,55,57,59,61,64,66,68,70,73,75,78,80,82,85,87,90,92,95,97 sinTblY: .byte 64,65,67,68,70,71,73,74,76,78,79,81,82,84,85,87,88,89,91,92,94,95,96,98,99,100,102,103,104,105,106,108,109,110,111,112,113,114,115,116,117,118,118,119,120,121,121,122,123,123,124,124,125,125,126,126,126,127,127,127,127,127,127,127,128,127,127,127,127,127,127,127,126,126,126,125,125,124,124,123,123,122,121,121,120,119,118,118,117,116,115,114,113,112,111,110,109,108,106,105,104,103,102,100,99,98,96,95,94,92,91,89,88,87,85,84,82,81,79,78,76,74,73,71,70,68,67,65,64,62,60,59,57,56,54,53,51,49,48,46,45,43,42,40,39,38,36,35,33,32,31,29,28,27,25,24,23,22,21,19,18,17,16,15,14,13,12,11,10,9,9,8,7,6,6,5,4,4,3,3,2,2,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,2,2,3,3,4,4,5,6,6,7,8,9,9,10,11,12,13,14,15,16,17,18,19,21,22,23,24,25,27,28,29,31,32,33,35,36,38,39,40,42,43,45,46,48,49,51,53,54,56,57,59,60,62 sinTblTextX: .byte 0,0,0,0,0,0,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,4,4,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,6,6,6,6,6,6,6,6,6,5,5,5,5,5,5,5,4,4,4,4,4,4,3,3,3,3,3,3,2,2,2,2,2,1,1,1,1,1,0,0,0,0,0,0,-1,-1,-1,-1,-1,-2,-2,-2,-2,-2,-3,-3,-3,-3,-3,-4,-4,-4,-4,-4,-4,-5,-5,-5,-5,-5,-5,-6,-6,-6,-6,-6,-6,-6,-7,-7,-7,-7,-7,-7,-7,-7,-7,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-7,-7,-7,-7,-7,-7,-7,-7,-7,-6,-6,-6,-6,-6,-6,-6,-5,-5,-5,-5,-5,-5,-4,-4,-4,-4,-4,-4,-3,-3,-3,-3,-3,-2,-2,-2,-2,-2,-1,-1,-1,-1,-1 .byte 0,0,0,0,0,0,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,4,4,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,6,6,6,6,6,6,6,6,6,5,5,5,5,5,5,5,4,4,4,4,4,4,3,3,3,3,3,3,2,2,2,2,2,1,1,1,1,1,0,0,0,0,0,0,-1,-1,-1,-1,-1,-2,-2,-2,-2,-2,-3,-3,-3,-3,-3,-4,-4,-4,-4,-4,-4,-5,-5,-5,-5,-5,-5,-6,-6,-6,-6,-6,-6,-6,-7,-7,-7,-7,-7,-7,-7,-7,-7,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-7,-7,-7,-7,-7,-7,-7,-7,-7,-6,-6,-6,-6,-6,-6,-6,-5,-5,-5,-5,-5,-5,-4,-4,-4,-4,-4,-4,-3,-3,-3,-3,-3,-2,-2,-2,-2,-2,-1,-1,-1,-1,-1 spritePalette: .byte 1, 1, 1, 1, 1, 1, 1, 1 .byte 1, 1, 1, 1, 3, 3, 3,14 .byte 14,14, 6, 6, 6,11,11,11 .byte 0, 0, 0, 0, 0, 0, 0, 0 .byte 0, 0, 0, 0, 0, 0, 0, 0 .byte 11,11,11, 6, 6, 6,14,14 .byte 14, 3, 3, 3, 1, 1, 1, 1 .byte 1, 1, 1, 1, 1, 1, 1, 1 spriteHiLo: .byte 0, 0, 0, 0, 0, 0, 0, 0 .byte 0, 0, 0, 0, 0, 0, 0, 0 .byte 1, 1, 1, 1, 1, 1, 1, 1 .byte 1, 1, 1, 1, 1, 1, 1, 1 .byte 1, 1, 1, 1, 1, 1, 1, 1 .byte 1, 1, 1, 1, 1, 1, 1, 1 .byte 0, 0, 0, 0, 0, 0, 0, 0 .byte 0, 0, 0, 0, 0, 0, 0, 0 textSpriteArr: .byte 7,7,7,7,7,7,7,7 .byte 7,7,7,7,7,7,7,7 .byte D,A,M,O,N,EE,S,Sp .byte D,EE,EE,M,EE,D,Sp,Sp .byte Sp,D,O,D,O,S,Sp,Sp .byte 7,7,7,7,7,7,7,7 .byte Sp,D,O,O,M,EE,D,Sp .byte Sp,M,EE,A,N,Sp,Sp,Sp .byte Sp,EE,N,EE,M,A,Sp,Sp .byte Sp,M,EE,M,EE,Sp,Sp,Sp .byte 7,7,7,7,7,7,7,7 .byte Sp,S,EE,M,EE,N,Sp,Sp .byte Sp,Sp,M,EE,A,D,Sp,Sp .byte Sp,A,M,EE,N,D,S,Sp .byte Sp,D,A,M,EE,S,Sp,Sp .byte 7,7,7,7,7,7,7,7 .byte Sp,Sp,D,EE,EE,D,Sp,Sp .byte Sp,Sp,D,O,N,EE,Sp,Sp .byte Sp,Sp,Sp,EE,O,N,Sp,Sp .byte Sp,Sp,EE,N,D,S,Sp,Sp .byte 7,7,7,7,7,7,7,7 .byte Sp,N,O,M,A,D,S,Sp,Sp .byte Sp,M,O,A,N,Sp,Sp,Sp .byte Sp,A,M,EE,N,Sp,Sp,Sp .byte 7,7,7,7,7,7,7,7 .byte D,EE,M,O,N,S,Sp,Sp .byte Sp,M,A,D,EE,Sp,Sp,Sp .byte Sp,Sp,M,EE,Sp,Sp,Sp,Sp .byte Sp,Sp,D,O,Sp,Sp,Sp,Sp .byte A,Sp,D,EE,M,O,Sp,Sp .byte 7,7,7,7,7,7,7,7 .byte 7,7,7,7,7,7,7,7 spriteTextPalette: .byte 0,11, 6,14, 3, 1, 1, 1 .byte 1, 1, 1, 3,14, 6, 11,0 .byte 0,11, 6,14, 3, 1, 1, 1 .byte 1, 1, 1, 3,14, 6, 11,0 spriteKerning: .byte 4, 2, 4, 2, -4, 10, 4, 4 .byte 4, 0, 4, 4, 3, 2, 8, 8 scrollText: .text " hello! my name is zados of damones, the true founder of it with irwin the magnificent boozer. damones was a joke, still is but still standing, so no worries about that... i love c64 bcos it was my first compuke, not forgetting amiga but i lost them both over 20 years ago. you know, emulating them is mastubating. no more c64, no more amiga. only personal cerebral compuking nowadays. once upon a time there was mhz, now ghz and tomorrow thz but you only need 1 mhz to prove you are living. pixelate your brains. be brave and drunk. this scroll shall be in a product / demo i have never heard of, but i am forced to write some words of wastedom. madness! at this point i would love to send my regards to lamers. scream your dreams, whisk your creams. fuck, i am tired of writing and thinking... too many beers. too drunk to fuck et cetera. a new start tomorrow... i thank you for the years, 26 years... i don't know why but grab a brew for it. and tomorrow i shan't drink never again ever! common thread is lost, totally. damones makes sense. suck my cucumber, rabbits! this is the end, finally. zados says goofoo! demons made me do a demo -- a quick and dirty hack for psykoz 2017 -- code: kakka -- music: zardax / ald -- gfx: h7 -- text: zados special greetings fly to spaceman x :) " scrollTextEnd: .byte 0 scrollPalette: .byte 11, 6, 14, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 14, 6, 11, 11 * = $2000 "Logo" logo: .byte 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32 .byte 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32 .byte 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32 .byte 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32 .byte 32,32,32,32,85,255,32,32,32,32,32,32,32,32,86,123,32,32,32,32,32,32,32,32,32,108,86,104,98,98,98,85,98,98,123,32,32,32,32,32,32,32,32,32,74,224,98,98,123,104,32,32,32,32,32,251,123,32,32,32,32,32,32,32,108,236,32,224,224,236,226,105,224,224,92,32,32,32,32,32,111,111,111,111,108,98,124,226,251,224,252,98,98,111,225,255,224,123,111,111,111,111,111,108,224,97,252,98,224,98,111,124,226,251,32,111,111,111,111,111,111,111,111,111,32,224,224,92,111,111,95,236,224,224,97,224,254,224,123,111,111,111,108,224,127,224,104,124,226,251,224,252,123,32,111,111,111,111,111,111,111,32,32,111,111,251,224,97,111,111,32,95,234,224,97,251,244,224,224,123,32,108,224,224,224,224,222,224,105,123,124,224,224,252,123,111,32,32,111,111,32,77,32,77,77,225,224,92,67,32,77,106,224,224,97,251,224,234,124,224,98,224,105,244,224,224,244,224,236,67,67,225,163,224,251,32,77,32,77,77,111,111,77,78,78,124,224,224,223,32,108,233,224,105,116,225,224,224,123,124,224,105,108,224,224,97,224,163,252,32,32,254,224,224,97,111,111,77,78,78,67,67,67,67,67,67,224,224,224,252,224,224,105,126,67,225,224,226,126,67,67,67,225,236,126,67,74,224,224,252,224,224,224,236,67,67,67,67,67,67,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,14,14,14,14,14,6,5,5,5,14,14,14,14,10,6,6,6,14,14,14,14,14,14,6,6,6,6,6,6,3,6,14,3,14,6,14,14,14,14,14,14,14,14,14,6,14,14,14,6,6,14,14,14,14,10,14,6,14,14,14,14,14,14,14,6,6,5,14,3,3,14,14,3,14,6,14,14,14,14,14,11,11,11,11,6,6,6,14,14,3,3,6,6,6,6,14,1,14,11,12,1,12,11,6,1,6,6,14,14,14,6,6,14,6,14,11,11,12,15,1,12,12,1,15,14,14,3,14,11,12,14,3,1,3,6,14,1,14,6,11,12,11,6,3,3,14,6,6,14,14,14,6,6,5,11,15,15,12,12,11,1,1,14,11,11,14,3,14,11,12,14,14,1,14,6,14,1,14,14,6,12,6,14,14,3,14,3,1,14,6,6,3,3,6,6,11,12,14,15,11,12,1,12,11,11,6,14,14,11,12,12,6,3,14,6,6,3,14,6,14,14,14,14,14,14,14,14,1,6,11,11,14,3,14,6,14,12,15,1,11,11,11,15,11,11,6,14,14,14,14,6,14,14,14,6,6,14,14,6,6,14,14,6,14,14,6,14,3,6,14,14,14,14,14,6,11,11,15,1,11,11,11,11,11,11,11,6,14,14,14,14,14,14,6,11,6,3,14,6,11,11,11,6,6,14,11,14,14,14,6,14,14,14,6,11,11,11,11,11,11,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,10,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,10,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,10,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,10,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,10,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14 logoEnd: scrollTopSprites: { DebugRaster(7) lda textSpriteXPtr adc #1 sta textSpriteXPtr clc lda textSpriteSlow adc #1 clc sta textSpriteSlow cmp #15 bne !+ lda #0 sta textSpriteSlow clc lda textSpritePtr adc #1 sta textSpritePtr !: lda textSpritePtr clc ror clc ror clc ror clc rol rol rol pha lda #0 sta textSpriteHiXPos sta textSpritestartPos sta textSpritestartPos + 1 clc lda textSpriteSlow sta textSpriteColor pla tax .for (var i = 0; i < 8; i++) { lda #214 sta $D001 + i * 2 clc lda textSpriteArr, x adc #$C0 clc sta $07F8 + i lda textSpriteArr, x rol tay txa pha lda i * 11 adc textSpriteXPtr tax ldx textSpriteXPtr lda #36 adc sinTblTextX + i * 17, x clc sta textSpriteXJemma pla tax lda textSpriteXJemma sbc spriteKerning, y clc adc textSpritestartPos + 1 sta textSpritestartPos + 1 bcc !+ lda textSpritestartPos adc #0 sta textSpritestartPos lda textSpriteHiXPos ora #1 << i sta textSpriteHiXPos !: lda textSpritestartPos + 1 sta $d000 + i * 2 adc spriteKerning + 1, y sta textSpritestartPos + 1 bcc !+ lda textSpritestartPos adc #1 sta textSpritestartPos clc !: txa pha ldx textSpriteColor lda spriteTextPalette + i, x sta $d027 + i pla tax inx } lda textSpriteHiXPos sta $d010 /* lda #%00000000 sta $d010 */ DebugRaster(0) :EndIRQ(examplePart.openBorders,examplePart.openBordersLine,false) } * = $10 "Zeropage" virtual .zp { spriteXPtr: .byte 0 spriteYPtr: .byte 0 spriteXLocPtr: .byte 0 spriteHiLoTmp: .byte 0 textSpriteHiXPos: .byte 0 textSpritePtr: .byte 0 textSpritestartPos: .word 0 textSpriteXPtr: .byte 0 textSpriteXJemma: .byte 0 .byte 0 .byte 0 .byte 0 .byte 0 textSpriteSlow: .byte 0 textSpriteColorCounter: .word 0 textSpriteColor: .byte 0 } scrollTextSmooth: .byte 0 scrollTextPtr: .byte 0,0 // //---------------------------------------------------------- //---------------------------------------------------------- // Macros //---------------------------------------------------------- .macro SetupIRQ(IRQaddr,IRQline,IRQlineHi) { lda #<IRQaddr sta irqpointer lda #>IRQaddr sta irqpointer+1 lda #$1f sta $dc0d sta $dd0d lda #$81 sta $d01a sta $d019 .if(IRQlineHi) { lda #$9b } else { lda #$1b } sta $d011 lda #IRQline sta $d012 } //---------------------------------------------------------- .macro EndIRQ(nextIRQaddr,nextIRQline,IRQlineHi) { asl $d019 lda #<nextIRQaddr sta irqpointer lda #>nextIRQaddr sta irqpointer+1 lda #nextIRQline sta $d012 .if(IRQlineHi) { lda $d011 ora #$80 sta $d011 } jmp $febc } .macro FillScreen(screen,char,colorbuff,color) { ldx #$00 loop: .for(var i=0; i<3; i++) { lda #char sta screen+[i*$100],x lda #color sta colorbuff+[i*$100],x } lda #char sta screen+[$2e8],x lda #color sta colorbuff+[$2e8],x inx bne loop } .macro CopyLogo(charStart, colorStart, charTargetStart, colorTargetStart) { lda #>charStart sta $fc lda #<charStart sta $fd lda #$04 sta $fe lda #>colorTargetStart sta $f9 lda #>colorStart sta $fa lda #<colorStart sta $fb lda #>charTargetStart sta $f8 lda #<charTargetStart sta $f7 ldx #$00 ldy #$00 loop: lda ($fb),y sta ($fd),y lda ($f9),y sta ($f7),y iny bne loop inc $fc inc $fe inc $fa inc $f8 inx cpx #$02 bne loop } .macro DebugRaster(color) { .if (debug) { pha lda #0 + color sta $d020 sta $d021 pla } } *=music.location "Music" .fill music.size, music.getData(i) * = $3000 "Sprites" .var sprites = LoadPicture("damones_sprite.png") .for (var s = 0; s < 8; s++) { .for (var y=0; y<21; y++) { .for (var x=0; x<3; x++) .byte sprites.getSinglecolorByte(x, y + (s * 21)) } .byte 0 // padding } .print "" .print "SID Data" .print "--------" .print "location=$"+toHexString(music.location) .print "init=$"+toHexString(music.init) .print "play=$"+toHexString(music.play) .print "songs="+music.songs .print "startSong="+music.startSong .print "size=$"+toHexString(music.size) .print "name="+music.name .print "author="+music.author .print "copyright="+music.copyright .print "" .print "Additional tech data" .print "--------------------" .print "header="+music.header .print "header version="+music.version .print "flags="+toBinaryString(music.flags) .print "speed="+toBinaryString(music.speed) .print "startpage="+music.startpage .print "pagelength="+music.pagelength
; DV3 QLWA Format V3.01  1992 Tony Tebby ; ; 2020-04-07 3.01 Changed for new ddf_mname format with size word (MK) section dv3 xdef qlf_ftwa include 'dev8_dv3_keys' include 'dev8_dv3_qlf_keys' include 'dev8_keys_qlwa' include 'dev8_keys_err' include 'dev8_keys_sys' include 'dev8_keys_hdr' include 'dev8_mac_assert' ;+++ ; DV3 QLWA Format ; ; This sets up the blank map and header and flushes it. ; It also sets the good and free allocation units into the drive definition ; (as well as the inbuild file header length) and sets the medium to "good" ; before the flush. ; ; d0 cr format type / error code ; d7 c p drive ID / number ; a0 c p pointer to bad sector map or 0 ; a3 c p pointer to linkage ; a4 c p pointer to drive definition ; ; status return standard ; ;--- qlf_ftwa qfm.reg reg d1/d2/d3/d4/d5/d6/a0/a1/a2 movem.l qfm.reg,-(sp) move.l ddf_atotal(a4),d2 ; total allocation move.l d2,d0 subq.l #1,d0 lsr.l #1,d0 moveq #0,d1 ; good sector lea qdf_map+qwa_gmap(a4),a1 qfm_smgood move.l d1,(a1)+ ; mark all sectors good dbra d0,qfm_smgood move.w ddf_asect(a4),d3 ; allocation size move.l d2,d1 ; total allocation move.l a0,d0 ; bad sector map beq.s qfm_link ; ... none tst.b (a0) ; bad sector list? bmi.l qfm_fmtf ; ... yes, cannot handle this move.l d2,d4 mulu d3,d4 ; sectors to check moveq #0,d0 ; sector being checked qfm_ckloop move.b (a0)+,d5 ; next eight sectors all alright? beq.s qfm_cklend ; ... yes qfm.regb reg d0/d1/d7 movem.l qfm.regb,-(sp) move.w #7,d1 ; check all seven bits qfm_ckbits add.b d5,d5 bcc.s qfm_ckbend ; this bit is ok move.l d0,d6 divu d3,d6 ; logical group moveq #0,d7 move.w d6,d7 add.l d7,d7 ; position in map lea qdf_map+qwa_gmap(a4),a2 tst.w (a2,d7.l) ; already a bad sector in this one? beq.s qfm_ckbend ; ... yes neg.w (a2,d7.l) ; it is bad now subq.w #1,d2 ; one fewer groups qfm_ckbend addq.l #1,d0 ; next sector of bad byte dbra d1,qfm_ckbits movem.l (sp)+,qfm.regb qfm_cklend addq.l #8,d0 ; next byte cmp.l d4,d0 blt.s qfm_ckloop ; bad groups are marked, d1 is total, d2 good, link up the map list qfm_link lea qdf_map+qwa_gmap(a4),a0 ; first map group moveq #1,d0 move.w qdf_msect(a4),d6 ; number of map sectors moveq #0,d4 move.w d6,d4 subq.w #1,d4 divu ddf_asect(a4),d4 addq.w #1,d4 ; number of map groups qfm_smap tst.w (a0) ; must be OK bne.l qfm_fmtf move.w d0,(a0)+ ; link to next addq.w #1,d0 cmp.w d4,d0 ble.s qfm_smap clr.w -2(a0) ; last is zero tst.w (a0)+ bne.l qfm_fmtf ; directory sector is next tst.w (a0)+ ; for simplicity, this must be good bne.l qfm_fmtf move.l a0,a1 addq.w #1,d0 ; next qfm_lklp tst.w (a1)+ ; next ok? bne.s qfm_lkle ; ... no move.w d0,-(a0) ; ... yes, set number (back a bit!!) move.l a1,a0 ; and set next to fill in qfm_lkle addq.w #1,d0 ; next cmp.w d1,d0 ; all done? blo.s qfm_lklp ; group map is set up, set the header lea qdf_map(a4),a2 ; fill in header assert 0,qwa_id,qwa_name-4,qwa_spr0-$1a,qwa_uchk-$1c move.l #qwa.id,(a2)+ ; ID lea ddf_mname(a4),a1 move.w (a1)+,d5 move.w d5,(a2)+ ; name length bra.s qfm_cpy_start qfm_cpy_name move.b (a1)+,(a2)+ qfm_cpy_start dbf d5,qfm_cpy_name lea qdf_map+qwa_spr0(a4),a1 ; fill up to here with spaces qfm_name_fill cmp.l a2,a1 beq.s qfm_name_done move.b #' ',(a2)+ bra.s qfm_name_fill qfm_name_done clr.w (a2)+ ; 2 spare bytes move.w sys_rand(a6),(a2)+ ; msw update clr.w (a2)+ ; clear lsw update moveq #0,d0 assert qwa_uchk+4,qwa_intl,qwa_sctg-2,qwa_sctt-4,qwa_trkc-6,qwa_cyld-8 clr.w (a2)+ ; interleave move.w d3,(a2)+ ; sectors per group move.w ddf_strk(a4),(a2)+ ; sectors per track move.w ddf_heads(a4),(a2)+ ; tracks per cyl beq.s qfm_cyld move.w ddf_atotal(a4),d0 mulu ddf_asect(a4),d0 swap d0 move.l d0,-(sp) move.w ddf_atotal+2(a4),d0 mulu ddf_asect(a4),d0 add.l (sp)+,d0 ; total sectors subq.l #1,d0 ; round up cylinders divu ddf_scyl(a4),d0 addq.w #1,d0 qfm_cyld move.w d0,(a2)+ ; cylinders per drive move.w d4,d5 ; number of map groups addq.w #1,d5 ; first free assert qwa_cyld+2,qwa_ngrp,qwa_fgrp-2,qwa_sctm-4,qwa_nmap-6 move.w d2,(a2)+ ; number of groups move.l d2,d0 ; good sub.w d5,d0 ; ... less map and dir move.w d0,(a2)+ ; free groups move.w d6,(a2)+ ; sectors per map move.w #1,(a2)+ ; number of maps assert qwa_nmap+2,qwa_free,qwa_root-2,qwa_rlen-4,qwa_fsct-8 move.w d5,(a2)+ ; first free move.w d4,(a2)+ ; root dir first group = ID moveq #hdr.len,d5 move.l d5,(a2)+ ; end of directory move.l ddf_psoff(a4),(a2)+ ; start sector clr.w (a2) ; park cylinder lea ddf_agood(a4),a2 ; set remaining bits of drive def assert ddf_agood,ddf_afree-4,ddf_fhlen-8 move.l d2,(a2)+ move.l d0,(a2)+ move.l d5,(a2)+ move.w d4,ddf_rdid+2(a4) ; including root dir ID ; all set up, flush it lea qdf_mupd(a4),a2 qfm_mulp st (a2)+ ; mark all map sectors updated subq.w #1,d6 bgt.s qfm_mulp assert ddf.mok,$ff st ddf_mstat(a4) st ddf_mupd(a4) ; map updated jsr ddl_dflush(a3) ; flush qfm_ok moveq #0,d0 qfm_exit movem.l (sp)+,qfm.reg rts qfm_fmtf moveq #err.fmtf,d0 bra.s qfm_exit end
;;----------------------------------------------------------------------------;; ;; Use the familiar long name in Zoom menu ;; Copyright 2014 Benito Palacios (aka pleonex) ;; ;; 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. ;;----------------------------------------------------------------------------;; @LongNameOffset equ 0xB4 .thumb .org 0x0215B628 ADD r5, 0x68 ADD r0, r5, 0x4 LDR r1, [r5,#0] BL 0x020DE2A8 ADD r0, r5, 0x4 ADD r4, @LongNameOffset ; All that code just to get a space for this line... MOV R1, #1 BL 0x020DE2AC ADD r0, r5, 0x4 MOV R6, #5 SUB r5, 0x68
; ::: #d8 0 #addr 0 ; error: behind ; ::: #addr -1 ; error: valid range ; ::: #d8 0 #d8 1 #addr 0x2 ; = 0x0001 ; ::: #d8 0 #d8 1 #d8 2 #addr 0x2 ; error: behind ; ::: #d8 0 #d8 1 #d8 2 #d8 3 #addr 0x2 ; error: behind ; ::: #bankdef non_writable { #addr 0, #size 10 } #res 1 #res 1 #res 1 #res 1 #addr 0x2 ; ::: #bankdef non_writable { #addr 0, #size 10 } #res 1 #res 1 #res 1 #res 1 #addr -1 ; error: valid range
#include "testcrypt.h" #include <crypt.h> std::string crypt_something() { char const* result = crypt("will error out", "\0"); if (result == NULL) { return std::string("*"); } return std::string(result); }
;Copyright (c) 1987, 1990, 1993, 2005 Vrije Universiteit, Amsterdam, The Netherlands. ;All rights reserved. ; ;Redistribution and use of the Amsterdam Compiler Kit 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 Vrije Universiteit nor the names of the ; software authors or 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, AUTHORS, 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 VRIJE UNIVERSITEIT OR ANY AUTHORS OR CONTRIBUTORS BE ;LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR ;CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF ;SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ;BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE ;OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, ;EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SECTION code_crt0_sccz80 PUBLIC l_long_mult EXTERN __retloc, __math_rhs, __math_lhs, __math_result ; 32 bits signed and unsigned integer multiply routine ; Expects operands on stack ; Yields product on stack ; Liberated from ack l_long_mult: LD (__math_rhs),HL ; store multiplier ex de,hl LD (__math_rhs+2),HL POP HL LD (__retloc),HL POP HL ; store multiplicand LD (__math_lhs),HL POP HL LD (__math_lhs+2),HL LD HL,0 LD (__math_result),HL LD (__math_result+2),HL LD BC,0 lp1: LD HL,__math_rhs ADD HL,BC LD a,(HL) ; get next byte of multiplier LD b,8 lp2: RRA JP NC,dont_add LD HL,(__math_lhs) ; add multiplicand to product EX DE,HL LD HL,(__math_result) ADD HL,DE LD (__math_result),HL LD HL,(__math_lhs+2) JP NC,noinc INC HL noinc: EX DE,HL LD HL,(__math_result+2) ADD HL,DE LD (__math_result+2),HL dont_add: LD HL,(__math_lhs) ; shift multiplicand left ADD HL,HL LD (__math_lhs),HL LD HL,(__math_lhs+2) JP NC,noshift ADD HL,HL INC HL JP store noshift: ADD HL,HL store: LD (__math_lhs+2),HL DEC b JP NZ,lp2 INC c LD a,c CP 4 JP NZ,lp1 LD HL,(__retloc) push hl LD HL,(__math_result+2) ex de,hl LD HL,(__math_result) ret
;****************************************************************************** ;* VP9 MC SIMD optimizations ;* ;* Copyright (c) 2013 Ronald S. Bultje <rsbultje gmail com> ;* ;* This file is part of FFmpeg. ;* ;* FFmpeg is free software; you can redistribute it and/or ;* modify it under the terms of the GNU Lesser General Public ;* License as published by the Free Software Foundation; either ;* version 2.1 of the License, or (at your option) any later version. ;* ;* FFmpeg is distributed in the hope that it will be useful, ;* but WITHOUT ANY WARRANTY; without even the implied warranty of ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;* Lesser General Public License for more details. ;* ;* You should have received a copy of the GNU Lesser General Public ;* License along with FFmpeg; if not, write to the Free Software ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ;****************************************************************************** %include "libavutil/x86/x86util.asm" SECTION_RODATA ; FIXME share with vp8dsp.asm pw_256: times 8 dw 256 %macro F8_TAPS 8 times 8 db %1, %2 times 8 db %3, %4 times 8 db %5, %6 times 8 db %7, %8 %endmacro ; int8_t ff_filters_ssse3[3][15][4][16] const filters_ssse3 ; smooth F8_TAPS -3, -1, 32, 64, 38, 1, -3, 0 F8_TAPS -2, -2, 29, 63, 41, 2, -3, 0 F8_TAPS -2, -2, 26, 63, 43, 4, -4, 0 F8_TAPS -2, -3, 24, 62, 46, 5, -4, 0 F8_TAPS -2, -3, 21, 60, 49, 7, -4, 0 F8_TAPS -1, -4, 18, 59, 51, 9, -4, 0 F8_TAPS -1, -4, 16, 57, 53, 12, -4, -1 F8_TAPS -1, -4, 14, 55, 55, 14, -4, -1 F8_TAPS -1, -4, 12, 53, 57, 16, -4, -1 F8_TAPS 0, -4, 9, 51, 59, 18, -4, -1 F8_TAPS 0, -4, 7, 49, 60, 21, -3, -2 F8_TAPS 0, -4, 5, 46, 62, 24, -3, -2 F8_TAPS 0, -4, 4, 43, 63, 26, -2, -2 F8_TAPS 0, -3, 2, 41, 63, 29, -2, -2 F8_TAPS 0, -3, 1, 38, 64, 32, -1, -3 ; regular F8_TAPS 0, 1, -5, 126, 8, -3, 1, 0 F8_TAPS -1, 3, -10, 122, 18, -6, 2, 0 F8_TAPS -1, 4, -13, 118, 27, -9, 3, -1 F8_TAPS -1, 4, -16, 112, 37, -11, 4, -1 F8_TAPS -1, 5, -18, 105, 48, -14, 4, -1 F8_TAPS -1, 5, -19, 97, 58, -16, 5, -1 F8_TAPS -1, 6, -19, 88, 68, -18, 5, -1 F8_TAPS -1, 6, -19, 78, 78, -19, 6, -1 F8_TAPS -1, 5, -18, 68, 88, -19, 6, -1 F8_TAPS -1, 5, -16, 58, 97, -19, 5, -1 F8_TAPS -1, 4, -14, 48, 105, -18, 5, -1 F8_TAPS -1, 4, -11, 37, 112, -16, 4, -1 F8_TAPS -1, 3, -9, 27, 118, -13, 4, -1 F8_TAPS 0, 2, -6, 18, 122, -10, 3, -1 F8_TAPS 0, 1, -3, 8, 126, -5, 1, 0 ; sharp F8_TAPS -1, 3, -7, 127, 8, -3, 1, 0 F8_TAPS -2, 5, -13, 125, 17, -6, 3, -1 F8_TAPS -3, 7, -17, 121, 27, -10, 5, -2 F8_TAPS -4, 9, -20, 115, 37, -13, 6, -2 F8_TAPS -4, 10, -23, 108, 48, -16, 8, -3 F8_TAPS -4, 10, -24, 100, 59, -19, 9, -3 F8_TAPS -4, 11, -24, 90, 70, -21, 10, -4 F8_TAPS -4, 11, -23, 80, 80, -23, 11, -4 F8_TAPS -4, 10, -21, 70, 90, -24, 11, -4 F8_TAPS -3, 9, -19, 59, 100, -24, 10, -4 F8_TAPS -3, 8, -16, 48, 108, -23, 10, -4 F8_TAPS -2, 6, -13, 37, 115, -20, 9, -4 F8_TAPS -2, 5, -10, 27, 121, -17, 7, -3 F8_TAPS -1, 3, -6, 17, 125, -13, 5, -2 F8_TAPS 0, 1, -3, 8, 127, -7, 3, -1 SECTION .text %macro filter_h_fn 1 %assign %%px mmsize/2 cglobal %1_8tap_1d_h_ %+ %%px, 6, 6, 11, dst, dstride, src, sstride, h, filtery mova m6, [pw_256] mova m7, [filteryq+ 0] %if ARCH_X86_64 && mmsize > 8 mova m8, [filteryq+16] mova m9, [filteryq+32] mova m10, [filteryq+48] %endif .loop: movh m0, [srcq-3] movh m1, [srcq-2] movh m2, [srcq-1] movh m3, [srcq+0] movh m4, [srcq+1] movh m5, [srcq+2] punpcklbw m0, m1 punpcklbw m2, m3 movh m1, [srcq+3] movh m3, [srcq+4] add srcq, sstrideq punpcklbw m4, m5 punpcklbw m1, m3 pmaddubsw m0, m7 %if ARCH_X86_64 && mmsize > 8 pmaddubsw m2, m8 pmaddubsw m4, m9 pmaddubsw m1, m10 %else pmaddubsw m2, [filteryq+16] pmaddubsw m4, [filteryq+32] pmaddubsw m1, [filteryq+48] %endif paddw m0, m2 paddw m4, m1 paddsw m0, m4 pmulhrsw m0, m6 %ifidn %1, avg movh m1, [dstq] %endif packuswb m0, m0 %ifidn %1, avg pavgb m0, m1 %endif movh [dstq], m0 add dstq, dstrideq dec hd jg .loop RET %endmacro INIT_MMX ssse3 filter_h_fn put filter_h_fn avg INIT_XMM ssse3 filter_h_fn put filter_h_fn avg %if ARCH_X86_64 %macro filter_hx2_fn 1 %assign %%px mmsize cglobal %1_8tap_1d_h_ %+ %%px, 6, 6, 14, dst, dstride, src, sstride, h, filtery mova m13, [pw_256] mova m8, [filteryq+ 0] mova m9, [filteryq+16] mova m10, [filteryq+32] mova m11, [filteryq+48] .loop: movu m0, [srcq-3] movu m1, [srcq-2] movu m2, [srcq-1] movu m3, [srcq+0] movu m4, [srcq+1] movu m5, [srcq+2] movu m6, [srcq+3] movu m7, [srcq+4] add srcq, sstrideq SBUTTERFLY bw, 0, 1, 12 SBUTTERFLY bw, 2, 3, 12 SBUTTERFLY bw, 4, 5, 12 SBUTTERFLY bw, 6, 7, 12 pmaddubsw m0, m8 pmaddubsw m1, m8 pmaddubsw m2, m9 pmaddubsw m3, m9 pmaddubsw m4, m10 pmaddubsw m5, m10 pmaddubsw m6, m11 pmaddubsw m7, m11 paddw m0, m2 paddw m1, m3 paddw m4, m6 paddw m5, m7 paddsw m0, m4 paddsw m1, m5 pmulhrsw m0, m13 pmulhrsw m1, m13 packuswb m0, m1 %ifidn %1, avg pavgb m0, [dstq] %endif mova [dstq], m0 add dstq, dstrideq dec hd jg .loop RET %endmacro INIT_XMM ssse3 filter_hx2_fn put filter_hx2_fn avg %endif ; ARCH_X86_64 %macro filter_v_fn 1 %assign %%px mmsize/2 %if ARCH_X86_64 cglobal %1_8tap_1d_v_ %+ %%px, 6, 8, 11, dst, dstride, src, sstride, h, filtery, src4, sstride3 %else cglobal %1_8tap_1d_v_ %+ %%px, 4, 7, 11, dst, dstride, src, sstride, filtery, src4, sstride3 mov filteryq, r5mp %define hd r4mp %endif mova m6, [pw_256] lea sstride3q, [sstrideq*3] lea src4q, [srcq+sstrideq] sub srcq, sstride3q mova m7, [filteryq+ 0] %if ARCH_X86_64 && mmsize > 8 mova m8, [filteryq+16] mova m9, [filteryq+32] mova m10, [filteryq+48] %endif .loop: ; FIXME maybe reuse loads from previous rows, or just ; more generally unroll this to prevent multiple loads of ; the same data? movh m0, [srcq] movh m1, [srcq+sstrideq] movh m2, [srcq+sstrideq*2] movh m3, [srcq+sstride3q] movh m4, [src4q] movh m5, [src4q+sstrideq] punpcklbw m0, m1 punpcklbw m2, m3 movh m1, [src4q+sstrideq*2] movh m3, [src4q+sstride3q] add srcq, sstrideq add src4q, sstrideq punpcklbw m4, m5 punpcklbw m1, m3 pmaddubsw m0, m7 %if ARCH_X86_64 && mmsize > 8 pmaddubsw m2, m8 pmaddubsw m4, m9 pmaddubsw m1, m10 %else pmaddubsw m2, [filteryq+16] pmaddubsw m4, [filteryq+32] pmaddubsw m1, [filteryq+48] %endif paddw m0, m2 paddw m4, m1 paddsw m0, m4 pmulhrsw m0, m6 %ifidn %1, avg movh m1, [dstq] %endif packuswb m0, m0 %ifidn %1, avg pavgb m0, m1 %endif movh [dstq], m0 add dstq, dstrideq dec hd jg .loop RET %endmacro INIT_MMX ssse3 filter_v_fn put filter_v_fn avg INIT_XMM ssse3 filter_v_fn put filter_v_fn avg %if ARCH_X86_64 %macro filter_vx2_fn 1 %assign %%px mmsize cglobal %1_8tap_1d_v_ %+ %%px, 6, 8, 14, dst, dstride, src, sstride, h, filtery, src4, sstride3 mova m13, [pw_256] lea sstride3q, [sstrideq*3] lea src4q, [srcq+sstrideq] sub srcq, sstride3q mova m8, [filteryq+ 0] mova m9, [filteryq+16] mova m10, [filteryq+32] mova m11, [filteryq+48] .loop: ; FIXME maybe reuse loads from previous rows, or just ; more generally unroll this to prevent multiple loads of ; the same data? movu m0, [srcq] movu m1, [srcq+sstrideq] movu m2, [srcq+sstrideq*2] movu m3, [srcq+sstride3q] movu m4, [src4q] movu m5, [src4q+sstrideq] movu m6, [src4q+sstrideq*2] movu m7, [src4q+sstride3q] add srcq, sstrideq add src4q, sstrideq SBUTTERFLY bw, 0, 1, 12 SBUTTERFLY bw, 2, 3, 12 SBUTTERFLY bw, 4, 5, 12 SBUTTERFLY bw, 6, 7, 12 pmaddubsw m0, m8 pmaddubsw m1, m8 pmaddubsw m2, m9 pmaddubsw m3, m9 pmaddubsw m4, m10 pmaddubsw m5, m10 pmaddubsw m6, m11 pmaddubsw m7, m11 paddw m0, m2 paddw m1, m3 paddw m4, m6 paddw m5, m7 paddsw m0, m4 paddsw m1, m5 pmulhrsw m0, m13 pmulhrsw m1, m13 packuswb m0, m1 %ifidn %1, avg pavgb m0, [dstq] %endif mova [dstq], m0 add dstq, dstrideq dec hd jg .loop RET %endmacro INIT_XMM ssse3 filter_vx2_fn put filter_vx2_fn avg %endif ; ARCH_X86_64 %macro fpel_fn 6 %if %2 == 4 %define %%srcfn movh %define %%dstfn movh %else %define %%srcfn movu %define %%dstfn mova %endif %if %2 <= 16 cglobal %1%2, 5, 7, 4, dst, dstride, src, sstride, h, dstride3, sstride3 lea sstride3q, [sstrideq*3] lea dstride3q, [dstrideq*3] %else cglobal %1%2, 5, 5, 4, dst, dstride, src, sstride, h %endif .loop: %%srcfn m0, [srcq] %%srcfn m1, [srcq+s%3] %%srcfn m2, [srcq+s%4] %%srcfn m3, [srcq+s%5] lea srcq, [srcq+sstrideq*%6] %ifidn %1, avg pavgb m0, [dstq] pavgb m1, [dstq+d%3] pavgb m2, [dstq+d%4] pavgb m3, [dstq+d%5] %endif %%dstfn [dstq], m0 %%dstfn [dstq+d%3], m1 %%dstfn [dstq+d%4], m2 %%dstfn [dstq+d%5], m3 lea dstq, [dstq+dstrideq*%6] sub hd, %6 jnz .loop RET %endmacro %define d16 16 %define s16 16 INIT_MMX mmx fpel_fn put, 4, strideq, strideq*2, stride3q, 4 fpel_fn put, 8, strideq, strideq*2, stride3q, 4 INIT_MMX mmxext fpel_fn avg, 4, strideq, strideq*2, stride3q, 4 fpel_fn avg, 8, strideq, strideq*2, stride3q, 4 INIT_XMM sse fpel_fn put, 16, strideq, strideq*2, stride3q, 4 fpel_fn put, 32, mmsize, strideq, strideq+mmsize, 2 fpel_fn put, 64, mmsize, mmsize*2, mmsize*3, 1 INIT_XMM sse2 fpel_fn avg, 16, strideq, strideq*2, stride3q, 4 fpel_fn avg, 32, mmsize, strideq, strideq+mmsize, 2 fpel_fn avg, 64, mmsize, mmsize*2, mmsize*3, 1 %undef s16 %undef d16
.size 8000 .text@48 jp lstatint .text@100 jp lbegin .data@143 80 .text@150 lbegin: ld c, 41 ld b, 03 lbegin_waitm3: ldff a, (c) and a, b cmp a, b jrnz lbegin_waitm3 ld a, 20 ldff(c), a xor a, a ldff(0f), a ld a, 02 ldff(ff), a ei ld a, 02 ldff(43), a ld hl, 8000 ld(hl), 00 .text@1000 lstatint: nop .text@1036 ld a, (hl--) and a, b jp lprint_a .text@7000 lprint_a: push af ld b, 91 call lwaitly_b xor a, a ldff(40), a pop af ld(9800), a ld bc, 7a00 ld hl, 8000 ld d, a0 lprint_copytiles: ld a, (bc) inc bc ld(hl++), a dec d jrnz lprint_copytiles ld a, c0 ldff(47), a ld a, 80 ldff(68), a ld a, ff ldff(69), a ldff(69), a ldff(69), a ldff(69), a ldff(69), a ldff(69), a xor a, a ldff(69), a ldff(69), a ldff(43), a ld a, 91 ldff(40), a lprint_limbo: jr lprint_limbo .text@7400 lwaitly_b: ld c, 44 lwaitly_b_loop: ldff a, (c) cmp a, b jrnz lwaitly_b_loop ret .data@7a00 00 00 7f 7f 41 41 41 41 41 41 41 41 41 41 7f 7f 00 00 08 08 08 08 08 08 08 08 08 08 08 08 08 08 00 00 7f 7f 01 01 01 01 7f 7f 40 40 40 40 7f 7f 00 00 7f 7f 01 01 01 01 3f 3f 01 01 01 01 7f 7f 00 00 41 41 41 41 41 41 7f 7f 01 01 01 01 01 01 00 00 7f 7f 40 40 40 40 7e 7e 01 01 01 01 7e 7e 00 00 7f 7f 40 40 40 40 7f 7f 41 41 41 41 7f 7f 00 00 7f 7f 01 01 02 02 04 04 08 08 10 10 10 10 00 00 3e 3e 41 41 41 41 3e 3e 41 41 41 41 3e 3e 00 00 7f 7f 41 41 41 41 7f 7f 01 01 01 01 7f 7f
processor 6502 include "vcs.h" include "macro.h" SKY_BLUE = 160 DARK_WATER = 160 SUN_RED = 48 CLOUD_ORANGE = 34 GREY_SCALE = 2 WHITE_WATER = 10 GREEN = 178 RED = 66 YELLOW = 30 WHITE = 14 BLACK = 0 SEG ORG $F000 Reset ; set TIA to known state (clear to 0) lda #0 ldx #0 .zapTIA sta 0,x inx cpx #$40 bne .zapTIA ; black playfield sidebars lda #$30 sta PF0 lda #$01 sta CTRLPF newFrame ; Start of vertical blank processing lda #0 sta VBLANK sta COLUBK ; background colour to black ; 3 scanlines of vertical sync signal to follow lda #%00000010 sta VSYNC ; turn ON VSYNC bit 1 sta WSYNC ; wait a scanline sta WSYNC ; another sta WSYNC ; another = 3 lines total lda #0 sta VSYNC ; turn OFF VSYNC bit 1 ; 37 scanlines of vertical blank to follow ldx #35 vBlank sta WSYNC dex bne vBlank ; 192 scanlines of picture to follow ; ---------------------------------- ; horizon kernel ; SL -2 sta WSYNC SLEEP 40 sta RESP0 sta RESP1 lda #0 sta HMP0 lda #$10 sta HMP1 lda #1 sta NUSIZ0 ; SL -1 sta WSYNC ;3 0 sta HMOVE ;3 3 lda #SUN_RED ;2 5 sta COLUP0 ;3 8 sta COLUP1 ;3 11 ; SL 0 ... 36 ; 36 variable width bands of color gradient ldy #11 ;2 13 ldx #36 ;2 15 horizonLoop sta WSYNC ;3 0 lda HORIZON_COLOR,y ;4 4 sta COLUBK ;3 7 lda SUN_SPRITE_LEFT,x ;4 11 sta GRP0 ;3 14 lda SUN_SPRITE_MIDDLE,x ;4 18 sta GRP1 ;3 21 lda #0 ;2 23 sta REFP0 ;1 24 SLEEP 16 ;13 39 lda #8 ;2 39 sta REFP0 ;3 42 dex ;2 44 beq horizonEnd ;2 47 txa ;2 49 cmp HORIZON_COUNT,y ;4 53 bpl horizonLoop ;2* 55 dey ;2 57 jmp horizonLoop ;2* 59 horizonEnd lda #0 ; sta GRP0 ; sta GRP1 ; sta REFP1 ; sta NUSIZ0 ; ; ---------------------------------- ; playfield kernel ; SC 18 ; SC 22 sta WSYNC ; SC 36 lda #GREEN sta COLUBK ldx #130 playfield0 sta WSYNC dex bne playfield0 sta WSYNC SLEEP 70 sta HMOVE sta WSYNC ldx #12 playfield1 sta WSYNC dex bne playfield1 ; SC 180 lda #BLACK sta COLUBK ldx #12 logo sta WSYNC dex bne logo lda #0 sta COLUBK ; background colour to black ; SC 192 ; 30 lines of overscan to follow ldx #00 doOverscan sta WSYNC ; wait a scanline inx cpx #30 bne doOverscan jmp newFrame ;----------------------------------------------------------------------------------- ; the graphics ORG $FF00 byte 0; pad .HORIZON_COLOR HORIZON_COLOR = .HORIZON_COLOR - 1 byte CLOUD_ORANGE + 2, CLOUD_ORANGE, 252, 254, 252, 250, WHITE_WATER, SKY_BLUE + 8, SKY_BLUE + 4, SKY_BLUE + 2, SKY_BLUE b_HORIZON_COUNT ; 11 bytes HORIZON_COUNT = b_HORIZON_COUNT - 1 byte $0, $2, $4, $6, $10, $16, $17, $18, $1a, $1c, $1f b_SUN_SPRITE_LEFT ; 36 bytes SUN_SPRITE_LEFT = b_SUN_SPRITE_LEFT - 1 byte $ff,$ff,$ff,$ff,$7f,$7f,$7f,$7f,$3f,$3f,$3f,$1f,$1f,$f,$f,$7,$3,$1,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0; 36 b_SUN_SPRITE_MIDDLE ; 36 bytes SUN_SPRITE_MIDDLE = b_SUN_SPRITE_MIDDLE - 1 byte $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$3c,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0; 36 ;----------------------------------------------------------------------------------- ; the CPU reset vectors ORG $FFFA .word Reset ; NMI .word Reset ; RESET .word Reset ; IRQ END
/*++ Copyright (C) Microsoft Corporation, 2002 Module Name: selbinding.hxx Abstract: Manipulation of the selective binding registry settings. Revision History: MauricF 03-20-02 Consolodate access to selective binding settings across rpccfg/rpcnsh/rpctrans.lib --*/ #include <sysinc.h> #include <selbinding.hxx> DWORD GetSelectiveBindingVersion( IN DWORD dwSize, IN LPVOID lpBuffer, OUT SB_VER *pVer ) /*++ Routine Description: Determines the version of the selective binding settings in this buffer. the appropriate Arguments: dwSize - Size of the buffer lpBuffer - The buffer containing the settings pVer - Pointer to the version we fill in Return Value: ERROR_OUTOFMEMORY ERROR_SUCCESS - if the buffer is corrupt -> *pVer==SB_VER_UNKNOWN, if its default settings *pVer==SB_VER_DEFAULT --*/ { SUBNET_REG_ENTRY *pRegEntry; ASSERT(pVer != NULL); //Initialize the out params *pVer = SB_VER_UNKNOWN; //If NULL, then we treat it as default settings if ((dwSize == 0) || (lpBuffer == NULL)) { *pVer = SB_VER_DEFAULT; return ERROR_SUCCESS; } //If its not large enough to hold the flag, then //it isn't new format, could be the old format if (dwSize < sizeof(DWORD)) { *pVer = SB_VER_INDICES; return ERROR_SUCCESS; } //We can now cast the buffer as the structure, but don't //access anything but the flag just yet pRegEntry = (SUBNET_REG_ENTRY*) lpBuffer; //If it doesn't contain our flag at the begining, its //not new format, could be a differnet format though if (((ULONG)'4vPI') != pRegEntry->dwFlag) { *pVer = SB_VER_INDICES; return ERROR_SUCCESS; } //At this point it is either new format or unknown, it is not old format //If its not large enough to hold the header, its unknown if (dwSize < sizeof(SUBNET_REG_ENTRY)) { return ERROR_SUCCESS; } //Now we can access the rest of thee header //If the size is not consistent with the number of subnets //it claims to be holding then it is unknown if (dwSize != (sizeof(SUBNET_REG_ENTRY) + sizeof(DWORD) * pRegEntry->dwCount)) { return ERROR_SUCCESS; } //If it is holding zero subnets, its unknown (this is not valid for SB_VER_SUBNETS) if (pRegEntry->dwCount == 0) { return ERROR_SUCCESS; } //Make sure the admit flag is either zero or one if ((pRegEntry->dwAdmit != 0) && (pRegEntry->dwAdmit != 1)) { return ERROR_SUCCESS; } //Looks legit *pVer = SB_VER_SUBNETS; return ERROR_SUCCESS; } DWORD GetSelectiveBindingBuffer( OUT LPDWORD lpSize, OUT LPVOID *lppBuffer ) /*++ Routine Description: Retrieves the buffer from the registry and allocates space for you. Arguments: lpSize - This is filled in with the size of the buffer. lppBuffer - This will point to a buffer containing the registry entry, can't be NULL Return Value: ERROR_OUTOFMEMORY ERROR_ACCESS_DENIED - The user did not have access to the registry key. ERROR_SUCCESS - lppBuffer will point to a buffer containing the registry key or NULL if the key could not be found or is of zero size. --*/ { HKEY hKey; DWORD dwStatus; DWORD dwDummy; ASSERT((lpSize != NULL) && (lppBuffer != NULL)); //Init the out params *lppBuffer = NULL; *lpSize = 0; // Open the handle to our registry entry dwStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, RPC_SELECTIVE_BINDING_KEY_PATH, 0, KEY_READ, &hKey ); if (dwStatus != ERROR_SUCCESS) { ASSERT((dwStatus == ERROR_FILE_NOT_FOUND) || (dwStatus == ERROR_ACCESS_DENIED) || (dwStatus == ERROR_OUTOFMEMORY) || (dwStatus == ERROR_NOT_ENOUGH_MEMORY)); if (dwStatus == ERROR_FILE_NOT_FOUND) { //Default settings return ERROR_SUCCESS; } return dwStatus; } // Query for the size of the buffer dwStatus = RegQueryValueEx(hKey, RPC_SELECTIVE_BINDING_VALUE, 0, &dwDummy, NULL, lpSize); if (dwStatus != ERROR_SUCCESS) { ASSERT(dwStatus == ERROR_OUTOFMEMORY); RegCloseKey(hKey); return dwStatus; } // If the size is zero, we will map this to default settings if (*lpSize == 0) { RegCloseKey(hKey); return ERROR_SUCCESS; } // Allocate the buffer *lppBuffer = new char[*lpSize]; if (*lppBuffer == NULL) { RegCloseKey(hKey); return ERROR_OUTOFMEMORY; } // Get the buffer for real this time dwStatus = RegQueryValueEx(hKey, RPC_SELECTIVE_BINDING_VALUE, 0, &dwDummy, (LPBYTE)*lppBuffer, lpSize); if (dwStatus != ERROR_SUCCESS) { ASSERT(dwStatus == ERROR_OUTOFMEMORY); delete [] *lppBuffer; } RegCloseKey(hKey); return dwStatus; } DWORD GetSelectiveBindingSettings( OUT SB_VER *pVer, OUT LPDWORD lpSize, OUT LPVOID *lppSettings ) /*++ Routine Description: Retrieves the version and version specific setting information. *lppSettings will point to the settings if *pVer == SB_VER_INDICES or SB_VER_SUBNETS, other wise *lppSettings will be NULL Arguments: Return Value: ERROR_SUCCESS ERROR_ACCESS_DENIED ERROR_OUTOFMEMORY --*/ { DWORD dwStatus = ERROR_SUCCESS; LPVOID lpBuffer = NULL; DWORD dwSize = 0; ASSERT((pVer != NULL) && (lpSize != NULL) && (lppSettings != NULL)); *lppSettings = NULL; // Get the selective binding buffer dwStatus = GetSelectiveBindingBuffer(&dwSize, &lpBuffer); if (dwStatus != ERROR_SUCCESS) { ASSERT((dwStatus == ERROR_ACCESS_DENIED) || (dwStatus == ERROR_OUTOFMEMORY)); return dwStatus; } // Get the selective binding version dwStatus = GetSelectiveBindingVersion(dwSize, lpBuffer, pVer); if (dwStatus != ERROR_SUCCESS) { ASSERT(0); delete [] lpBuffer; return dwStatus; } // Depending on the version, fill in the appropriate structure switch (*pVer) { case SB_VER_INDICES: dwStatus = GetSelectiveBindingIndices(dwSize, lpBuffer, lpSize, (VER_INDICES_SETTINGS**) lppSettings); break; case SB_VER_SUBNETS: dwStatus = GetSelectiveBindingSubnets(dwSize, lpBuffer, lpSize, (VER_SUBNETS_SETTINGS**) lppSettings); break; case SB_VER_UNKNOWN: case SB_VER_DEFAULT: break; default: ASSERT(0); } ASSERT((dwStatus == ERROR_SUCCESS) || (dwStatus == ERROR_OUTOFMEMORY)); return dwStatus; } DWORD GetSelectiveBindingSubnets( IN DWORD dwSize, IN LPVOID lpBuffer, OUT LPDWORD lpSize, OUT VER_SUBNETS_SETTINGS **lppSettings ) /*++ Routine Description: Allocates and fills in a settings structure based off an SB_VER_SUBNETS buffer. Arguments: IN dwSize - size of the SB_VER_SUBNETS buffer IN lpBuffer - pointer to the SB_VER_SUBNETS buffer OUT lppSettings - filled in with a pointer to te subnet settings Return Value: ERROR_SUCCESS ERROR_OUTOFMEMORY --*/ { SUBNET_REG_ENTRY *pEntry; ASSERT((lpBuffer != NULL) && (lppSettings != NULL)); // Cast the buffer as a SUBNET_REG_ENTRY pEntry = (SUBNET_REG_ENTRY*)lpBuffer; // Calculate the size to allocate for VER_SUBNETS_SETTINGS *lpSize = sizeof(VER_SUBNETS_SETTINGS) + pEntry->dwCount*sizeof(DWORD); *lppSettings = (VER_SUBNETS_SETTINGS*) new char [*lpSize]; if (*lppSettings == NULL) return ERROR_OUTOFMEMORY; // Copy in the relevent fields (*lppSettings)->bAdmit = (BOOL)pEntry->dwAdmit; (*lppSettings)->dwCount = pEntry->dwCount; memcpy((*lppSettings)->dwSubnets, pEntry->dwSubnets, pEntry->dwCount*sizeof(DWORD)); return ERROR_SUCCESS; } DWORD GetSelectiveBindingIndices( IN DWORD dwSize, IN LPVOID lpBuffer, OUT LPDWORD lpSize, OUT VER_INDICES_SETTINGS **lppSettings ) /*++ Routine Description: Allocates and fills in a settings structure based off an SB_VER_INDICES buffer. Arguments: IN dwSize - size of the SB_VER_INDICES buffer IN lpBuffer - pointer to the SB_VER_INDICES buffer OUT lppSettings - filled in with a pointer to the indices settings Return Value: ERROR_SUCCESS ERROR_OUTOFMEMORY --*/ { DWORD dwStatus = ERROR_SUCCESS; DWORD dwCount=0; LPVOID lpTmp = NULL; DWORD dwIndex; DWORD idx; ASSERT((lpBuffer != NULL) && (lppSettings != NULL)); // Count how many indices there are lpTmp = lpBuffer; while (NextIndex((char**)&lpTmp) != -1) dwCount++; // Calculate the size to allocate for VER_INDICES_SETTINGS *lpSize = sizeof(VER_INDICES_SETTINGS) + dwCount*sizeof(DWORD); *lppSettings = (VER_INDICES_SETTINGS*) new char [*lpSize]; if (*lppSettings == NULL) return ERROR_OUTOFMEMORY; // Step through and get each index lpTmp = lpBuffer; idx = 0; (*lppSettings)->dwCount = dwCount; for (idx = 0; idx <dwCount; idx++) (*lppSettings)->dwIndices[idx] = NextIndex((char**)&lpTmp); return ERROR_SUCCESS; } DWORD DeleteSelectiveBinding() /*++ Routine Description: Deletes the linkage key, this indicates we should use the default settings for selective binding (listen on all interfaces). Arguments: Return Value: ERROR_SUCCESS ERROR_ACCESS_DENIED --*/ { HKEY hKey; DWORD dwStatus; // Attempt to open the key dwStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, RPC_SETTINGS_PATH, 0, KEY_ALL_ACCESS, &hKey ); if (dwStatus != ERROR_SUCCESS) { ASSERT((dwStatus == ERROR_ACCESS_DENIED) || (dwStatus == ERROR_FILE_NOT_FOUND)); return dwStatus; } // Delete the selective binding key dwStatus = RegDeleteKey(hKey, RPC_SELECTIVE_BINDING_KEY); ASSERT((dwStatus == ERROR_SUCCESS) || (dwStatus == ERROR_FILE_NOT_FOUND)); RegCloseKey(hKey); return ERROR_SUCCESS; } DWORD SetSelectiveBindingSubnets( IN DWORD dwCount, IN LPDWORD lpSubnetTable, IN BOOL bAdmit ) /*++ Routine Description: This converts the inputs into a buffer which we write to the registry using SetSelectiveBindingBuffer. Arguments: bAdmit - True for Admit (Add) list False for Deny (Delete) list. dwCount - The number of subnets we are setting. It is illegal to set zero subnets. lpSubnetTable - This is the array of subnets we wish to create an Admit or Deny list from. Return Value: ERROR_ACCESS_DENIED ERROR_OUTOFMEMORY ERROR_SUCCESS --*/ { SUBNET_REG_ENTRY *pRegEntry; DWORD dwSize; DWORD dwStatus; ASSERT((dwCount !=0) && (lpSubnetTable != NULL)); //Calculate the size of the buffer dwSize = sizeof(SUBNET_REG_ENTRY) + dwCount*sizeof(DWORD); pRegEntry = (SUBNET_REG_ENTRY*) new char[dwSize]; if (pRegEntry == NULL) return ERROR_OUTOFMEMORY; //Fill in the structure pRegEntry->dwFlag = ((ULONG)'4vPI'); pRegEntry->dwCount = dwCount; pRegEntry->dwAdmit = (bAdmit ? ((DWORD)0x01) : ((DWORD)0x00)); memcpy(pRegEntry->dwSubnets, lpSubnetTable, dwCount*sizeof(DWORD)); //Write this to the registry dwStatus = SetSelectiveBindingBuffer(dwSize, (LPVOID)pRegEntry); delete [] pRegEntry; pRegEntry = NULL; return dwStatus; } DWORD SetSelectiveBindingBuffer( IN DWORD dwSize, IN LPVOID lpBuffer ) /*++ Routine Description: Writes the buffer to the selective binding key in the registry Arguments: dwSize - This is the size of the buffer. lpBuffer - This is the buffer we write to the registry. Return Value: ERROR_ACCESS_DENIED - The user did not have permission to write to this key ERROR_SUCCESS --*/ { HKEY hKey; DWORD dwStatus; DWORD dwDummy; ASSERT((dwSize != 0) && (lpBuffer != NULL)); // Attempt to create the key, this will succeed even if the key already exists dwStatus = RegCreateKeyEx(HKEY_LOCAL_MACHINE, RPC_SELECTIVE_BINDING_KEY_PATH, 0, "", REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, &dwDummy ); if (dwStatus != ERROR_SUCCESS) { ASSERT(dwStatus == ERROR_ACCESS_DENIED); return dwStatus; } // Write the value dwStatus = RegSetValueEx(hKey, "Bind", 0, REG_BINARY, (LPBYTE)lpBuffer, dwSize ); ASSERT(dwStatus == ERROR_SUCCESS); RegCloseKey(hKey); return dwStatus; } DWORD NextIndex( IN OUT char **Ptr ) /*++ Routine Description: Retrieves the next index from the buffer, and moves the pointer to the start of the following index. Arguments: Ptr - A pointer to the old registry format for storing indices. Each index is stored as a string, (must be ASCII when its passed to this function). The Ptr gets updated to point to the following index. Return Value: The index retrieved or -1 if the end of the buffer has been reached. --*/ { char *Index = (char *)*Ptr ; if (*Index == 0) { return -1; } while (*(char *)*Ptr) ((char *)*Ptr)++ ; ((char *)*Ptr)++ ; return (DWORD) atol(Index) ; }
; A021345: Decimal expansion of 1/341. ; 0,0,2,9,3,2,5,5,1,3,1,9,6,4,8,0,9,3,8,4,1,6,4,2,2,2,8,7,3,9,0,0,2,9,3,2,5,5,1,3,1,9,6,4,8,0,9,3,8,4,1,6,4,2,2,2,8,7,3,9,0,0,2,9,3,2,5,5,1,3,1,9,6,4,8,0,9,3,8,4,1,6,4,2,2,2,8,7,3,9,0,0,2,9,3,2,5,5,1 add $0,2 mov $1,10 pow $1,$0 mul $1,2 div $1,6820 mod $1,10 mov $0,$1
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r13 push %r14 push %rbp push %rcx push %rdi push %rsi lea addresses_normal_ht+0xf245, %rsi lea addresses_A_ht+0x18c0d, %rdi nop nop nop and %rbp, %rbp mov $99, %rcx rep movsb nop nop nop nop nop xor $6422, %rbp lea addresses_UC_ht+0x9aad, %rsi lea addresses_WT_ht+0x1770d, %rdi clflush (%rsi) nop xor %r14, %r14 mov $29, %rcx rep movsb nop nop nop and $50823, %rsi lea addresses_UC_ht+0x1ad8d, %rsi lea addresses_WC_ht+0xf30d, %rdi clflush (%rsi) clflush (%rdi) nop nop nop nop nop lfence mov $86, %rcx rep movsb nop nop and %rbp, %rbp lea addresses_WT_ht+0x1deb5, %rsi lea addresses_WC_ht+0x17a25, %rdi nop nop xor $9697, %r10 mov $0, %rcx rep movsq nop nop nop nop nop inc %rdi lea addresses_D_ht+0x230d, %rsi lea addresses_D_ht+0x330d, %rdi clflush (%rdi) nop xor %rbp, %rbp mov $118, %rcx rep movsw nop nop add %rdi, %rdi lea addresses_A_ht+0x1330d, %rcx nop nop nop nop inc %rdi mov $0x6162636465666768, %r14 movq %r14, (%rcx) cmp $61322, %r13 pop %rsi pop %rdi pop %rcx pop %rbp pop %r14 pop %r13 pop %r10 ret .global s_faulty_load s_faulty_load: push %r10 push %r12 push %r13 push %r15 push %r8 push %rbx push %rdx // Load lea addresses_US+0x126d1, %rdx clflush (%rdx) nop nop nop nop nop xor %r13, %r13 mov (%rdx), %r10d nop cmp %r8, %r8 // Faulty Load lea addresses_normal+0x14b0d, %r12 nop nop nop nop add $41882, %r15 mov (%r12), %r13d lea oracles, %r8 and $0xff, %r13 shlq $12, %r13 mov (%r8,%r13,1), %r13 pop %rdx pop %rbx pop %r8 pop %r15 pop %r13 pop %r12 pop %r10 ret /* <gen_faulty_load> [REF] {'src': {'NT': False, 'same': False, 'congruent': 0, 'type': 'addresses_normal', 'AVXalign': False, 'size': 1}, 'OP': 'LOAD'} {'src': {'NT': False, 'same': False, 'congruent': 0, 'type': 'addresses_US', 'AVXalign': False, 'size': 4}, 'OP': 'LOAD'} [Faulty Load] {'src': {'NT': False, 'same': True, 'congruent': 0, 'type': 'addresses_normal', 'AVXalign': False, 'size': 4}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'same': False, 'congruent': 3, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 3, 'type': 'addresses_A_ht'}} {'src': {'same': False, 'congruent': 4, 'type': 'addresses_UC_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 10, 'type': 'addresses_WT_ht'}} {'src': {'same': True, 'congruent': 7, 'type': 'addresses_UC_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 11, 'type': 'addresses_WC_ht'}} {'src': {'same': False, 'congruent': 0, 'type': 'addresses_WT_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 3, 'type': 'addresses_WC_ht'}} {'src': {'same': False, 'congruent': 11, 'type': 'addresses_D_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 11, 'type': 'addresses_D_ht'}} {'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 11, 'type': 'addresses_A_ht', 'AVXalign': False, 'size': 8}} {'34': 21829} 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 */
// ---------------------------------------------------------------------------- // - Open3D: www.open3d.org - // ---------------------------------------------------------------------------- // The MIT License (MIT) // // Copyright (c) 2018-2021 www.open3d.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 <cmath> #include <limits> #include "open3d/core/AdvancedIndexing.h" #include "open3d/core/Dtype.h" #include "open3d/core/MemoryManager.h" #include "open3d/core/SizeVector.h" #include "open3d/core/Tensor.h" #include "open3d/core/kernel/Kernel.h" #include "open3d/core/linalg/kernel/SVD3x3.h" #include "open3d/utility/Helper.h" #include "tests/UnitTest.h" #include "tests/core/CoreTest.h" namespace open3d { namespace tests { class LinalgPermuteDevices : public PermuteDevices {}; INSTANTIATE_TEST_SUITE_P(Linalg, LinalgPermuteDevices, testing::ValuesIn(PermuteDevices::TestCases())); TEST_P(LinalgPermuteDevices, Matmul) { const float EPSILON = 1e-8; core::Device device = GetParam(); core::Dtype dtype = core::Float32; // Matmul test. core::Tensor A(std::vector<float>{1, 2, 3, 4, 5, 6}, {2, 3}, dtype, device); core::Tensor B( std::vector<float>{7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}, {3, 4}, dtype, device); core::Tensor C = A.Matmul(B); EXPECT_EQ(C.GetShape(), core::SizeVector({2, 4})); std::vector<float> C_data = C.ToFlatVector<float>(); std::vector<float> C_gt = {74, 80, 86, 92, 173, 188, 203, 218}; for (int i = 0; i < 8; ++i) { EXPECT_TRUE(std::abs(C_data[i] - C_gt[i]) < EPSILON); } // Non-contiguous matmul test. core::Tensor A_slice = A.GetItem( {core::TensorKey::Slice(core::None, core::None, core::None), core::TensorKey::Slice(1, core::None, core::None)}); core::Tensor B_slice = B.IndexGet({core::Tensor(std::vector<int64_t>{0, 2}, {2}, core::Int64, device)}) .GetItem({core::TensorKey::Slice(core::None, core::None, core::None)}); core::Tensor C_slice = A_slice.Matmul(B_slice); std::vector<float> C_slice_data = C_slice.ToFlatVector<float>(); std::vector<float> C_slice_gt = {59, 64, 69, 74, 125, 136, 147, 158}; for (int i = 0; i < 6; ++i) { EXPECT_TRUE(std::abs(C_slice_data[i] - C_slice_gt[i]) < EPSILON); } // Incompatible shape test. EXPECT_ANY_THROW(A.Matmul(core::Tensor::Zeros({3, 4, 5}, dtype))); EXPECT_ANY_THROW(A.Matmul(core::Tensor::Zeros({3, 0}, dtype))); EXPECT_ANY_THROW(A.Matmul(core::Tensor::Zeros({2, 4}, dtype))); } TEST_P(LinalgPermuteDevices, LU) { core::Device device = GetParam(); core::Dtype dtype = core::Float32; // LU test for 3x4 const 2D tensor of dtype Float32. const core::Tensor A_3x4cf = core::Tensor::Init<float>( {{2, 3, 1}, {3, 3, 1}, {2, 4, 1}, {2, 1, 3}}, device); // Default parameter for permute_l (false). core::Tensor permutationcf0, lowercf0, uppercf0; std::tie(permutationcf0, lowercf0, uppercf0) = A_3x4cf.LU(); core::Tensor outputcf0 = permutationcf0.Matmul(lowercf0.Matmul(uppercf0)).Contiguous(); EXPECT_TRUE(A_3x4cf.AllClose(outputcf0, FLT_EPSILON, FLT_EPSILON)); // "permute_l = true": L must be P*L. So, output = L*U. core::Tensor permutationcf1, lowercf1, uppercf1; std::tie(permutationcf1, lowercf1, uppercf1) = A_3x4cf.LU(/*permute_l=*/true); core::Tensor outputcf1 = lowercf1.Matmul(uppercf1).Contiguous(); EXPECT_TRUE(A_3x4cf.AllClose(outputcf1, FLT_EPSILON, FLT_EPSILON)); // LU test for 3x3 const square 2D tensor of dtype Float64. const core::Tensor A_3x3cd = core::Tensor::Init<double>( {{2, 3, 1}, {3, 3, 1}, {2, 4, 1}}, device); core::Tensor permutationcd0, lowercd0, uppercd0; std::tie(permutationcd0, lowercd0, uppercd0) = A_3x3cd.LU(); core::Tensor outputcd0 = permutationcd0.Matmul(lowercd0.Matmul(uppercd0)).Contiguous(); EXPECT_TRUE(A_3x3cd.AllClose(outputcd0, DBL_EPSILON, DBL_EPSILON)); // Singular test. EXPECT_ANY_THROW(core::Tensor::Zeros({3, 3}, dtype, device).LU()); // Shape test. EXPECT_ANY_THROW(core::Tensor::Ones({0}, dtype, device).LU()); EXPECT_ANY_THROW(core::Tensor::Ones({2, 2, 2}, dtype, device).LU()); } TEST_P(LinalgPermuteDevices, LUIpiv) { const float EPSILON = 1e-6; core::Device device = GetParam(); core::Dtype dtype = core::Float32; // LU test for 3x3 square 2D tensor of dtype Float32. const core::Tensor A_3x3f = core::Tensor::Init<float>( {{2, 3, 1}, {3, 3, 1}, {2, 4, 1}}, device); core::Tensor ipiv3f, A3f; std::tie(ipiv3f, A3f) = A_3x3f.LUIpiv(); EXPECT_TRUE( A3f.AllClose(core::Tensor::Init<float>({{3.0, 3.0, 1.0}, {0.666667, 2.0, 0.333333}, {0.666667, 0.5, 0.166667}}, device), EPSILON, EPSILON)); EXPECT_TRUE(ipiv3f.To(core::Int32) .AllClose(core::Tensor::Init<int>({2, 3, 3}, device), EPSILON)); // LU test for 3x3 square 2D tensor of dtype Float64. core::Tensor A_3x3d = core::Tensor::Init<double>( {{2, 3, 1}, {3, 3, 1}, {2, 4, 1}}, device); core::Tensor ipiv3d, A3d; std::tie(ipiv3d, A3d) = A_3x3d.LUIpiv(); EXPECT_TRUE( A3d.AllClose(core::Tensor::Init<double>({{3.0, 3.0, 1.0}, {0.666667, 2.0, 0.333333}, {0.666667, 0.5, 0.166667}}, device), EPSILON, EPSILON)); EXPECT_TRUE(ipiv3d.To(core::Int32) .AllClose(core::Tensor::Init<int>({2, 3, 3}, device), EPSILON)); // Singular test. EXPECT_ANY_THROW(core::Tensor::Zeros({3, 3}, dtype, device).LU()); // Shape test. EXPECT_ANY_THROW(core::Tensor::Ones({0}, dtype, device).LU()); EXPECT_ANY_THROW(core::Tensor::Ones({2, 2, 2}, dtype, device).LU()); } TEST_P(LinalgPermuteDevices, Triu) { core::Device device = GetParam(); core::Dtype dtype = core::Float32; // Input 2D matrix of dtype Float32. const core::Tensor A_4x5f = core::Tensor::Init<float>({{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18, 19, 20}}, device); // Get upper triangle matrix from main diagonal (= 0). core::Tensor Uf0 = A_4x5f.Triu(); EXPECT_TRUE(Uf0.AllClose(core::Tensor::Init<float>({{1, 2, 3, 4, 5}, {0, 7, 8, 9, 10}, {0, 0, 13, 14, 15}, {0, 0, 0, 19, 20}}, device))); // Get upper triangle matrix from diagonal (= 1). core::Tensor Uf1 = A_4x5f.Triu(1); EXPECT_TRUE(Uf1.AllClose(core::Tensor::Init<float>({{0, 2, 3, 4, 5}, {0, 0, 8, 9, 10}, {0, 0, 0, 14, 15}, {0, 0, 0, 0, 20}}, device))); // Get upper triangle matrix from diagonal (= -1). core::Tensor Uf1_ = A_4x5f.Triu(-1); EXPECT_TRUE(Uf1_.AllClose(core::Tensor::Init<float>({{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {0, 12, 13, 14, 15}, {0, 0, 18, 19, 20}}, device))); // Boundary test. EXPECT_ANY_THROW(A_4x5f.Triu(-4)); EXPECT_ANY_THROW(A_4x5f.Triu(5)); // Shape test. EXPECT_ANY_THROW(core::Tensor::Ones({0}, dtype, device).Triu()); EXPECT_ANY_THROW(core::Tensor::Ones({2, 2, 2}, dtype, device).Triu()); } TEST_P(LinalgPermuteDevices, Tril) { core::Device device = GetParam(); core::Dtype dtype = core::Float32; // Input 2D matrix of dtype Float32. const core::Tensor A_4x5f = core::Tensor::Init<float>({{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18, 19, 20}}, device); // Get lower triangle matrix from main diagonal (= 0). core::Tensor Lf0 = A_4x5f.Tril(); EXPECT_TRUE(Lf0.AllClose(core::Tensor::Init<float>({{1, 0, 0, 0, 0}, {6, 7, 0, 0, 0}, {11, 12, 13, 0, 0}, {16, 17, 18, 19, 0}}, device))); // Get lower triangle matrix from diagonal (= 1). core::Tensor Lf1 = A_4x5f.Tril(1); EXPECT_TRUE(Lf1.AllClose(core::Tensor::Init<float>({{1, 2, 0, 0, 0}, {6, 7, 8, 0, 0}, {11, 12, 13, 14, 0}, {16, 17, 18, 19, 20}}, device))); // Get lower triangle matrix from diagonal (= -1). core::Tensor Lf1_ = A_4x5f.Tril(-1); EXPECT_TRUE(Lf1_.AllClose(core::Tensor::Init<float>({{0, 0, 0, 0, 0}, {6, 0, 0, 0, 0}, {11, 12, 0, 0, 0}, {16, 17, 18, 0, 0}}, device))); core::Tensor Lf4 = A_4x5f.Tril(4); EXPECT_TRUE(Lf4.AllClose(core::Tensor::Init<float>({{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18, 19, 20}}, device))); // Boundary test. EXPECT_ANY_THROW(A_4x5f.Tril(-5)); EXPECT_ANY_THROW(A_4x5f.Tril(6)); // Shape test. EXPECT_ANY_THROW(core::Tensor::Ones({0}, dtype, device).Tril()); EXPECT_ANY_THROW(core::Tensor::Ones({2, 2, 2}, dtype, device).Tril()); } TEST_P(LinalgPermuteDevices, Triul) { core::Device device = GetParam(); core::Dtype dtype = core::Float32; // Input 2D matrix of dtype Float32. const core::Tensor A_4x5f = core::Tensor::Init<float>({{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18, 19, 20}}, device); // Get lower triangle matrix from main diagonal (= 0). core::Tensor Uf0, Lf0; std::tie(Uf0, Lf0) = A_4x5f.Triul(); EXPECT_TRUE(Uf0.AllClose(core::Tensor::Init<float>({{1, 2, 3, 4, 5}, {0, 7, 8, 9, 10}, {0, 0, 13, 14, 15}, {0, 0, 0, 19, 20}}, device))); EXPECT_TRUE(Lf0.AllClose(core::Tensor::Init<float>({{1, 0, 0, 0, 0}, {6, 1, 0, 0, 0}, {11, 12, 1, 0, 0}, {16, 17, 18, 1, 0}}, device))); core::Tensor Uf1, Lf1; std::tie(Uf1, Lf1) = A_4x5f.Triul(1); EXPECT_TRUE(Uf1.AllClose(core::Tensor::Init<float>({{0, 2, 3, 4, 5}, {0, 0, 8, 9, 10}, {0, 0, 0, 14, 15}, {0, 0, 0, 0, 20}}, device))); EXPECT_TRUE(Lf1.AllClose(core::Tensor::Init<float>({{1, 1, 0, 0, 0}, {6, 7, 1, 0, 0}, {11, 12, 13, 1, 0}, {16, 17, 18, 19, 1}}, device))); core::Tensor Uf1_, Lf1_; std::tie(Uf1_, Lf1_) = A_4x5f.Triul(-1); EXPECT_TRUE(Uf1_.AllClose(core::Tensor::Init<float>({{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {0, 12, 13, 14, 15}, {0, 0, 18, 19, 20}}, device))); EXPECT_TRUE(Lf1_.AllClose(core::Tensor::Init<float>({{0, 0, 0, 0, 0}, {1, 0, 0, 0, 0}, {11, 1, 0, 0, 0}, {16, 17, 1, 0, 0}}, device))); // Boundary test. EXPECT_ANY_THROW(A_4x5f.Triul(-4)); EXPECT_ANY_THROW(A_4x5f.Triul(5)); // Shape test. EXPECT_ANY_THROW(core::Tensor::Ones({0}, dtype, device).Triul()); EXPECT_ANY_THROW(core::Tensor::Ones({2, 2, 2}, dtype, device).Triul()); } TEST_P(LinalgPermuteDevices, Inverse) { const float EPSILON = 1e-5; core::Device device = GetParam(); core::Dtype dtype = core::Float32; // Inverse test. core::Tensor A(std::vector<float>{2, 3, 1, 3, 3, 1, 2, 4, 1}, {3, 3}, dtype, device); core::Tensor A_inv = A.Inverse(); EXPECT_EQ(A_inv.GetShape(), core::SizeVector({3, 3})); std::vector<float> A_inv_data = A_inv.ToFlatVector<float>(); std::vector<float> A_inv_gt = {-1, 1, 0, -1, 0, 1, 6, -2, -3}; for (int i = 0; i < 9; ++i) { EXPECT_TRUE(std::abs(A_inv_data[i] - A_inv_gt[i]) < EPSILON); } // Singular test. EXPECT_ANY_THROW(core::Tensor::Zeros({3, 3}, dtype, device).Inverse()); // Shape test. EXPECT_ANY_THROW(core::Tensor::Ones({0}, dtype, device).Inverse()); EXPECT_ANY_THROW(core::Tensor::Ones({2, 2, 2}, dtype, device).Inverse()); EXPECT_ANY_THROW(core::Tensor::Ones({3, 4}, dtype, device).Inverse()); } TEST_P(LinalgPermuteDevices, SVD) { const float EPSILON = 1e-5; core::Device device = GetParam(); core::Dtype dtype = core::Float32; core::Tensor A(std::vector<float>{2, 4, 1, 3, 0, 0, 0, 0}, {4, 2}, dtype, device); core::Tensor U, S, VT; std::tie(U, S, VT) = A.SVD(); EXPECT_EQ(U.GetShape(), core::SizeVector({4, 4})); EXPECT_EQ(S.GetShape(), core::SizeVector({2})); EXPECT_EQ(VT.GetShape(), core::SizeVector({2, 2})); core::Tensor UUT = U.Matmul(U.T()); std::vector<float> UUT_data = UUT.ToFlatVector<float>(); std::vector<float> UUT_gt = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; for (int i = 0; i < 16; ++i) { EXPECT_TRUE(std::abs(UUT_data[i] - UUT_gt[i]) < EPSILON); } core::Tensor VVT = VT.T().Matmul(VT); std::vector<float> VVT_data = VVT.ToFlatVector<float>(); std::vector<float> VVT_gt = {1, 0, 0, 1}; for (int i = 0; i < 4; ++i) { EXPECT_TRUE(std::abs(VVT_data[i] - VVT_gt[i]) < EPSILON); } core::Tensor USVT = U.GetItem({core::TensorKey::Slice(core::None, core::None, core::None), core::TensorKey::Slice(core::None, 2, core::None)}) .Matmul(core::Tensor::Diag(S).Matmul(VT)); EXPECT_EQ(USVT.GetShape(), A.GetShape()); std::vector<float> A_data = A.ToFlatVector<float>(); std::vector<float> USVT_data = USVT.ToFlatVector<float>(); for (int i = 0; i < 8; ++i) { EXPECT_TRUE(std::abs(A_data[i] - USVT_data[i]) < EPSILON); } } TEST_P(LinalgPermuteDevices, Solve) { const float EPSILON = 1e-8; core::Device device = GetParam(); core::Dtype dtype = core::Float32; // Solve test. core::Tensor A(std::vector<float>{3, 1, 1, 2}, {2, 2}, dtype, device); core::Tensor B(std::vector<float>{9, 8}, {2}, dtype, device); core::Tensor X = A.Solve(B); EXPECT_EQ(X.GetShape(), core::SizeVector{2}); std::vector<float> X_data = X.ToFlatVector<float>(); std::vector<float> X_gt = std::vector<float>{2, 3}; for (int i = 0; i < 2; ++i) { EXPECT_TRUE(std::abs(X_data[i] - X_gt[i]) < EPSILON); } // Singular test. EXPECT_ANY_THROW(core::Tensor::Zeros({2, 2}, dtype, device).Solve(B)); // Shape test. EXPECT_ANY_THROW(core::Tensor::Ones({2, 3}, dtype, device).Solve(B)); EXPECT_ANY_THROW(core::Tensor::Ones({2, 2, 2}, dtype, device).Solve(B)); EXPECT_ANY_THROW(core::Tensor::Ones({2, 0}, dtype, device).Solve(B)); EXPECT_ANY_THROW(core::Tensor::Ones({2}, dtype, device).Solve(B)); } TEST_P(LinalgPermuteDevices, LeastSquares) { const float EPSILON = 1e-5; core::Device device = GetParam(); core::Dtype dtype = core::Float32; // Solve test. core::Tensor A(std::vector<float>{1.44, -7.84, -4.39, 4.53, -9.96, -0.28, -3.24, 3.83, -7.55, 3.24, 6.27, -6.64, 8.34, 8.09, 5.28, 2.06, 7.08, 2.52, 0.74, -2.47, -5.45, -5.70, -1.19, 4.70}, {6, 4}, dtype, device); core::Tensor B(std::vector<float>{8.58, 9.35, 8.26, -4.43, 8.48, -0.70, -5.28, -0.26, 5.72, -7.36, 8.93, -2.52}, {6, 2}, dtype, device); core::Tensor X = A.LeastSquares(B); EXPECT_EQ(X.GetShape(), core::SizeVector({4, 2})); std::vector<float> X_data = X.ToFlatVector<float>(); std::vector<float> X_gt = std::vector<float>{ -0.45063714, 0.249748, -0.84915021, -0.90201926, 0.70661216, 0.63234303, 0.12888575, 0.13512364}; for (int i = 0; i < 2; ++i) { EXPECT_TRUE(std::abs(X_data[i] - X_gt[i]) < EPSILON); } } TEST_P(LinalgPermuteDevices, KernelOps) { core::Tensor A_3x3 = core::Tensor::Init<float>({{0, 1, 0}, {1, 0, 0}, {0, 0, 1}}); core::Tensor B_3x1 = core::Tensor::Init<float>({{1}, {3}, {6}}); core::Tensor I_3x3 = core::Tensor::Eye(3, core::Float32, core::Device("CPU:0")); core::Tensor output3x3 = core::Tensor::Empty({3, 3}, core::Float32, core::Device("CPU:0")); core::Tensor output3x1 = core::Tensor::Empty({3, 1}, core::Float32, core::Device("CPU:0")); // {3, 3} x {3, 3} MatMul auto matmul3x3_expected = A_3x3.Matmul(I_3x3); core::linalg::kernel::matmul3x3_3x3(A_3x3.GetDataPtr<float>(), I_3x3.GetDataPtr<float>(), output3x3.GetDataPtr<float>()); EXPECT_TRUE(output3x3.AllClose(matmul3x3_expected)); // {3, 3} x {3, 1} MatMul auto matmul3x1_expected = A_3x3.Matmul(B_3x1); core::linalg::kernel::matmul3x3_3x1(A_3x3.GetDataPtr<float>(), B_3x1.GetDataPtr<float>(), output3x1.GetDataPtr<float>()); EXPECT_TRUE(output3x1.AllClose(matmul3x1_expected)); // Inverse 3x3 auto Ainv_expected = A_3x3.Inverse(); core::linalg::kernel::inverse3x3(A_3x3.GetDataPtr<float>(), output3x3.GetDataPtr<float>()); EXPECT_TRUE(output3x3.AllClose(Ainv_expected)); // Transpose 3x3 auto AT_expected = A_3x3.T(); core::linalg::kernel::transpose3x3(A_3x3.GetDataPtr<float>(), output3x3.GetDataPtr<float>()); EXPECT_TRUE(output3x3.AllClose(AT_expected)); // Det 3x3 double det_expected = A_3x3.Det(); double det_output = static_cast<double>( core::linalg::kernel::det3x3(A_3x3.GetDataPtr<float>())); EXPECT_EQ(det_output, det_expected); // SVD Solver 3x3. core::linalg::kernel::solve_svd3x3(A_3x3.GetDataPtr<float>(), B_3x1.GetDataPtr<float>(), output3x1.GetDataPtr<float>()); auto Solve_Expected = A_3x3.Solve(B_3x1); EXPECT_TRUE(output3x1.AllClose(Solve_Expected)); } } // namespace tests } // namespace open3d
// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland. // // Use, modification and distribution is subject to 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) #ifndef BOOST_CORE_IGNORE_UNUSED_HPP #define BOOST_CORE_IGNORE_UNUSED_HPP #include <boost/config.hpp> namespace boost { #ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES template <typename... Ts> BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore_unused(Ts const &...) {} template <typename... Ts> BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore_unused() {} #else template <typename T1> BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore_unused(T1 const &) {} template <typename T1, typename T2> BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore_unused(T1 const &, T2 const &) {} template <typename T1, typename T2, typename T3> BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore_unused(T1 const &, T2 const &, T3 const &) {} template <typename T1, typename T2, typename T3, typename T4> BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore_unused(T1 const &, T2 const &, T3 const &, T4 const &) {} template <typename T1, typename T2, typename T3, typename T4, typename T5> BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore_unused(T1 const &, T2 const &, T3 const &, T4 const &, T5 const &) {} template <typename T1> BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore_unused() {} template <typename T1, typename T2> BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore_unused() {} template <typename T1, typename T2, typename T3> BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore_unused() {} template <typename T1, typename T2, typename T3, typename T4> BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore_unused() {} template <typename T1, typename T2, typename T3, typename T4, typename T5> BOOST_FORCEINLINE BOOST_CXX14_CONSTEXPR void ignore_unused() {} #endif } // namespace boost #endif // BOOST_CORE_IGNORE_UNUSED_HPP
;Variables only used with the Deflemask playback ROM SECTION "Deflemask player variables",wram0 NewJoyData: ds 1 OldJoyData: ds 1
; DRAW LOAD SPRITE 1 BYTE DEFINITION ROTATED ; 01.2006 aralbrec, Sprite Pack v3.0 ; sinclair spectrum version INCLUDE "clib_target_cfg.asm" SECTION code_temp_sp1 PUBLIC _SP1_DRAW_LOAD1 EXTERN _SP1_DRAW_LOAD1NR EXTERN SP1RETSPRDRAW ; following data segment copied into struct sp1_cs ld hl,0 ld ix,0 call _SP1_DRAW_LOAD1 ; following draw code called by way of SP1UpdateNow ; ; a = hor rot table ; bc = graphic disp ; hl = graphic def ptr ; ix = left graphic def ptr ; ; 51 + 138*4 - 6 + 10 = 607 cycles _SP1_DRAW_LOAD1: cp SP1V_ROTTBL/256 jp z, _SP1_DRAW_LOAD1NR add hl,bc add ix,bc ex de,hl ld h,a ; h = shift table ; de = sprite def (graph only) ; ix = left sprite def _SP1Load1Rotate: ; 0 ld a,(de) inc de ld l,a ld a,(hl) inc h ld l,(ix+0) or (hl) ld (SP1V_PIXELBUFFER+0),a ld l,(ix+1) ld b,(hl) dec h ld a,(de) inc de ld l,a ld a,b or (hl) ld (SP1V_PIXELBUFFER+1),a ; 1 ld a,(de) inc de ld l,a ld a,(hl) inc h ld l,(ix+2) or (hl) ld (SP1V_PIXELBUFFER+2),a ld l,(ix+3) ld b,(hl) dec h ld a,(de) inc de ld l,a ld a,b or (hl) ld (SP1V_PIXELBUFFER+3),a ; 2 ld a,(de) inc de ld l,a ld a,(hl) inc h ld l,(ix+4) or (hl) ld (SP1V_PIXELBUFFER+4),a ld l,(ix+5) ld b,(hl) dec h ld a,(de) inc de ld l,a ld a,b or (hl) ld (SP1V_PIXELBUFFER+5),a ; 3 ld a,(de) inc de ld l,a ld a,(hl) inc h ld l,(ix+6) or (hl) ld (SP1V_PIXELBUFFER+6),a ld l,(ix+7) ld b,(hl) dec h ld a,(de) ld l,a ld a,b or (hl) ld (SP1V_PIXELBUFFER+7),a jp SP1RETSPRDRAW
; A001590: Tribonacci numbers: a(n) = a(n-1) + a(n-2) + a(n-3) with a(0)=0, a(1)=1, a(2)=0. ; 0,1,0,1,2,3,6,11,20,37,68,125,230,423,778,1431,2632,4841,8904,16377,30122,55403,101902,187427,344732,634061,1166220,2145013,3945294,7256527,13346834,24548655,45152016,83047505,152748176,280947697,516743378,950439251,1748130326,3215312955,5913882532,10877325813,20006521300,36797729645,67681576758,124485827703,228965134106,421132538567,774583500376,1424681173049,2620397211992,4819661885417,8864740270458,16304799367867,29989201523742,55158741162067,101452742053676,186600684739485,343212167955228,631265594748389,1161078447443102,2135556210146719,3927900252338210,7224534909928031 mov $6,2 mov $10,$0 lpb $6 mov $0,$10 sub $6,1 add $0,$6 sub $0,1 add $4,1 mov $12,$0 lpb $4 sub $4,1 mov $9,$12 add $11,1 lpb $11 mov $5,$9 mov $7,2 sub $11,1 lpb $7 mov $0,$5 sub $0,1 mov $3,$0 sub $7,1 cal $3,232508 ; Number of (n+1) X (1+1) 0..2 arrays with every element next to itself plus and minus one within the range 0..2 horizontally, diagonally or antidiagonally, with no adjacent elements equal. trn $0,$3 cal $0,5 ; d(n) (also called tau(n) or sigma_0(n)), the number of divisors of n. mul $0,$3 mov $8,$0 lpe lpe lpe mov $2,$6 lpb $2 mov $1,$8 sub $2,1 lpe lpe lpb $10 sub $1,$8 mov $10,0 lpe div $1,4
#include "bound_duvdt.h" void bound_duvdt() { auto &dudt = ::dudt; auto &dvdt = ::dvdt; auto &na = ::na; auto &ncrms = ::ncrms; // for (int k=0; k<nzm; k++) { // for (int j=0; j<ny; j++) { // for (int icrm=0; icrm<ncrms; icrm++) { parallel_for( SimpleBounds<3>(nzm,ny,ncrms) , YAKL_LAMBDA (int k, int j, int icrm) { dudt(na-1,k,j,nx,icrm) = dudt(na-1,k,j,0,icrm); }); if (RUN3D) { // for (int k=0; k<nzm; k++) { // for (int i=0; i<nx; i++) { // for (int icrm=0; icrm<ncrms; icrm++) { parallel_for( SimpleBounds<3>(nzm,nx,ncrms) , YAKL_LAMBDA (int k, int i, int icrm) { dvdt(na-1,k,ny,i,icrm) = dvdt(na-1,k,0,i,icrm); }); } }
; A094373: Expansion of (1-x-x^2)/((1-x)*(1-2*x)). ; 1,2,3,5,9,17,33,65,129,257,513,1025,2049,4097,8193,16385,32769,65537,131073,262145,524289,1048577,2097153,4194305,8388609,16777217,33554433,67108865,134217729,268435457,536870913,1073741825,2147483649,4294967297,8589934593,17179869185,34359738369,68719476737,137438953473,274877906945,549755813889,1099511627777,2199023255553,4398046511105,8796093022209,17592186044417,35184372088833,70368744177665,140737488355329,281474976710657,562949953421313,1125899906842625,2251799813685249,4503599627370497,9007199254740993,18014398509481985,36028797018963969,72057594037927937,144115188075855873,288230376151711745,576460752303423489,1152921504606846977,2305843009213693953,4611686018427387905,9223372036854775809,18446744073709551617,36893488147419103233,73786976294838206465,147573952589676412929,295147905179352825857,590295810358705651713,1180591620717411303425,2361183241434822606849,4722366482869645213697,9444732965739290427393,18889465931478580854785,37778931862957161709569,75557863725914323419137,151115727451828646838273,302231454903657293676545,604462909807314587353089,1208925819614629174706177,2417851639229258349412353,4835703278458516698824705,9671406556917033397649409,19342813113834066795298817,38685626227668133590597633,77371252455336267181195265,154742504910672534362390529,309485009821345068724781057,618970019642690137449562113,1237940039285380274899124225,2475880078570760549798248449,4951760157141521099596496897,9903520314283042199192993793,19807040628566084398385987585,39614081257132168796771975169,79228162514264337593543950337,158456325028528675187087900673,316912650057057350374175801345 mov $1,2 pow $1,$0 div $1,2 add $1,1 mov $0,$1
; A130722: The twice repeated nonnegative integers at even indices, the non-repeated nonnegative integers at odd indices. ; 0,0,0,1,1,2,1,3,2,4,2,5,3,6,3,7,4,8,4,9,5,10,5,11,6,12,6,13,7,14,7,15,8,16,8,17,9,18,9,19,10,20,10,21,11,22,11,23,12,24,12,25,13,26,13,27,14,28,14,29,15,30,15,31,16,32,16,33,17,34,17,35,18,36,18,37,19,38,19,39 dif $0,2 div $0,2
; long long atoll(const char *buf) SECTION code_clib SECTION code_stdlib PUBLIC atoll EXTERN asm_atoll, l_store_64_dehldehl_mbc atoll: pop af pop bc pop hl push hl push bc push af push ix push bc ; save result * call asm_atoll pop bc ; bc = result * pop ix jp l_store_64_dehldehl_mbc ; store result ; SDCC bridge for Classic IF __CLASSIC PUBLIC _atoll defc _atoll = atoll ENDIF
#include <memory> #include <mutex> struct some_resource { void do_something() { } }; std::shared_ptr<some_resource> resource_ptr; std::mutex resource_mutex; void foo() { std::unique_lock<std::mutex> lk(resource_mutex); if (!resource_ptr) { resource_ptr.reset(new some_resource); } lk.unlock(); resource_ptr->do_something(); } int main() { foo(); return 0; }
//////////////////////////////////////////////////////////////////////////////// // Copyright (c) 2014-2016, Lawrence Livermore National Security, LLC. // Produced at the Lawrence Livermore National Laboratory. // Written by the LBANN Research Team (B. Van Essen, et al.) listed in // the CONTRIBUTORS file. <lbann-dev@llnl.gov> // // LLNL-CODE-697807. // All rights reserved. // // This file is part of LBANN: Livermore Big Artificial Neural Network // Toolkit. For details, see http://software.llnl.gov/LBANN or // https://github.com/LLNL/LBANN. // // Licensed under the Apache License, Version 2.0 (the "Licensee"); 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. // // patchworks_common.hpp - LBANN PATCHWORKS header for common definitions //////////////////////////////////////////////////////////////////////////////// /** * LBANN PATCHWORKS common header * - includes commonly used macros, definitions and declarations */ #include "lbann_config.hpp" #ifdef LBANN_HAS_OPENCV #ifndef _PATCHWORKS_COMMON_H_ #define _PATCHWORKS_COMMON_H_ #include <utility> // std::pair #include <limits> #include <cstdint> #include <string> #include "lbann/data_readers/opencv_extensions.hpp" namespace lbann { namespace patchworks { /// Patch displacement type using displacement_type = std::pair<int, int>; #if 0 // using 32-bit floating point for intermediate image data processing using pw_fp_t = float; using pw_cv_vec3 = cv::Vec3f; #define _PATCHWORKS_STAT_FLOAT_ 32 #define _PW_CV_FP_ CV_32FC3 #else // using 64-bit floating point for intermediate image data processing using pw_fp_t = double; using pw_cv_vec3 = cv::Vec3d; #define _PATCHWORKS_STAT_FLOAT_ 64 #define _PW_CV_FP_ CV_64FC3 #endif } // end of namespace patchworks } // end of namespace lbann #endif // _PATCHWORKS_COMMON_H_ #endif // LBANN_HAS_OPENCV
extern m7_ippsDLPGenerateDH:function extern n8_ippsDLPGenerateDH:function extern y8_ippsDLPGenerateDH:function extern e9_ippsDLPGenerateDH:function extern l9_ippsDLPGenerateDH:function extern n0_ippsDLPGenerateDH:function extern k0_ippsDLPGenerateDH:function extern ippcpJumpIndexForMergedLibs extern ippcpSafeInit:function segment .data align 8 dq .Lin_ippsDLPGenerateDH .Larraddr_ippsDLPGenerateDH: dq m7_ippsDLPGenerateDH dq n8_ippsDLPGenerateDH dq y8_ippsDLPGenerateDH dq e9_ippsDLPGenerateDH dq l9_ippsDLPGenerateDH dq n0_ippsDLPGenerateDH dq k0_ippsDLPGenerateDH segment .text global ippsDLPGenerateDH:function (ippsDLPGenerateDH.LEndippsDLPGenerateDH - ippsDLPGenerateDH) .Lin_ippsDLPGenerateDH: db 0xf3, 0x0f, 0x1e, 0xfa call ippcpSafeInit wrt ..plt align 16 ippsDLPGenerateDH: db 0xf3, 0x0f, 0x1e, 0xfa mov rax, qword [rel ippcpJumpIndexForMergedLibs wrt ..gotpc] movsxd rax, dword [rax] lea r11, [rel .Larraddr_ippsDLPGenerateDH] mov r11, qword [r11+rax*8] jmp r11 .LEndippsDLPGenerateDH:
INCLUDE "../../../hardware.inc/hardware.inc" default_palette EQU %11100100 ; ########################################################### wait_for_vblank: MACRO .loop\@ ld a, [rLY] cp SCRN_Y; jr c, .loop\@ ENDM ; ########################################################### var: MACRO PUSHS SECTION "variables", WRAM0 IF _NARG != 3 FAIL "VAR: Expected 3 args, but got {d:_NARG}" ENDC \1:: \2 \3 POPS ENDM ; ########################################################### lda: MACRO ;PRINTT "arg1 \1\n" ;PRINTT "arg2 \2\n" IF "\2" == "a" ;pass ELIF "\2" == "0" xor a ELSE ld a, \2 ENDC ld \1, a ENDM ; ########################################################### lcd: MACRO lda [rLCDC], \1 ENDM ; ########################################################### sound: MACRO lda [rAUDENA], \1 ENDM ; ########################################################### breakpoint: MACRO ld b,b ENDM ; ########################################################### memcpy: MACRO ; dst, src, length ld hl, \1 ld de, \2 ld bc, \3 .loop_start\@: ;ld a, [de] ;ld [hli], a lda [hli], [de] inc de dec bc ld a, b or c jr nz, .loop_start\@ ENDM ; ########################################################### SECTION "Header", ROM0[$100] EntryPoint: nop jp main EntryPointEnd: end_of_cartridge_header EQU $150 header_length EQU end_of_cartridge_header - EntryPointEnd REPT header_length db 0 ENDR ; ###########################################################
.global s_prepare_buffers s_prepare_buffers: push %r11 push %r15 push %r8 push %rcx push %rdi push %rdx push %rsi lea addresses_D_ht+0x5cf4, %rsi lea addresses_A_ht+0x17dc0, %rdi nop add $64351, %rdx mov $48, %rcx rep movsb nop nop nop nop dec %r8 lea addresses_A_ht+0x14f4, %r11 nop nop nop xor $3625, %r15 movups (%r11), %xmm4 vpextrq $0, %xmm4, %rdi nop nop dec %r11 lea addresses_A_ht+0xf264, %rsi and $49986, %r8 mov $0x6162636465666768, %rcx movq %rcx, (%rsi) nop nop nop nop nop sub $6783, %rdx lea addresses_WC_ht+0x1eb74, %r8 nop nop nop cmp $8629, %rdx mov (%r8), %r11w nop nop nop and %rcx, %rcx lea addresses_normal_ht+0x19a74, %r15 nop nop nop cmp $64528, %rdx movl $0x61626364, (%r15) nop nop sub $21593, %rdi lea addresses_WC_ht+0x1ccf4, %rdx nop nop nop nop sub %rcx, %rcx mov (%rdx), %r8d nop nop add %r15, %r15 lea addresses_WT_ht+0xcc9a, %rsi nop sub %r15, %r15 mov $0x6162636465666768, %r8 movq %r8, %xmm2 movups %xmm2, (%rsi) nop nop nop nop xor $30462, %r15 lea addresses_WT_ht+0x130f4, %r15 clflush (%r15) nop nop nop nop nop cmp $63917, %r8 mov $0x6162636465666768, %rsi movq %rsi, %xmm3 movups %xmm3, (%r15) nop nop nop nop nop sub %rcx, %rcx lea addresses_WT_ht+0xb618, %rdi nop nop nop nop nop sub %rcx, %rcx mov $0x6162636465666768, %rdx movq %rdx, %xmm7 and $0xffffffffffffffc0, %rdi vmovntdq %ymm7, (%rdi) nop nop xor $20112, %r15 lea addresses_WT_ht+0x459c, %rsi lea addresses_normal_ht+0x1c0f4, %rdi nop nop nop add $15099, %r8 mov $71, %rcx rep movsw sub $14833, %r8 lea addresses_WC_ht+0xf6c4, %r11 dec %rcx mov $0x6162636465666768, %rsi movq %rsi, %xmm4 vmovups %ymm4, (%r11) add $57982, %r15 pop %rsi pop %rdx pop %rdi pop %rcx pop %r8 pop %r15 pop %r11 ret .global s_faulty_load s_faulty_load: push %r10 push %r12 push %r14 push %r9 push %rax push %rdx // Faulty Load lea addresses_WC+0x1a0f4, %rdx nop nop nop nop lfence mov (%rdx), %eax lea oracles, %rdx and $0xff, %rax shlq $12, %rax mov (%rdx,%rax,1), %rax pop %rdx pop %rax pop %r9 pop %r14 pop %r12 pop %r10 ret /* <gen_faulty_load> [REF] {'src': {'type': 'addresses_WC', 'same': False, 'size': 4, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} [Faulty Load] {'src': {'type': 'addresses_WC', 'same': True, 'size': 4, 'congruent': 0, 'NT': True, 'AVXalign': False}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'type': 'addresses_D_ht', 'congruent': 7, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 0, 'same': False}, 'OP': 'REPM'} {'src': {'type': 'addresses_A_ht', 'same': False, 'size': 16, 'congruent': 9, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'dst': {'type': 'addresses_A_ht', 'same': False, 'size': 8, 'congruent': 3, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_WC_ht', 'same': False, 'size': 2, 'congruent': 7, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'dst': {'type': 'addresses_normal_ht', 'same': False, 'size': 4, 'congruent': 7, 'NT': True, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_WC_ht', 'same': False, 'size': 4, 'congruent': 10, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'dst': {'type': 'addresses_WT_ht', 'same': True, 'size': 16, 'congruent': 1, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'dst': {'type': 'addresses_WT_ht', 'same': False, 'size': 16, 'congruent': 11, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'dst': {'type': 'addresses_WT_ht', 'same': False, 'size': 32, 'congruent': 1, 'NT': True, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_WT_ht', 'congruent': 1, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 10, 'same': False}, 'OP': 'REPM'} {'dst': {'type': 'addresses_WC_ht', 'same': False, 'size': 32, 'congruent': 2, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'38': 21829} 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 */
/********** This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. (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 **********/ // "liveMedia" // Copyright (c) 1996-2012 Live Networks, Inc. All rights reserved. // RTP sink for MPEG video (RFC 2250) // Implementation #include "MPEG1or2VideoRTPSink.hh" #include "MPEG1or2VideoStreamFramer.hh" MPEG1or2VideoRTPSink::MPEG1or2VideoRTPSink(UsageEnvironment& env, Groupsock* RTPgs) : VideoRTPSink(env, RTPgs, 32, 90000, "MPV") { fPictureState.temporal_reference = 0; fPictureState.picture_coding_type = fPictureState.vector_code_bits = 0; } MPEG1or2VideoRTPSink::~MPEG1or2VideoRTPSink() { } MPEG1or2VideoRTPSink* MPEG1or2VideoRTPSink::createNew(UsageEnvironment& env, Groupsock* RTPgs) { return new MPEG1or2VideoRTPSink(env, RTPgs); } Boolean MPEG1or2VideoRTPSink::sourceIsCompatibleWithUs(MediaSource& source) { // Our source must be an appropriate framer: return source.isMPEG1or2VideoStreamFramer(); } Boolean MPEG1or2VideoRTPSink::allowFragmentationAfterStart() const { return True; } Boolean MPEG1or2VideoRTPSink ::frameCanAppearAfterPacketStart(unsigned char const* frameStart, unsigned numBytesInFrame) const { // A 'frame' (which in this context can mean a header or a slice as well as a // complete picture) can appear at other than the first position in a packet // in all situations, EXCEPT when it follows the end of (i.e., the last slice // of) a picture. I.e., the headers at the beginning of a picture must // appear at the start of a RTP packet. if (!fPreviousFrameWasSlice) return True; // A slice is already packed into this packet. We allow this new 'frame' // to be packed after it, provided that it is also a slice: return numBytesInFrame >= 4 && frameStart[0] == 0 && frameStart[1] == 0 && frameStart[2] == 1 && frameStart[3] >= 1 && frameStart[3] <= 0xAF; } #define VIDEO_SEQUENCE_HEADER_START_CODE 0x000001B3 #define PICTURE_START_CODE 0x00000100 void MPEG1or2VideoRTPSink ::doSpecialFrameHandling(unsigned fragmentationOffset, unsigned char* frameStart, unsigned numBytesInFrame, struct timeval framePresentationTime, unsigned numRemainingBytes) { Boolean thisFrameIsASlice = False; // until we learn otherwise if (isFirstFrameInPacket()) { fSequenceHeaderPresent = fPacketBeginsSlice = fPacketEndsSlice = False; } if (fragmentationOffset == 0) { // Begin by inspecting the 4-byte code at the start of the frame: if (numBytesInFrame < 4) return; // shouldn't happen unsigned startCode = (frameStart[0]<<24) | (frameStart[1]<<16) | (frameStart[2]<<8) | frameStart[3]; if (startCode == VIDEO_SEQUENCE_HEADER_START_CODE) { // This is a video sequence header fSequenceHeaderPresent = True; } else if (startCode == PICTURE_START_CODE) { // This is a picture header // Record the parameters of this picture: if (numBytesInFrame < 8) return; // shouldn't happen unsigned next4Bytes = (frameStart[4]<<24) | (frameStart[5]<<16) | (frameStart[6]<<8) | frameStart[7]; unsigned char byte8 = numBytesInFrame == 8 ? 0 : frameStart[8]; fPictureState.temporal_reference = (next4Bytes&0xFFC00000)>>(32-10); fPictureState.picture_coding_type = (next4Bytes&0x00380000)>>(32-(10+3)); unsigned char FBV, BFC, FFV, FFC; FBV = BFC = FFV = FFC = 0; switch (fPictureState.picture_coding_type) { case 3: FBV = (byte8&0x40)>>6; BFC = (byte8&0x38)>>3; // fall through to: case 2: FFV = (next4Bytes&0x00000004)>>2; FFC = ((next4Bytes&0x00000003)<<1) | ((byte8&0x80)>>7); } fPictureState.vector_code_bits = (FBV<<7) | (BFC<<4) | (FFV<<3) | FFC; } else if ((startCode&0xFFFFFF00) == 0x00000100) { unsigned char lastCodeByte = startCode&0xFF; if (lastCodeByte <= 0xAF) { // This is (the start of) a slice thisFrameIsASlice = True; } else { // This is probably a GOP header; we don't do anything with this } } else { // The first 4 bytes aren't a code that we recognize. envir() << "Warning: MPEG1or2VideoRTPSink::doSpecialFrameHandling saw strange first 4 bytes " << (void*)startCode << ", but we're not a fragment\n"; } } else { // We're a fragment (other than the first) of a slice. thisFrameIsASlice = True; } if (thisFrameIsASlice) { // This packet begins a slice iff there's no fragmentation offset: fPacketBeginsSlice = (fragmentationOffset == 0); // This packet also ends a slice iff there are no fragments remaining: fPacketEndsSlice = (numRemainingBytes == 0); } // Set the video-specific header based on the parameters that we've seen. // Note that this may get done more than once, if several frames appear // in the packet. That's OK, because this situation happens infrequently, // and we want the video-specific header to reflect the most up-to-date // information (in particular, from a Picture Header) anyway. unsigned videoSpecificHeader = // T == 0 (fPictureState.temporal_reference<<16) | // AN == N == 0 (fSequenceHeaderPresent<<13) | (fPacketBeginsSlice<<12) | (fPacketEndsSlice<<11) | (fPictureState.picture_coding_type<<8) | fPictureState.vector_code_bits; setSpecialHeaderWord(videoSpecificHeader); // Also set the RTP timestamp. (As above, we do this for each frame // in the packet.) setTimestamp(framePresentationTime); // Set the RTP 'M' (marker) bit iff this frame ends (i.e., is the last // slice of) a picture (and there are no fragments remaining). // This relies on the source being a "MPEG1or2VideoStreamFramer". MPEG1or2VideoStreamFramer* framerSource = (MPEG1or2VideoStreamFramer*)fSource; if (framerSource != NULL && framerSource->pictureEndMarker() && numRemainingBytes == 0) { setMarkerBit(); framerSource->pictureEndMarker() = False; } fPreviousFrameWasSlice = thisFrameIsASlice; } unsigned MPEG1or2VideoRTPSink::specialHeaderSize() const { // There's a 4 byte special audio header: return 4; }
SECTION code_clib PUBLIC pixeladdress INCLUDE "graphics/grafix.inc" EXTERN __primo_screen_base ; ; $Id: pixladdr.asm,v 1.9 2016-04-22 20:17:17 dom Exp $ ; ; ****************************************************************** ; ; Get absolute pixel address in map of virtual (x,y) coordinate. ; ; in: hl = (x,y) coordinate of pixel (h,l) ; ; out: de = address of pixel byte ; a = bit number of byte where pixel is to be placed ; fz = 1 if bit number is 0 of pixel position ; .pixeladdress ld a,h ;Save x ld h,0 add hl,hl ;*32 add hl,hl add hl,hl add hl,hl add hl,hl ld e,a srl e srl e srl e ld d,0 add hl,de ld de,(__primo_screen_base) add hl,de ex de,hl and 7 xor 7 ret
Entity start No options Constants 0 S start 1 S tab 2 S index 3 I 1 4 I 10 5 S tab[ 6 S ]= 7 I 4 8 S io.writeln End Valid context (always) No properties Def start No parameters Local variables 0 table tab 1 int index End No results ldconst 3 --> [1] stvar 1 --> [index] 2: ldvar 1 --> [index] ldconst 4 --> [10] le ifnot 18 --> [18] jmp 12 --> [12] 7: ldvar 1 --> [index] ldconst 3 --> [1] add stvar 1 --> [index] jmp 2 --> [2] 12: ldvar 1 --> [index] ldvar 1 --> [index] ldconst 4 --> [10] mul sttab 0 --> [tab] jmp 7 --> [7] 18: ldconst 3 --> [1] stvar 1 --> [index] 20: ldvar 1 --> [index] ldconst 4 --> [10] le ifnot 38 --> [38] jmp 30 --> [30] 25: ldvar 1 --> [index] ldconst 3 --> [1] add stvar 1 --> [index] jmp 20 --> [20] 30: ldconst 5 --> [tab[] ldvar 1 --> [index] ldconst 6 --> []=] ldvar 1 --> [index] ldtab 0 --> [tab] ldconst 7 --> [4] lcall 8 --> [io.writeln] jmp 25 --> [25] 38: stop End End
; A026644: a(n) = a(n-1) + 2*a(n-2) + 2, for n>=3, where a(0)= 1, a(1)= 2, a(2)= 4. ; 1,2,4,10,20,42,84,170,340,682,1364,2730,5460,10922,21844,43690,87380,174762,349524,699050,1398100,2796202,5592404,11184810,22369620,44739242,89478484,178956970,357913940,715827882,1431655764,2863311530,5726623060,11453246122,22906492244,45812984490,91625968980,183251937962,366503875924,733007751850,1466015503700,2932031007402,5864062014804,11728124029610,23456248059220,46912496118442,93824992236884,187649984473770,375299968947540,750599937895082,1501199875790164,3002399751580330 mov $1,2 pow $1,$0 mul $1,4 sub $1,5 div $1,3 add $1,1 mov $0,$1
<% import collections import pwnlib.abi import pwnlib.constants import pwnlib.shellcraft %> <%docstring>mq_timedsend(mqdes, msg_ptr, msg_len, msg_prio, abs_timeout) -> str Invokes the syscall mq_timedsend. See 'man 2 mq_timedsend' for more information. Arguments: mqdes(mqd_t): mqdes msg_ptr(char*): msg_ptr msg_len(size_t): msg_len msg_prio(unsigned): msg_prio abs_timeout(timespec*): abs_timeout Returns: int </%docstring> <%page args="mqdes=0, msg_ptr=0, msg_len=0, msg_prio=0, abs_timeout=0"/> <% abi = pwnlib.abi.ABI.syscall() stack = abi.stack regs = abi.register_arguments[1:] allregs = pwnlib.shellcraft.registers.current() can_pushstr = ['msg_ptr'] can_pushstr_array = [] argument_names = ['mqdes', 'msg_ptr', 'msg_len', 'msg_prio', 'abs_timeout'] argument_values = [mqdes, msg_ptr, msg_len, msg_prio, abs_timeout] # Load all of the arguments into their destination registers / stack slots. register_arguments = dict() stack_arguments = collections.OrderedDict() string_arguments = dict() dict_arguments = dict() array_arguments = dict() syscall_repr = [] for name, arg in zip(argument_names, argument_values): if arg is not None: syscall_repr.append('%s=%r' % (name, arg)) # If the argument itself (input) is a register... if arg in allregs: index = argument_names.index(name) if index < len(regs): target = regs[index] register_arguments[target] = arg elif arg is not None: stack_arguments[index] = arg # The argument is not a register. It is a string value, and we # are expecting a string value elif name in can_pushstr and isinstance(arg, str): string_arguments[name] = arg # The argument is not a register. It is a dictionary, and we are # expecting K:V paris. elif name in can_pushstr_array and isinstance(arg, dict): array_arguments[name] = ['%s=%s' % (k,v) for (k,v) in arg.items()] # The arguent is not a register. It is a list, and we are expecting # a list of arguments. elif name in can_pushstr_array and isinstance(arg, (list, tuple)): array_arguments[name] = arg # The argument is not a register, string, dict, or list. # It could be a constant string ('O_RDONLY') for an integer argument, # an actual integer value, or a constant. else: index = argument_names.index(name) if index < len(regs): target = regs[index] register_arguments[target] = arg elif arg is not None: stack_arguments[target] = arg # Some syscalls have different names on various architectures. # Determine which syscall number to use for the current architecture. for syscall in ['SYS_mq_timedsend']: if hasattr(pwnlib.constants, syscall): break else: raise Exception("Could not locate any syscalls: %r" % syscalls) %> /* mq_timedsend(${', '.join(syscall_repr)}) */ %for name, arg in string_arguments.items(): ${pwnlib.shellcraft.pushstr(arg, append_null=('\x00' not in arg))} ${pwnlib.shellcraft.mov(regs[argument_names.index(name)], abi.stack)} %endfor %for name, arg in array_arguments.items(): ${pwnlib.shellcraft.pushstr_array(regs[argument_names.index(name)], arg)} %endfor %for name, arg in stack_arguments.items(): ${pwnlib.shellcraft.push(arg)} %endfor ${pwnlib.shellcraft.setregs(register_arguments)} ${pwnlib.shellcraft.syscall(syscall)}
/*******************************************************************\ Module: Pointer Logic Author: Daniel Kroening, kroening@kroening.com \*******************************************************************/ /// \file /// Pointer Logic #include "pointer_logic.h" #include <cassert> #include <util/arith_tools.h> #include <util/c_types.h> #include <util/invariant.h> #include <util/pointer_offset_size.h> #include <util/prefix.h> #include <util/std_expr.h> bool pointer_logict::is_dynamic_object(const exprt &expr) const { if(expr.type().get_bool(ID_C_dynamic)) return true; if(expr.id()==ID_symbol) if(has_prefix(id2string(to_symbol_expr(expr).get_identifier()), "symex_dynamic::")) return true; return false; } void pointer_logict::get_dynamic_objects(std::vector<std::size_t> &o) const { o.clear(); std::size_t nr=0; for(pointer_logict::objectst::const_iterator it=objects.begin(); it!=objects.end(); it++, nr++) if(is_dynamic_object(*it)) o.push_back(nr); } std::size_t pointer_logict::add_object(const exprt &expr) { // remove any index/member if(expr.id()==ID_index) { assert(expr.operands().size()==2); return add_object(expr.op0()); } else if(expr.id()==ID_member) { assert(expr.operands().size()==1); return add_object(expr.op0()); } return objects.number(expr); } exprt pointer_logict::pointer_expr( std::size_t object, const pointer_typet &type) const { pointert pointer(object, 0); return pointer_expr(pointer, type); } exprt pointer_logict::pointer_expr( const pointert &pointer, const pointer_typet &type) const { if(pointer.object==null_object) // NULL? { if(pointer.offset==0) { constant_exprt result(type); result.set_value(ID_NULL); return result; } else { constant_exprt null(type); null.set_value(ID_NULL); return plus_exprt(null, from_integer(pointer.offset, pointer_diff_type())); } } else if(pointer.object==invalid_object) // INVALID? { constant_exprt result(type); result.set_value("INVALID"); return result; } if(pointer.object>=objects.size()) { constant_exprt result(type); result.set_value("INVALID-"+std::to_string(pointer.object)); return result; } const exprt &object_expr=objects[pointer.object]; exprt deep_object=object_rec(pointer.offset, type, object_expr); return address_of_exprt(deep_object, type); } exprt pointer_logict::object_rec( const mp_integer &offset, const typet &pointer_type, const exprt &src) const { if(src.type().id()==ID_array) { mp_integer size= pointer_offset_size(src.type().subtype(), ns); if(size<=0) return src; mp_integer index=offset/size; mp_integer rest=offset%size; if(rest<0) rest=-rest; index_exprt tmp(src.type().subtype()); tmp.index()=from_integer(index, typet(ID_integer)); tmp.array()=src; return object_rec(rest, pointer_type, tmp); } else if(src.type().id()==ID_struct) { const struct_typet::componentst &components= to_struct_type(src.type()).components(); if(offset<0) return src; mp_integer current_offset=0; for(const auto &c : components) { assert(offset>=current_offset); const typet &subtype=c.type(); mp_integer sub_size=pointer_offset_size(subtype, ns); assert(sub_size>0); mp_integer new_offset=current_offset+sub_size; if(new_offset>offset) { // found it member_exprt tmp(src, c); return object_rec( offset-current_offset, pointer_type, tmp); } assert(new_offset<=offset); current_offset=new_offset; assert(current_offset<=offset); } return src; } else if(src.type().id()==ID_union) return src; return src; } pointer_logict::pointer_logict(const namespacet &_ns):ns(_ns) { // add NULL null_object=objects.number(exprt(ID_NULL)); assert(null_object==0); // add INVALID invalid_object=objects.number(exprt("INVALID")); } pointer_logict::~pointer_logict() { }
-- HUMAN RESOURCE MACHINE PROGRAM -- COMMENT 11 INBOX COPYTO 0 INBOX COPYTO 1 INBOX OUTBOX COPYFROM 1 OUTBOX COPYFROM 0 OUTBOX COMMENT 12 INBOX OUTBOX INBOX OUTBOX INBOX OUTBOX a: b: c: d: e: f: COMMENT 4 INBOX COPYTO 0 INBOX COPYTO 1 INBOX COPYTO 2 SUB 1 JUMPN i COMMENT 0 COPYFROM 1 SUB 0 JUMPN g COMMENT 5 COPYFROM 0 OUTBOX COPYFROM 1 OUTBOX COPYFROM 2 OUTBOX JUMP d g: COMMENT 6 COPYFROM 2 SUB 0 JUMPN h COMMENT 9 COPYFROM 1 OUTBOX COPYFROM 0 OUTBOX COPYFROM 2 OUTBOX JUMP b h: COMMENT 10 COPYFROM 1 OUTBOX COPYFROM 2 OUTBOX COPYFROM 0 OUTBOX JUMP a COMMENT 1 i: COPYFROM 1 SUB 0 JUMPN k COMMENT 3 COPYFROM 2 SUB 0 JUMPN j COMMENT 7 COPYFROM 0 OUTBOX COPYFROM 2 OUTBOX COPYFROM 1 OUTBOX JUMP c j: COMMENT 8 COPYFROM 2 OUTBOX COPYFROM 0 OUTBOX COPYFROM 1 OUTBOX JUMP e k: COMMENT 2 COPYFROM 2 OUTBOX COPYFROM 1 OUTBOX COPYFROM 0 OUTBOX JUMP f DEFINE COMMENT 0 eJzTZWBgMJayNLaXzjbzkck2W6j8w99FSymZX/dFPlCK4bH5XEsVsxYPB0PpKb0G0ltv6dfvLtVbsBck x+AZU37aW6uEJaImAsQ1jVnqBaJ5vNbXJAZyTc4Lkp6iG1I3yzVs/VzZqNAVILn8Oktjpm5L4+jubDO1 vmyzGRPO2fT0v7djbZEqFq1TaikuN1nGWxa6Ykvp9DXLS3as8yv5tUmq99cmkN49tVLFze1aJQyjYBSM AqoBAMVpPIw; DEFINE COMMENT 1 eJwzZmBgqBBcoskkdkzbxOC57mdDLxMHQwHHqUqcRUtl2rp8ZKSnHBSfvuabiM62Bsm4nRm6cTv/G9ls P2Xqu2OTsfRWoHaGT9JaJfy63mUg9vaI47nno1LSOdOP+QjmaxrtyMs2A4lrRv8seJLc1hWUu37uhYJP C40qubecqBM5qlTvegIkXzN1qVfDEqVk/h1tXeq7bvQ37uKaDBL32Xvd12fv+ViT3dtzbu3aX8u/40Tf xC1xOys2XTxwbOOMs2vX/768dr3tDY919XcYRsEoGAUkAwARI1YF; DEFINE COMMENT 2 eJxLYGBgeMjNYRDMp2n0XUvTKEB7ruUxtRYPD+UP8VOVlmWfkvcu+ySd2vFM6uWEEom6WXziZau2il08 4CPDfERZgfnIPY2wk8w6rididESOHtL9dAhoHMNZCcbEmdLOqfLqy7JB/Odux3MTA7d53w8xdC6LuqbT FL1VSzP6ux5I7rCzVLGE96+J6wM+LawK3rHON679jGTiyQuSiTxXQfKTs+dazs9hcNhSypgI4rs1fdez atQ0qq5XdKqu3+adXMuYuKS6NdOuyqWtvuJGv2T5+rkHyhbsBantmBZT/m66dWnPUgHHa6s5DDrXHNN+ t3ar1ru1z3VrVksYgtS4z6itXDDjQX38rJD2+FnLe9SXrFjbsOTXpk/LfHeIrxI5ClKzad9131MHaiL6 Lr6coHDv4gGQ2OdLMeUmF9fXmFx0adO4wDU58Mynhd9Pr1jbepJ7S+tJm+0KJ+p3g9SZXNxf23cxpnzW pRt5yy4vyy68JhlUd/253/XryW6Lbp2zYRgFo2CAAQAVO6XA; DEFINE COMMENT 3 eJwLYGBgSODfqrVU5pqOtZKE4TulKNMahbVWK0UFk8yFSzLkBTmL5AW9y8yFcysmCM+rniuyvuadUm0l UBuDh+Uxn+8O+6xlXDSNQPxd1j/879vNjbKwfxAX63Q897DzzwKQeFVws/rl4K1aX2JL3H3jtnlHxV/3 BYmvT9uq9SdVwtAweZ+1YbKAY1Hidd+0BI5AnoSaCN8459QvsZxFfTG5FX0x1qUg9VK9HAZne6vNd876 EC802yilZe72nLtzfxa8midV/G3+/lqQmpULjmmvXBBl+m3+OZuLcySDfs2wLr06lbFJaWpqR/Lkad0g NRZbosMstkgG9e7eZw3iu2ztjQzYti46Y8fx3M97ais7D93oB6s7Ndey9HyyG8MV71Ceq9FhILHQ21Gm XTe2eRdeC07judq+mmEUjIIhDgA6DnvM; DEFINE COMMENT 4 eJxzZGBg+CezRPOW5DWdDPFrOhOEq821hZ77aQuti54grJQsLVGSIaw2NYtZR6uEX1erpFQvpvy5gVCz iUHsDH5dl+UJqgf3WysxH9EWEjmawL9hX4Xggr1AIxm2OTmnxjpNXwNiT7LPEp1k/0420PG5LrPTe7vz Lq4nQOIels/9Wu0kg2Kdfvir+PzwB4mVRR3P3RwvVTw9ZV71m+wTff1Fvza9KIrbWV5w8cDqXOYju9NF jq5Pu3ggKb1+d1Dur00XCj4t9Cupm8VYenE+SH98y6eF8S3Tuu0nTOu+OrWt6+G01A6Q+KstlkIB2z7E B2xbP3fuVt8dILFHazgCbQ7PjWIYBaNgBAMAgSpoVA; DEFINE COMMENT 5 eJxzYGBg0Oee6tnBfcyHT/xG3jOp9TX6iuvnTlXasQ4oxbBQ2SqkU/FBnLLCh/hT8iUZU3jidoLEr5nN q55k35r5wc87dJH/D/8//lrBH/yiw7p8c8JB8u8t5lUr2DI2fXZXXjrNz2Y7SOxG0n3b3enbvINyBZNA /C2l52yiSls8vhbnhLPm5VY8yPq0ECSuNJWzSH8aZ5H19O05GYusQg4uWur1aZmTS8SK+7Yg+SnTfxYs mPGz4OhsoWamhdpT+RZdnF+y2GRZwxKX5SD51P3XdErPL9E8f17TSOb8e7tjx61CZu4xbu3d/XLCrEs3 +kFqHh9aF73u6L4YhlEwCkY4AAAim2kp; DEFINE COMMENT 6 eJyLZWBg+McmoMDF8VzXmmeqJxt/dBgb/76Ynfwf4oFSDGcljmkfFOcwOCgeZRojJuDoLyoZ5CziHeos MjdKW0gwKYE/pvwdj/QUkNq1Kr2RJgZOLjMNDZ0/Gya7Neq3eIDEfys7p8boxJRv05lXDeK/tndUDnRM Uj3tnaQ6za9ZfX3AMe31ARwGf/x7LKb5nbOJ9FwX/d2hr0rBdlq3gu2Jvml+N/pDA7b3gvSauK2L/uz+ IK7OhzERxN9Tu1VLqf65rlvTfdufTcluQq3HfEDiUr3f9fh6qs23dAs43m33Dr3YVpIR3zKvOr5FqBkk f3Xq+VimhUu9QGzzeTHlGYse1H9adqMfxF8wQzDp14zgtFfztEpA/JLFS72Mly712rjC0BnE37ZdwpB7 P0egwSGjlKmHU9KnHl6WbXFKqNnldGpH60mlFpCayyeqzRcdUXTyOLLN2+CQVvCmfcFpvbtrK012X6hj GAWjYBABAC2vhsE; DEFINE COMMENT 7 eJzzZ2BgmMKT7HZUYF9MjcKnhUAuwyn5675nJbbnZIjPq/4m0tZ1T+hE3z0hrskgOXNh6SkXBXNnVghe nJ8jcHE+SOy5wfHcSluOwNuuik4S3tlmILFUk+05lbYfGyS8lZeC+L5xUaZR8dXm/UXZZl+Leyz8Ss7Z NBeWuF8o0AoWzdiecybRpe181IF556NCV8hG7VgnmTh9zZXM6Wvm54SuAOlPSrcuLS9YXwNiN/QdzxWa vdRrwrxzNiWLvUxmLitWW7q8WA0kVzPVu+zd9Af1F+dM6/60DOK+xl3ZZr27eyxm7hFwFD6ekm5x6kbe pFNaJd9Pa5WA5APPbM95fepBfe5x7ansx5gWsx87MO8YkK1w4kRf4JkLddvOchY1XijJ+HyJI9D3sqFz 5JX3dpFXokwZRsEoGAYAAIdrg/k; DEFINE COMMENT 8 eJxzYWBgOMn5XW+laLbZI8Vq84uCMeU1XOvncnG4LA9nX7HWm+3mBm827i01XK82yqufXA9UzsDGP6+6 g1urpEDeuwzEr7TdF8PstM37szuDg6/HPmtDXw4DWz8OA5Dca/vtOTIutZWe/qkrF/m/2pgYqLMtMfDX JpDciYy1VrxlnEV2VS8nJNfOn7OnNnXllXruLe0NC/aC5OXaBBxZW1o88uuC09QqPjZ8LfaZ3lxYtgok N2He3Kg58+dGVWySMLTYImH4assxbZC4/4IbecZLGZs2rljeU7DKZprwxvbVIPH7J5/7MZ+NDjt/PjjN 5GJKet/FqVkgcZG7hs6LbvVGNl6om3XonM12hlEwCkYYAABODGj7; DEFINE COMMENT 9 eJyLYWBguMqVbXaVa67lOx4Bx3c8Ti47+X/47+TPCa8Q3BfjL/qzIEZMqhiojGGv3Hu7jbKKThtlk93m iniX3RPSnnpUQHlpMF/ZqmA+m+0LePN2gdS5aM2rzrWRDPptWRNhYmCUAhJ7pdlX9dkwdoaP0YF5Nhav NoLE6nwYHBb5e4e+CS3J2B5RW/kiJqQ9LcFm2v6EulkgecXM93aqSeuiHWOD0zSjX+Rvj7AuDQxfXzMv zLj1fsi07rYQ6SnrA9pXP/ZVObbMI+wkSM+e2v211fXWpTtaUtIvtkHs5uvRCo7uzgm3asyt+Fu9vZez dntvdT3XZLMOnW1mHXm7VnSJHGXqDjsZ3S1yFKT+7OJm9aXLl2iW7rymo76LwyBjh5fJ3K2Gztqb10WH rC/JWLiOsyhl5Ym+iBWxMzIW3dzAtPDgfunFC/aGrK/fHbLed0fORp1tIHP+LTdKWbguJR0cJltv5N3b vD2HYRSMgkEGAC4+k4M; DEFINE COMMENT 10 eJzzZWBgyBE45nNUQDIoQzymXFriQf0zqdJOoDDDb2Wl5N/KN/KslbzL9BWNWwvkt/emyOXONJbi3qIu efEASE2E8fIeA/PUjlWOL/IFnF/kg8SmWkhPEbFhWrzNiXuLgHPeribXg/tB4gKRyW5XMls83HK2ec/P kQyanG0Vopv1IG5xqlRxXVJIO0/Cr4m+cVyTz0e5LC+LWrFWMXPFWpA+r9T9tSB6QdPyHq12oean/cuy P05Ylr1kYko6SDy71WbanM5PC/l6VqzlmixydO/ktFP602acBck9WuPkIrwxOuzWrpjy3t0h7b+PfFoY cjR0Re7xHetyj4euAKkRPv7DX+Wgc6rP3phyn70X6hp3hbQ37prWfWjH9l7m7dpTmbfHztDenLry0qZX G49t/LWJYRSMgmEEAAozf2s; DEFINE COMMENT 11 eJxrYWBgqFFYomkvvUSzQfKaDp94tbmzSIuHs8g27wzxH/720r2RG2X3xdQo7IsBKmVYqf1dj1knypRf d64lv66Tyzm9fTGN+s/9lhkpOp0yVXR6bJ7sZmPxw9/DUit4nZVVCEjPc7dg102eTi6F3udsCr29TDZ5 epl8dj9n89wNqM9DK/i6T01EW0h0GEjtl9hj2pvjj2kvTpUwzMrfZy1bcN33SH5rZlze8dyfOTfyrmQe z92dPjUrKV0p2ayII9CpWDLIqbgmAqQ3uHmtVXBzTcSCJsZEtyaIeXJte6Xk2p7xyLW9k93RUqy2o6XH Yk2zVUhwM0cgSP5EXZTphA5LYxD76Gwvk4tzvEy0537XM593Tcd/gXMqSHymdOgKab3UlaV6K9b+k7n0 8JN02Ktbkumvb0nOfHdMbeV7kJp3SqbHhdVMj4PYoVYqxy7bfjr03E16a6TnirUqPivWgsQrbVWOZTrr Xtdw9bu5zOPSQ5BYVuSOdU3RcTtnxy7YOzv24oHlcY8OgsST0j8tjIq3vcEQ//iRY2z6a8fYz49B4vUV psefVrqe8Kr+dGhKo8327FbuLSDx7sqwkxtqbl3cUCNzrb3B7SVILHzSwwX/JgovYZuVdmrnrFsXJ8zb eH/CPIg56ktyZ/Iterhg5YIVa99Nv3VxyvT82zVTDz1gGAUjDgAAQKPXYA; DEFINE COMMENT 12 eJzrY2BgWCojoPBNpFk9mE/TyJqn2lyMM9j1HY9ViJDA3CgmsQ/x/2QYE4HKGITVvEyE1ZLdctR++Mur awXLqyslg8Q19EvcfYy0gn2MeiMjjPfFgMQydKd6BmgHu4LYlbbbvM+7LPV67hbs+txNwPG2633bQMce Cwv7HotjNvdtc21qIipt10W7OJyP5fE6HwvSkxe0RLMt5LluVuRz3bIoDoPlcedslscpOkXFB7vKRuWE VwXXRCgEW4Xohvzwnxe2zbssapu3Y2yLB0/CVE+QfrecLNGfOf/lfuYYpYD4ohkKioqZjspBuY7KfiVT NEBiSvXV5laN1eZHWgUc5dqCXVlbrvu6NWkF6zVEh12pnxsV3LwumgEcPkyL/8m4LN8rV7ZqoXL97hCV RwePqbmemKjJc/WVZtytAO2F90DqlBX8bh5TMz1+Sd30uLYG85FG/ZsbGvVXrO01aF8Nkr9v53pinoPK sT63mxs2eULEMp2Zj9x2TTsVGnD7E0eg3o+8IP9fuwN5voHk4iKYFh+OnL6GIT5vl2Qi8xHVJJGj4LDJ UF5qm6Jy7Eny78s3kg49OJMY9qooUeQZSM6o8uKB6VW+O5ZU++5Qqv+16W1j6Aqh1k8Lj7SunyvX9nAB SI1d1adDYTWuJx425N92a4K4nWvywwVz5q+f+22+8lK5OdPX/JqxYZ/19E+H8qfcurhkYv0d7bn5t0Hq Hk47uH/tzIP7GUbBsAEAHIzZpA; DEFINE LABEL 0 eJyTYGBguGw7RaPV7prOdwdL40jPuVE8XsuyEwOVWn6E1c3KirTZfid6wz7TGJGjs2PLT8+OfX3pTOLG +0BtDItTPYUFIp/7GfrGlDN4tnU1uX5aeN7l5oZAx/LT8xxsb1TaznzHMApGwSgY1AAA57MqIg; DEFINE LABEL 1 eJzjY2BgmOewRHOTZ4n7dR+rkMRAxsQ3oVolWZHraw5HPqgHSjMoZi7RTEr3MlmfluzGEmGybGnY//8M SMDGoq9qkeXynlCrBXsTrQ/uZ7d2PeFhGXbSxqL9DLfJzvPbdHaef6U542yNQvlpkPpnUuWnA7TTToHY p73nWhr6CjhahkoGfYktyehOlip+kuxdBpILynVyCcpd6nUl80be7vR51UnpqR22KUyLVZOmr2GIf3SQ IV7m2p3oSw8ZRsEoGAVkAwDyNknc; DEFINE LABEL 2 eJxTYGBguGb2XPexOYfBOisJw9uuSzTPJDoqn0lcosmT8F3vRYyXiWWoZNAf/w/x131u5J13MW5ldrrR b2FvM03ERnjJIsv21e8tfm1SMcvbpWK2YV+n+adD7Namx2VcTI9Hen46NCn00cGsyP49mtH9e2bH2mwH Wsdw2Nm77EdYTHlR4vFcBhxAIXjB3htJ/XtA7N2B3mWSid5luNSOglEwCsgHAClSPn4;
; A258812: a(n) = n^11 - 1. ; 0,2047,177146,4194303,48828124,362797055,1977326742,8589934591,31381059608,99999999999,285311670610,743008370687,1792160394036,4049565169663,8649755859374,17592186044415,34271896307632,64268410079231,116490258898218,204799999999999 add $0,1 mov $1,$0 pow $1,11 sub $1,1
.global s_prepare_buffers s_prepare_buffers: push %r11 push %r13 push %r14 push %r15 push %r8 push %rbx push %rdi lea addresses_WC_ht+0x10ae7, %r14 nop and $31404, %r11 mov (%r14), %ebx nop nop sub %rdi, %rdi lea addresses_UC_ht+0x10a67, %r8 nop nop nop nop nop sub %rdi, %rdi mov (%r8), %r13 cmp %r11, %r11 lea addresses_UC_ht+0x1e67, %r8 nop cmp $45691, %r15 vmovups (%r8), %ymm0 vextracti128 $1, %ymm0, %xmm0 vpextrq $1, %xmm0, %rbx nop nop nop nop nop and %rbx, %rbx pop %rdi pop %rbx pop %r8 pop %r15 pop %r14 pop %r13 pop %r11 ret .global s_faulty_load s_faulty_load: push %r15 push %r8 push %rax push %rcx push %rdi push %rdx push %rsi // Store lea addresses_WC+0x1fe67, %rdi nop cmp %rdx, %rdx mov $0x5152535455565758, %rsi movq %rsi, (%rdi) nop nop nop add $60701, %rax // REPMOV lea addresses_US+0x689f, %rsi lea addresses_RW+0xbe67, %rdi nop cmp $20106, %rdx mov $24, %rcx rep movsb nop and $45274, %rsi // Faulty Load lea addresses_WT+0xe667, %rdx nop nop nop sub $32678, %r15 mov (%rdx), %eax lea oracles, %rdx and $0xff, %rax shlq $12, %rax mov (%rdx,%rax,1), %rax pop %rsi pop %rdx pop %rdi pop %rcx pop %rax pop %r8 pop %r15 ret /* <gen_faulty_load> [REF] {'src': {'type': 'addresses_WT', 'same': False, 'size': 1, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'dst': {'type': 'addresses_WC', 'same': False, 'size': 8, 'congruent': 11, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_US', 'congruent': 3, 'same': False}, 'dst': {'type': 'addresses_RW', 'congruent': 11, 'same': False}, 'OP': 'REPM'} [Faulty Load] {'src': {'type': 'addresses_WT', 'same': True, 'size': 4, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'type': 'addresses_WC_ht', 'same': False, 'size': 4, 'congruent': 7, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_UC_ht', 'same': False, 'size': 8, 'congruent': 10, 'NT': True, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_UC_ht', 'same': False, 'size': 32, 'congruent': 8, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'39': 21829} 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 */
;************************************************************************** ; 485E.ASM ; ; High Speed Auto Enable, Auto Baud detect converter ; ; Version Info ; ------------- ; Version 1.3 ; Changed from counting loop to Timer0 based timing ; ; Version 1.4 ; Added watchdog timeout support and commented some code. ; ; Version 1.5 ; Removed RS232_SLOW algorithm to removed power up deadlock. ; ;-------------------------------------------------------------------------- ; ; Author ; ------ ; Anthony A. Kempka ; ;************************************************************************** LIST P=12C508A, R=DEC #include "p12c508.inc" ; ; Use the following config settings __CONFIG _CP_ON & _WDT_ON & _MCLRE_OFF & _IntRC_OSC ; ; Handy bit defines ; TX_EN_Bit EQU 0x00 RS232_Bit EQU 0x01 RTS_Bit EQU 0x02 RS485_Bit EQU 0x03 CTS_Bit EQU 0x04 LED_Bit EQU 0x05 TRIS_LED_OFF EQU 0x2E TRIS_LED_ON EQU 0x0E ;-------------------------------------------------------------------------- ; Set ScratchPadRam here. ;-------------------------------------------------------------------------- ScratchPadRam EQU 0x08 ;-------------------------------------------------------------------------- ; Variables ;-------------------------------------------------------------------------- Timeout EQU ScratchPadRam+0 Timeout_X10 EQU ScratchPadRam+1 Timeout_485 EQU ScratchPadRam+2 Count EQU ScratchPadRam+3 ;-------------------------------------------------------------------------- ; Program Code ;-------------------------------------------------------------------------- ;-------------------------------------------------------------------------- ; Main Program ;-------------------------------------------------------------------------- ORG 0 Start MOVWF OSCCAL ; Load the oscillator calibration CLRF GPIO ; Clear the I/O outputs MOVLW TRIS_LED_OFF ; Configure I/O TRIS GPIO ; Load the TRIS BSF GPIO, CTS_Bit ; Make sure CTS inactive! MOVLW 0xC2 ; Option register prescale 1:8 OPTION ; load into option register ; ; Start with the FAST prescale 9600-115200 since this is the most common. ; Use the timeout for 9600 BPS since it is the slowest. ; MOVLW 0x82 ; Starting timeout 130 count, 9600 BPS MOVWF Timeout_X10 MOVLW 0x0D ; bit time timeout 13 MOVWF Timeout Data_In_Loop CLRWDT ; Kick the dog BTFSS GPIO, RS232_Bit ; Check RS232 active (0) CALL RS232_TMT BTFSS GPIO, RS485_Bit ; Check RS485 active (0) CALL RS485_RCV BTFSS GPIO, RTS_Bit ; Check for RTS active (0) BCF GPIO, CTS_Bit ; CTS Active GOTO Data_In_Loop ; Repeat the whole thing ;-------------------------------------------------------------------------- ; ; Handles the RS-485 receive (RS-232 transmit to PC) ; RS485_RCV BSF GPIO, CTS_Bit ; Make sure CTS inactive! MOVLW TRIS_LED_ON ; LED ON state TRIS GPIO BSF GPIO, LED_Bit ; LED Green RS485_RCV_START MOVLW 0xFF ; Set the timeout MOVWF Timeout_485 RS485_RCV_LOOP CLRWDT ; Kick the dog BTFSS GPIO, RS232_Bit ; Check RS232 active (0) GOTO RS485_RCV_TMT BTFSS GPIO, RS485_Bit ; Check RS485 active (0) GOTO RS485_RCV_START DECFSZ Timeout_485, F ; Do timeout decrement GOTO RS485_RCV_LOOP GOTO RS485_RCV_END RS485_RCV_TMT CALL RS232_TMT RS485_RCV_END MOVLW TRIS_LED_OFF ; LED OFF state TRIS GPIO RETLW 0 ;-------------------------------------------------------------------------- ; ; Handles the RS-232 (HOST PC) transmitinng ; ; When this routine is entered, we are seeing the START bit of ; the first byte being sent. ; RS232_TMT CLRF TMR0 ; Clear the TIMER0 count BSF GPIO, TX_EN_Bit ; Enable RS485 transmit BCF GPIO, CTS_Bit ; CTS Active MOVLW TRIS_LED_ON ; LED ON state TRIS GPIO BCF GPIO, LED_Bit ; LED Red INCF Timeout, F ; Increase Timeout every once in a while ; ; Check if we are to goto FAST timing loop ; RS232_TMT_ON CLRWDT BTFSS GPIO, RS232_Bit ; Check RS232 inactive (1) GOTO RS232_TMT_ON RS232_TMT_1 ; Check minimum INCF TMR0, W ; Make sure count is at least 1 CLRF TMR0 ; Clear timer 0 for OFF loop MOVWF Count SUBWF Timeout, W ; subtract current from current min. BTFSS STATUS, C GOTO RS232_TMT_OFF ; no carry set (Timeout < W) MOVFW Count ; carry set (Timeout > W) MOVWF Timeout ; Save new timeout RS232_TMT_2 MOVWF Timeout_X10 ; Multiply times 8 INCF Timeout_X10, F RLF Timeout_X10, F RLF Timeout_X10, F RLF Timeout_X10, F RS232_TMT_OFF CLRWDT BTFSS GPIO, RS232_Bit ; Check RS232 active (0) GOTO RS232_TMT_3 MOVFW TMR0 ; check timeout SUBWF Timeout_X10, W BTFSS STATUS, C GOTO RS232_TMT_TIMEOUT GOTO RS232_TMT_OFF RS232_TMT_3 INCF TMR0, W ; make sure count is at least 1 CLRF TMR0 ; clear Timer 0 for ON loop MOVWF Count SUBWF Timeout, W ; subtract current from current min. BTFSS STATUS, C GOTO RS232_TMT_ON ; no carry set (Timeout < W) MOVFW Count ; carry set (Timeout > W) MOVWF Timeout ; Save new timeout RS232_TMT_4 CLRWDT ; Kick the dog MOVWF Timeout_X10 ; Multiply times 8 INCF Timeout_X10, F RLF Timeout_X10, F RLF Timeout_X10, F RLF Timeout_X10, F GOTO RS232_TMT_ON RS232_TMT_TIMEOUT BCF GPIO, TX_EN_Bit ; Disable RS485 transmit MOVLW TRIS_LED_OFF ; LED OFF state TRIS GPIO BSF GPIO, CTS_Bit ; Make sure CTS inactive! RETLW 0 ;---------------------------------------------------------------------------- END ; End of program code ;**************************************************************************** ;****************************************************************************
user/_echo: file format elf64-littleriscv Disassembly of section .text: 0000000000000000 <main>: 0: 7179 addi sp,sp,-48 2: f406 sd ra,40(sp) 4: f022 sd s0,32(sp) 6: ec26 sd s1,24(sp) 8: e84a sd s2,16(sp) a: e44e sd s3,8(sp) c: e052 sd s4,0(sp) e: 1800 addi s0,sp,48 10: 4785 li a5,1 12: 06a7d463 bge a5,a0,7a <main+0x7a> 16: 00858493 addi s1,a1,8 1a: ffe5099b addiw s3,a0,-2 1e: 1982 slli s3,s3,0x20 20: 0209d993 srli s3,s3,0x20 24: 098e slli s3,s3,0x3 26: 05c1 addi a1,a1,16 28: 99ae add s3,s3,a1 2a: 00001a17 auipc s4,0x1 2e: 876a0a13 addi s4,s4,-1930 # 8a0 <l_free+0x12> 32: 0004b903 ld s2,0(s1) 36: 854a mv a0,s2 38: 00000097 auipc ra,0x0 3c: 094080e7 jalr 148(ra) # cc <strlen> 40: 0005061b sext.w a2,a0 44: 85ca mv a1,s2 46: 4505 li a0,1 48: 00000097 auipc ra,0x0 4c: 2ca080e7 jalr 714(ra) # 312 <write> 50: 04a1 addi s1,s1,8 52: 01348a63 beq s1,s3,66 <main+0x66> 56: 4605 li a2,1 58: 85d2 mv a1,s4 5a: 4505 li a0,1 5c: 00000097 auipc ra,0x0 60: 2b6080e7 jalr 694(ra) # 312 <write> 64: b7f9 j 32 <main+0x32> 66: 4605 li a2,1 68: 00001597 auipc a1,0x1 6c: 84058593 addi a1,a1,-1984 # 8a8 <l_free+0x1a> 70: 4505 li a0,1 72: 00000097 auipc ra,0x0 76: 2a0080e7 jalr 672(ra) # 312 <write> 7a: 4501 li a0,0 7c: 00000097 auipc ra,0x0 80: 276080e7 jalr 630(ra) # 2f2 <exit> 0000000000000084 <strcpy>: 84: 1141 addi sp,sp,-16 86: e422 sd s0,8(sp) 88: 0800 addi s0,sp,16 8a: 87aa mv a5,a0 8c: 0585 addi a1,a1,1 8e: 0785 addi a5,a5,1 90: fff5c703 lbu a4,-1(a1) 94: fee78fa3 sb a4,-1(a5) 98: fb75 bnez a4,8c <strcpy+0x8> 9a: 6422 ld s0,8(sp) 9c: 0141 addi sp,sp,16 9e: 8082 ret 00000000000000a0 <strcmp>: a0: 1141 addi sp,sp,-16 a2: e422 sd s0,8(sp) a4: 0800 addi s0,sp,16 a6: 00054783 lbu a5,0(a0) aa: cb91 beqz a5,be <strcmp+0x1e> ac: 0005c703 lbu a4,0(a1) b0: 00f71763 bne a4,a5,be <strcmp+0x1e> b4: 0505 addi a0,a0,1 b6: 0585 addi a1,a1,1 b8: 00054783 lbu a5,0(a0) bc: fbe5 bnez a5,ac <strcmp+0xc> be: 0005c503 lbu a0,0(a1) c2: 40a7853b subw a0,a5,a0 c6: 6422 ld s0,8(sp) c8: 0141 addi sp,sp,16 ca: 8082 ret 00000000000000cc <strlen>: cc: 1141 addi sp,sp,-16 ce: e422 sd s0,8(sp) d0: 0800 addi s0,sp,16 d2: 00054783 lbu a5,0(a0) d6: cf91 beqz a5,f2 <strlen+0x26> d8: 0505 addi a0,a0,1 da: 87aa mv a5,a0 dc: 4685 li a3,1 de: 9e89 subw a3,a3,a0 e0: 00f6853b addw a0,a3,a5 e4: 0785 addi a5,a5,1 e6: fff7c703 lbu a4,-1(a5) ea: fb7d bnez a4,e0 <strlen+0x14> ec: 6422 ld s0,8(sp) ee: 0141 addi sp,sp,16 f0: 8082 ret f2: 4501 li a0,0 f4: bfe5 j ec <strlen+0x20> 00000000000000f6 <memset>: f6: 1141 addi sp,sp,-16 f8: e422 sd s0,8(sp) fa: 0800 addi s0,sp,16 fc: ca19 beqz a2,112 <memset+0x1c> fe: 87aa mv a5,a0 100: 1602 slli a2,a2,0x20 102: 9201 srli a2,a2,0x20 104: 00a60733 add a4,a2,a0 108: 00b78023 sb a1,0(a5) 10c: 0785 addi a5,a5,1 10e: fee79de3 bne a5,a4,108 <memset+0x12> 112: 6422 ld s0,8(sp) 114: 0141 addi sp,sp,16 116: 8082 ret 0000000000000118 <strchr>: 118: 1141 addi sp,sp,-16 11a: e422 sd s0,8(sp) 11c: 0800 addi s0,sp,16 11e: 00054783 lbu a5,0(a0) 122: cb99 beqz a5,138 <strchr+0x20> 124: 00f58763 beq a1,a5,132 <strchr+0x1a> 128: 0505 addi a0,a0,1 12a: 00054783 lbu a5,0(a0) 12e: fbfd bnez a5,124 <strchr+0xc> 130: 4501 li a0,0 132: 6422 ld s0,8(sp) 134: 0141 addi sp,sp,16 136: 8082 ret 138: 4501 li a0,0 13a: bfe5 j 132 <strchr+0x1a> 000000000000013c <gets>: 13c: 711d addi sp,sp,-96 13e: ec86 sd ra,88(sp) 140: e8a2 sd s0,80(sp) 142: e4a6 sd s1,72(sp) 144: e0ca sd s2,64(sp) 146: fc4e sd s3,56(sp) 148: f852 sd s4,48(sp) 14a: f456 sd s5,40(sp) 14c: f05a sd s6,32(sp) 14e: ec5e sd s7,24(sp) 150: 1080 addi s0,sp,96 152: 8baa mv s7,a0 154: 8a2e mv s4,a1 156: 892a mv s2,a0 158: 4481 li s1,0 15a: 4aa9 li s5,10 15c: 4b35 li s6,13 15e: 89a6 mv s3,s1 160: 2485 addiw s1,s1,1 162: 0344d863 bge s1,s4,192 <gets+0x56> 166: 4605 li a2,1 168: faf40593 addi a1,s0,-81 16c: 4501 li a0,0 16e: 00000097 auipc ra,0x0 172: 19c080e7 jalr 412(ra) # 30a <read> 176: 00a05e63 blez a0,192 <gets+0x56> 17a: faf44783 lbu a5,-81(s0) 17e: 00f90023 sb a5,0(s2) 182: 01578763 beq a5,s5,190 <gets+0x54> 186: 0905 addi s2,s2,1 188: fd679be3 bne a5,s6,15e <gets+0x22> 18c: 89a6 mv s3,s1 18e: a011 j 192 <gets+0x56> 190: 89a6 mv s3,s1 192: 99de add s3,s3,s7 194: 00098023 sb zero,0(s3) 198: 855e mv a0,s7 19a: 60e6 ld ra,88(sp) 19c: 6446 ld s0,80(sp) 19e: 64a6 ld s1,72(sp) 1a0: 6906 ld s2,64(sp) 1a2: 79e2 ld s3,56(sp) 1a4: 7a42 ld s4,48(sp) 1a6: 7aa2 ld s5,40(sp) 1a8: 7b02 ld s6,32(sp) 1aa: 6be2 ld s7,24(sp) 1ac: 6125 addi sp,sp,96 1ae: 8082 ret 00000000000001b0 <stat>: 1b0: 1101 addi sp,sp,-32 1b2: ec06 sd ra,24(sp) 1b4: e822 sd s0,16(sp) 1b6: e426 sd s1,8(sp) 1b8: e04a sd s2,0(sp) 1ba: 1000 addi s0,sp,32 1bc: 892e mv s2,a1 1be: 4581 li a1,0 1c0: 00000097 auipc ra,0x0 1c4: 172080e7 jalr 370(ra) # 332 <open> 1c8: 02054563 bltz a0,1f2 <stat+0x42> 1cc: 84aa mv s1,a0 1ce: 85ca mv a1,s2 1d0: 00000097 auipc ra,0x0 1d4: 17a080e7 jalr 378(ra) # 34a <fstat> 1d8: 892a mv s2,a0 1da: 8526 mv a0,s1 1dc: 00000097 auipc ra,0x0 1e0: 13e080e7 jalr 318(ra) # 31a <close> 1e4: 854a mv a0,s2 1e6: 60e2 ld ra,24(sp) 1e8: 6442 ld s0,16(sp) 1ea: 64a2 ld s1,8(sp) 1ec: 6902 ld s2,0(sp) 1ee: 6105 addi sp,sp,32 1f0: 8082 ret 1f2: 597d li s2,-1 1f4: bfc5 j 1e4 <stat+0x34> 00000000000001f6 <atoi>: 1f6: 1141 addi sp,sp,-16 1f8: e422 sd s0,8(sp) 1fa: 0800 addi s0,sp,16 1fc: 00054603 lbu a2,0(a0) 200: fd06079b addiw a5,a2,-48 204: 0ff7f793 zext.b a5,a5 208: 4725 li a4,9 20a: 02f76963 bltu a4,a5,23c <atoi+0x46> 20e: 86aa mv a3,a0 210: 4501 li a0,0 212: 45a5 li a1,9 214: 0685 addi a3,a3,1 216: 0025179b slliw a5,a0,0x2 21a: 9fa9 addw a5,a5,a0 21c: 0017979b slliw a5,a5,0x1 220: 9fb1 addw a5,a5,a2 222: fd07851b addiw a0,a5,-48 226: 0006c603 lbu a2,0(a3) 22a: fd06071b addiw a4,a2,-48 22e: 0ff77713 zext.b a4,a4 232: fee5f1e3 bgeu a1,a4,214 <atoi+0x1e> 236: 6422 ld s0,8(sp) 238: 0141 addi sp,sp,16 23a: 8082 ret 23c: 4501 li a0,0 23e: bfe5 j 236 <atoi+0x40> 0000000000000240 <memmove>: 240: 1141 addi sp,sp,-16 242: e422 sd s0,8(sp) 244: 0800 addi s0,sp,16 246: 02b57463 bgeu a0,a1,26e <memmove+0x2e> 24a: 00c05f63 blez a2,268 <memmove+0x28> 24e: 1602 slli a2,a2,0x20 250: 9201 srli a2,a2,0x20 252: 00c507b3 add a5,a0,a2 256: 872a mv a4,a0 258: 0585 addi a1,a1,1 25a: 0705 addi a4,a4,1 25c: fff5c683 lbu a3,-1(a1) 260: fed70fa3 sb a3,-1(a4) 264: fee79ae3 bne a5,a4,258 <memmove+0x18> 268: 6422 ld s0,8(sp) 26a: 0141 addi sp,sp,16 26c: 8082 ret 26e: 00c50733 add a4,a0,a2 272: 95b2 add a1,a1,a2 274: fec05ae3 blez a2,268 <memmove+0x28> 278: fff6079b addiw a5,a2,-1 27c: 1782 slli a5,a5,0x20 27e: 9381 srli a5,a5,0x20 280: fff7c793 not a5,a5 284: 97ba add a5,a5,a4 286: 15fd addi a1,a1,-1 288: 177d addi a4,a4,-1 28a: 0005c683 lbu a3,0(a1) 28e: 00d70023 sb a3,0(a4) 292: fee79ae3 bne a5,a4,286 <memmove+0x46> 296: bfc9 j 268 <memmove+0x28> 0000000000000298 <memcmp>: 298: 1141 addi sp,sp,-16 29a: e422 sd s0,8(sp) 29c: 0800 addi s0,sp,16 29e: ca05 beqz a2,2ce <memcmp+0x36> 2a0: fff6069b addiw a3,a2,-1 2a4: 1682 slli a3,a3,0x20 2a6: 9281 srli a3,a3,0x20 2a8: 0685 addi a3,a3,1 2aa: 96aa add a3,a3,a0 2ac: 00054783 lbu a5,0(a0) 2b0: 0005c703 lbu a4,0(a1) 2b4: 00e79863 bne a5,a4,2c4 <memcmp+0x2c> 2b8: 0505 addi a0,a0,1 2ba: 0585 addi a1,a1,1 2bc: fed518e3 bne a0,a3,2ac <memcmp+0x14> 2c0: 4501 li a0,0 2c2: a019 j 2c8 <memcmp+0x30> 2c4: 40e7853b subw a0,a5,a4 2c8: 6422 ld s0,8(sp) 2ca: 0141 addi sp,sp,16 2cc: 8082 ret 2ce: 4501 li a0,0 2d0: bfe5 j 2c8 <memcmp+0x30> 00000000000002d2 <memcpy>: 2d2: 1141 addi sp,sp,-16 2d4: e406 sd ra,8(sp) 2d6: e022 sd s0,0(sp) 2d8: 0800 addi s0,sp,16 2da: 00000097 auipc ra,0x0 2de: f66080e7 jalr -154(ra) # 240 <memmove> 2e2: 60a2 ld ra,8(sp) 2e4: 6402 ld s0,0(sp) 2e6: 0141 addi sp,sp,16 2e8: 8082 ret 00000000000002ea <fork>: 2ea: 4885 li a7,1 2ec: 00000073 ecall 2f0: 8082 ret 00000000000002f2 <exit>: 2f2: 4889 li a7,2 2f4: 00000073 ecall 2f8: 8082 ret 00000000000002fa <wait>: 2fa: 488d li a7,3 2fc: 00000073 ecall 300: 8082 ret 0000000000000302 <pipe>: 302: 4891 li a7,4 304: 00000073 ecall 308: 8082 ret 000000000000030a <read>: 30a: 4895 li a7,5 30c: 00000073 ecall 310: 8082 ret 0000000000000312 <write>: 312: 48c1 li a7,16 314: 00000073 ecall 318: 8082 ret 000000000000031a <close>: 31a: 48d5 li a7,21 31c: 00000073 ecall 320: 8082 ret 0000000000000322 <kill>: 322: 4899 li a7,6 324: 00000073 ecall 328: 8082 ret 000000000000032a <exec>: 32a: 489d li a7,7 32c: 00000073 ecall 330: 8082 ret 0000000000000332 <open>: 332: 48bd li a7,15 334: 00000073 ecall 338: 8082 ret 000000000000033a <mknod>: 33a: 48c5 li a7,17 33c: 00000073 ecall 340: 8082 ret 0000000000000342 <unlink>: 342: 48c9 li a7,18 344: 00000073 ecall 348: 8082 ret 000000000000034a <fstat>: 34a: 48a1 li a7,8 34c: 00000073 ecall 350: 8082 ret 0000000000000352 <link>: 352: 48cd li a7,19 354: 00000073 ecall 358: 8082 ret 000000000000035a <mkdir>: 35a: 48d1 li a7,20 35c: 00000073 ecall 360: 8082 ret 0000000000000362 <chdir>: 362: 48a5 li a7,9 364: 00000073 ecall 368: 8082 ret 000000000000036a <dup>: 36a: 48a9 li a7,10 36c: 00000073 ecall 370: 8082 ret 0000000000000372 <getpid>: 372: 48ad li a7,11 374: 00000073 ecall 378: 8082 ret 000000000000037a <sbrk>: 37a: 48b1 li a7,12 37c: 00000073 ecall 380: 8082 ret 0000000000000382 <sleep>: 382: 48b5 li a7,13 384: 00000073 ecall 388: 8082 ret 000000000000038a <uptime>: 38a: 48b9 li a7,14 38c: 00000073 ecall 390: 8082 ret 0000000000000392 <putc>: static char digits[] = "0123456789ABCDEF"; static void putc(int fd, char c) { 392: 1101 addi sp,sp,-32 394: ec06 sd ra,24(sp) 396: e822 sd s0,16(sp) 398: 1000 addi s0,sp,32 39a: feb407a3 sb a1,-17(s0) write(fd, &c, 1); 39e: 4605 li a2,1 3a0: fef40593 addi a1,s0,-17 3a4: 00000097 auipc ra,0x0 3a8: f6e080e7 jalr -146(ra) # 312 <write> } 3ac: 60e2 ld ra,24(sp) 3ae: 6442 ld s0,16(sp) 3b0: 6105 addi sp,sp,32 3b2: 8082 ret 00000000000003b4 <printint>: static void printint(int fd, int xx, int base, int sgn) { 3b4: 7139 addi sp,sp,-64 3b6: fc06 sd ra,56(sp) 3b8: f822 sd s0,48(sp) 3ba: f426 sd s1,40(sp) 3bc: f04a sd s2,32(sp) 3be: ec4e sd s3,24(sp) 3c0: 0080 addi s0,sp,64 3c2: 84aa mv s1,a0 char buf[16]; int i, neg; uint x; neg = 0; if(sgn && xx < 0){ 3c4: c299 beqz a3,3ca <printint+0x16> 3c6: 0805c963 bltz a1,458 <printint+0xa4> neg = 1; x = -xx; } else { x = xx; 3ca: 2581 sext.w a1,a1 neg = 0; 3cc: 4881 li a7,0 3ce: fc040693 addi a3,s0,-64 } i = 0; 3d2: 4701 li a4,0 do{ buf[i++] = digits[x % base]; 3d4: 2601 sext.w a2,a2 3d6: 00000517 auipc a0,0x0 3da: 53a50513 addi a0,a0,1338 # 910 <digits> 3de: 883a mv a6,a4 3e0: 2705 addiw a4,a4,1 3e2: 02c5f7bb remuw a5,a1,a2 3e6: 1782 slli a5,a5,0x20 3e8: 9381 srli a5,a5,0x20 3ea: 97aa add a5,a5,a0 3ec: 0007c783 lbu a5,0(a5) 3f0: 00f68023 sb a5,0(a3) }while((x /= base) != 0); 3f4: 0005879b sext.w a5,a1 3f8: 02c5d5bb divuw a1,a1,a2 3fc: 0685 addi a3,a3,1 3fe: fec7f0e3 bgeu a5,a2,3de <printint+0x2a> if(neg) 402: 00088c63 beqz a7,41a <printint+0x66> buf[i++] = '-'; 406: fd070793 addi a5,a4,-48 40a: 00878733 add a4,a5,s0 40e: 02d00793 li a5,45 412: fef70823 sb a5,-16(a4) 416: 0028071b addiw a4,a6,2 while(--i >= 0) 41a: 02e05863 blez a4,44a <printint+0x96> 41e: fc040793 addi a5,s0,-64 422: 00e78933 add s2,a5,a4 426: fff78993 addi s3,a5,-1 42a: 99ba add s3,s3,a4 42c: 377d addiw a4,a4,-1 42e: 1702 slli a4,a4,0x20 430: 9301 srli a4,a4,0x20 432: 40e989b3 sub s3,s3,a4 putc(fd, buf[i]); 436: fff94583 lbu a1,-1(s2) 43a: 8526 mv a0,s1 43c: 00000097 auipc ra,0x0 440: f56080e7 jalr -170(ra) # 392 <putc> while(--i >= 0) 444: 197d addi s2,s2,-1 446: ff3918e3 bne s2,s3,436 <printint+0x82> } 44a: 70e2 ld ra,56(sp) 44c: 7442 ld s0,48(sp) 44e: 74a2 ld s1,40(sp) 450: 7902 ld s2,32(sp) 452: 69e2 ld s3,24(sp) 454: 6121 addi sp,sp,64 456: 8082 ret x = -xx; 458: 40b005bb negw a1,a1 neg = 1; 45c: 4885 li a7,1 x = -xx; 45e: bf85 j 3ce <printint+0x1a> 0000000000000460 <vprintf>: } // Print to the given fd. Only understands %d, %x, %p, %s. void vprintf(int fd, const char *fmt, va_list ap) { 460: 7119 addi sp,sp,-128 462: fc86 sd ra,120(sp) 464: f8a2 sd s0,112(sp) 466: f4a6 sd s1,104(sp) 468: f0ca sd s2,96(sp) 46a: ecce sd s3,88(sp) 46c: e8d2 sd s4,80(sp) 46e: e4d6 sd s5,72(sp) 470: e0da sd s6,64(sp) 472: fc5e sd s7,56(sp) 474: f862 sd s8,48(sp) 476: f466 sd s9,40(sp) 478: f06a sd s10,32(sp) 47a: ec6e sd s11,24(sp) 47c: 0100 addi s0,sp,128 char *s; int c, i, state; state = 0; for(i = 0; fmt[i]; i++){ 47e: 0005c903 lbu s2,0(a1) 482: 18090f63 beqz s2,620 <vprintf+0x1c0> 486: 8aaa mv s5,a0 488: 8b32 mv s6,a2 48a: 00158493 addi s1,a1,1 state = 0; 48e: 4981 li s3,0 if(c == '%'){ state = '%'; } else { putc(fd, c); } } else if(state == '%'){ 490: 02500a13 li s4,37 494: 4c55 li s8,21 496: 00000c97 auipc s9,0x0 49a: 422c8c93 addi s9,s9,1058 # 8b8 <l_free+0x2a> printptr(fd, va_arg(ap, uint64)); } else if(c == 's'){ s = va_arg(ap, char*); if(s == 0) s = "(null)"; while(*s != 0){ 49e: 02800d93 li s11,40 putc(fd, 'x'); 4a2: 4d41 li s10,16 putc(fd, digits[x >> (sizeof(uint64) * 8 - 4)]); 4a4: 00000b97 auipc s7,0x0 4a8: 46cb8b93 addi s7,s7,1132 # 910 <digits> 4ac: a839 j 4ca <vprintf+0x6a> putc(fd, c); 4ae: 85ca mv a1,s2 4b0: 8556 mv a0,s5 4b2: 00000097 auipc ra,0x0 4b6: ee0080e7 jalr -288(ra) # 392 <putc> 4ba: a019 j 4c0 <vprintf+0x60> } else if(state == '%'){ 4bc: 01498d63 beq s3,s4,4d6 <vprintf+0x76> for(i = 0; fmt[i]; i++){ 4c0: 0485 addi s1,s1,1 4c2: fff4c903 lbu s2,-1(s1) 4c6: 14090d63 beqz s2,620 <vprintf+0x1c0> if(state == 0){ 4ca: fe0999e3 bnez s3,4bc <vprintf+0x5c> if(c == '%'){ 4ce: ff4910e3 bne s2,s4,4ae <vprintf+0x4e> state = '%'; 4d2: 89d2 mv s3,s4 4d4: b7f5 j 4c0 <vprintf+0x60> if(c == 'd'){ 4d6: 11490c63 beq s2,s4,5ee <vprintf+0x18e> 4da: f9d9079b addiw a5,s2,-99 4de: 0ff7f793 zext.b a5,a5 4e2: 10fc6e63 bltu s8,a5,5fe <vprintf+0x19e> 4e6: f9d9079b addiw a5,s2,-99 4ea: 0ff7f713 zext.b a4,a5 4ee: 10ec6863 bltu s8,a4,5fe <vprintf+0x19e> 4f2: 00271793 slli a5,a4,0x2 4f6: 97e6 add a5,a5,s9 4f8: 439c lw a5,0(a5) 4fa: 97e6 add a5,a5,s9 4fc: 8782 jr a5 printint(fd, va_arg(ap, int), 10, 1); 4fe: 008b0913 addi s2,s6,8 502: 4685 li a3,1 504: 4629 li a2,10 506: 000b2583 lw a1,0(s6) 50a: 8556 mv a0,s5 50c: 00000097 auipc ra,0x0 510: ea8080e7 jalr -344(ra) # 3b4 <printint> 514: 8b4a mv s6,s2 } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 516: 4981 li s3,0 518: b765 j 4c0 <vprintf+0x60> printint(fd, va_arg(ap, uint64), 10, 0); 51a: 008b0913 addi s2,s6,8 51e: 4681 li a3,0 520: 4629 li a2,10 522: 000b2583 lw a1,0(s6) 526: 8556 mv a0,s5 528: 00000097 auipc ra,0x0 52c: e8c080e7 jalr -372(ra) # 3b4 <printint> 530: 8b4a mv s6,s2 state = 0; 532: 4981 li s3,0 534: b771 j 4c0 <vprintf+0x60> printint(fd, va_arg(ap, int), 16, 0); 536: 008b0913 addi s2,s6,8 53a: 4681 li a3,0 53c: 866a mv a2,s10 53e: 000b2583 lw a1,0(s6) 542: 8556 mv a0,s5 544: 00000097 auipc ra,0x0 548: e70080e7 jalr -400(ra) # 3b4 <printint> 54c: 8b4a mv s6,s2 state = 0; 54e: 4981 li s3,0 550: bf85 j 4c0 <vprintf+0x60> printptr(fd, va_arg(ap, uint64)); 552: 008b0793 addi a5,s6,8 556: f8f43423 sd a5,-120(s0) 55a: 000b3983 ld s3,0(s6) putc(fd, '0'); 55e: 03000593 li a1,48 562: 8556 mv a0,s5 564: 00000097 auipc ra,0x0 568: e2e080e7 jalr -466(ra) # 392 <putc> putc(fd, 'x'); 56c: 07800593 li a1,120 570: 8556 mv a0,s5 572: 00000097 auipc ra,0x0 576: e20080e7 jalr -480(ra) # 392 <putc> 57a: 896a mv s2,s10 putc(fd, digits[x >> (sizeof(uint64) * 8 - 4)]); 57c: 03c9d793 srli a5,s3,0x3c 580: 97de add a5,a5,s7 582: 0007c583 lbu a1,0(a5) 586: 8556 mv a0,s5 588: 00000097 auipc ra,0x0 58c: e0a080e7 jalr -502(ra) # 392 <putc> for (i = 0; i < (sizeof(uint64) * 2); i++, x <<= 4) 590: 0992 slli s3,s3,0x4 592: 397d addiw s2,s2,-1 594: fe0914e3 bnez s2,57c <vprintf+0x11c> printptr(fd, va_arg(ap, uint64)); 598: f8843b03 ld s6,-120(s0) state = 0; 59c: 4981 li s3,0 59e: b70d j 4c0 <vprintf+0x60> s = va_arg(ap, char*); 5a0: 008b0913 addi s2,s6,8 5a4: 000b3983 ld s3,0(s6) if(s == 0) 5a8: 02098163 beqz s3,5ca <vprintf+0x16a> while(*s != 0){ 5ac: 0009c583 lbu a1,0(s3) 5b0: c5ad beqz a1,61a <vprintf+0x1ba> putc(fd, *s); 5b2: 8556 mv a0,s5 5b4: 00000097 auipc ra,0x0 5b8: dde080e7 jalr -546(ra) # 392 <putc> s++; 5bc: 0985 addi s3,s3,1 while(*s != 0){ 5be: 0009c583 lbu a1,0(s3) 5c2: f9e5 bnez a1,5b2 <vprintf+0x152> s = va_arg(ap, char*); 5c4: 8b4a mv s6,s2 state = 0; 5c6: 4981 li s3,0 5c8: bde5 j 4c0 <vprintf+0x60> s = "(null)"; 5ca: 00000997 auipc s3,0x0 5ce: 2e698993 addi s3,s3,742 # 8b0 <l_free+0x22> while(*s != 0){ 5d2: 85ee mv a1,s11 5d4: bff9 j 5b2 <vprintf+0x152> putc(fd, va_arg(ap, uint)); 5d6: 008b0913 addi s2,s6,8 5da: 000b4583 lbu a1,0(s6) 5de: 8556 mv a0,s5 5e0: 00000097 auipc ra,0x0 5e4: db2080e7 jalr -590(ra) # 392 <putc> 5e8: 8b4a mv s6,s2 state = 0; 5ea: 4981 li s3,0 5ec: bdd1 j 4c0 <vprintf+0x60> putc(fd, c); 5ee: 85d2 mv a1,s4 5f0: 8556 mv a0,s5 5f2: 00000097 auipc ra,0x0 5f6: da0080e7 jalr -608(ra) # 392 <putc> state = 0; 5fa: 4981 li s3,0 5fc: b5d1 j 4c0 <vprintf+0x60> putc(fd, '%'); 5fe: 85d2 mv a1,s4 600: 8556 mv a0,s5 602: 00000097 auipc ra,0x0 606: d90080e7 jalr -624(ra) # 392 <putc> putc(fd, c); 60a: 85ca mv a1,s2 60c: 8556 mv a0,s5 60e: 00000097 auipc ra,0x0 612: d84080e7 jalr -636(ra) # 392 <putc> state = 0; 616: 4981 li s3,0 618: b565 j 4c0 <vprintf+0x60> s = va_arg(ap, char*); 61a: 8b4a mv s6,s2 state = 0; 61c: 4981 li s3,0 61e: b54d j 4c0 <vprintf+0x60> } } } 620: 70e6 ld ra,120(sp) 622: 7446 ld s0,112(sp) 624: 74a6 ld s1,104(sp) 626: 7906 ld s2,96(sp) 628: 69e6 ld s3,88(sp) 62a: 6a46 ld s4,80(sp) 62c: 6aa6 ld s5,72(sp) 62e: 6b06 ld s6,64(sp) 630: 7be2 ld s7,56(sp) 632: 7c42 ld s8,48(sp) 634: 7ca2 ld s9,40(sp) 636: 7d02 ld s10,32(sp) 638: 6de2 ld s11,24(sp) 63a: 6109 addi sp,sp,128 63c: 8082 ret 000000000000063e <fprintf>: void fprintf(int fd, const char *fmt, ...) { 63e: 715d addi sp,sp,-80 640: ec06 sd ra,24(sp) 642: e822 sd s0,16(sp) 644: 1000 addi s0,sp,32 646: e010 sd a2,0(s0) 648: e414 sd a3,8(s0) 64a: e818 sd a4,16(s0) 64c: ec1c sd a5,24(s0) 64e: 03043023 sd a6,32(s0) 652: 03143423 sd a7,40(s0) va_list ap; va_start(ap, fmt); 656: fe843423 sd s0,-24(s0) vprintf(fd, fmt, ap); 65a: 8622 mv a2,s0 65c: 00000097 auipc ra,0x0 660: e04080e7 jalr -508(ra) # 460 <vprintf> } 664: 60e2 ld ra,24(sp) 666: 6442 ld s0,16(sp) 668: 6161 addi sp,sp,80 66a: 8082 ret 000000000000066c <printf>: void printf(const char *fmt, ...) { 66c: 711d addi sp,sp,-96 66e: ec06 sd ra,24(sp) 670: e822 sd s0,16(sp) 672: 1000 addi s0,sp,32 674: e40c sd a1,8(s0) 676: e810 sd a2,16(s0) 678: ec14 sd a3,24(s0) 67a: f018 sd a4,32(s0) 67c: f41c sd a5,40(s0) 67e: 03043823 sd a6,48(s0) 682: 03143c23 sd a7,56(s0) va_list ap; va_start(ap, fmt); 686: 00840613 addi a2,s0,8 68a: fec43423 sd a2,-24(s0) vprintf(1, fmt, ap); 68e: 85aa mv a1,a0 690: 4505 li a0,1 692: 00000097 auipc ra,0x0 696: dce080e7 jalr -562(ra) # 460 <vprintf> } 69a: 60e2 ld ra,24(sp) 69c: 6442 ld s0,16(sp) 69e: 6125 addi sp,sp,96 6a0: 8082 ret 00000000000006a2 <free>: 6a2: 1141 addi sp,sp,-16 6a4: e422 sd s0,8(sp) 6a6: 0800 addi s0,sp,16 6a8: ff050693 addi a3,a0,-16 6ac: 00000797 auipc a5,0x0 6b0: 28c7b783 ld a5,652(a5) # 938 <freep> 6b4: a805 j 6e4 <free+0x42> 6b6: 4618 lw a4,8(a2) 6b8: 9db9 addw a1,a1,a4 6ba: feb52c23 sw a1,-8(a0) 6be: 6398 ld a4,0(a5) 6c0: 6318 ld a4,0(a4) 6c2: fee53823 sd a4,-16(a0) 6c6: a091 j 70a <free+0x68> 6c8: ff852703 lw a4,-8(a0) 6cc: 9e39 addw a2,a2,a4 6ce: c790 sw a2,8(a5) 6d0: ff053703 ld a4,-16(a0) 6d4: e398 sd a4,0(a5) 6d6: a099 j 71c <free+0x7a> 6d8: 6398 ld a4,0(a5) 6da: 00e7e463 bltu a5,a4,6e2 <free+0x40> 6de: 00e6ea63 bltu a3,a4,6f2 <free+0x50> 6e2: 87ba mv a5,a4 6e4: fed7fae3 bgeu a5,a3,6d8 <free+0x36> 6e8: 6398 ld a4,0(a5) 6ea: 00e6e463 bltu a3,a4,6f2 <free+0x50> 6ee: fee7eae3 bltu a5,a4,6e2 <free+0x40> 6f2: ff852583 lw a1,-8(a0) 6f6: 6390 ld a2,0(a5) 6f8: 02059713 slli a4,a1,0x20 6fc: 9301 srli a4,a4,0x20 6fe: 0712 slli a4,a4,0x4 700: 9736 add a4,a4,a3 702: fae60ae3 beq a2,a4,6b6 <free+0x14> 706: fec53823 sd a2,-16(a0) 70a: 4790 lw a2,8(a5) 70c: 02061713 slli a4,a2,0x20 710: 9301 srli a4,a4,0x20 712: 0712 slli a4,a4,0x4 714: 973e add a4,a4,a5 716: fae689e3 beq a3,a4,6c8 <free+0x26> 71a: e394 sd a3,0(a5) 71c: 00000717 auipc a4,0x0 720: 20f73e23 sd a5,540(a4) # 938 <freep> 724: 6422 ld s0,8(sp) 726: 0141 addi sp,sp,16 728: 8082 ret 000000000000072a <malloc>: 72a: 7139 addi sp,sp,-64 72c: fc06 sd ra,56(sp) 72e: f822 sd s0,48(sp) 730: f426 sd s1,40(sp) 732: f04a sd s2,32(sp) 734: ec4e sd s3,24(sp) 736: e852 sd s4,16(sp) 738: e456 sd s5,8(sp) 73a: e05a sd s6,0(sp) 73c: 0080 addi s0,sp,64 73e: 02051493 slli s1,a0,0x20 742: 9081 srli s1,s1,0x20 744: 04bd addi s1,s1,15 746: 8091 srli s1,s1,0x4 748: 0014899b addiw s3,s1,1 74c: 0485 addi s1,s1,1 74e: 00000517 auipc a0,0x0 752: 1ea53503 ld a0,490(a0) # 938 <freep> 756: c515 beqz a0,782 <malloc+0x58> 758: 611c ld a5,0(a0) 75a: 4798 lw a4,8(a5) 75c: 02977f63 bgeu a4,s1,79a <malloc+0x70> 760: 8a4e mv s4,s3 762: 0009871b sext.w a4,s3 766: 6685 lui a3,0x1 768: 00d77363 bgeu a4,a3,76e <malloc+0x44> 76c: 6a05 lui s4,0x1 76e: 000a0b1b sext.w s6,s4 772: 004a1a1b slliw s4,s4,0x4 776: 00000917 auipc s2,0x0 77a: 1c290913 addi s2,s2,450 # 938 <freep> 77e: 5afd li s5,-1 780: a88d j 7f2 <malloc+0xc8> 782: 00000797 auipc a5,0x0 786: 1be78793 addi a5,a5,446 # 940 <base> 78a: 00000717 auipc a4,0x0 78e: 1af73723 sd a5,430(a4) # 938 <freep> 792: e39c sd a5,0(a5) 794: 0007a423 sw zero,8(a5) 798: b7e1 j 760 <malloc+0x36> 79a: 02e48b63 beq s1,a4,7d0 <malloc+0xa6> 79e: 4137073b subw a4,a4,s3 7a2: c798 sw a4,8(a5) 7a4: 1702 slli a4,a4,0x20 7a6: 9301 srli a4,a4,0x20 7a8: 0712 slli a4,a4,0x4 7aa: 97ba add a5,a5,a4 7ac: 0137a423 sw s3,8(a5) 7b0: 00000717 auipc a4,0x0 7b4: 18a73423 sd a0,392(a4) # 938 <freep> 7b8: 01078513 addi a0,a5,16 7bc: 70e2 ld ra,56(sp) 7be: 7442 ld s0,48(sp) 7c0: 74a2 ld s1,40(sp) 7c2: 7902 ld s2,32(sp) 7c4: 69e2 ld s3,24(sp) 7c6: 6a42 ld s4,16(sp) 7c8: 6aa2 ld s5,8(sp) 7ca: 6b02 ld s6,0(sp) 7cc: 6121 addi sp,sp,64 7ce: 8082 ret 7d0: 6398 ld a4,0(a5) 7d2: e118 sd a4,0(a0) 7d4: bff1 j 7b0 <malloc+0x86> 7d6: 01652423 sw s6,8(a0) 7da: 0541 addi a0,a0,16 7dc: 00000097 auipc ra,0x0 7e0: ec6080e7 jalr -314(ra) # 6a2 <free> 7e4: 00093503 ld a0,0(s2) 7e8: d971 beqz a0,7bc <malloc+0x92> 7ea: 611c ld a5,0(a0) 7ec: 4798 lw a4,8(a5) 7ee: fa9776e3 bgeu a4,s1,79a <malloc+0x70> 7f2: 00093703 ld a4,0(s2) 7f6: 853e mv a0,a5 7f8: fef719e3 bne a4,a5,7ea <malloc+0xc0> 7fc: 8552 mv a0,s4 7fe: 00000097 auipc ra,0x0 802: b7c080e7 jalr -1156(ra) # 37a <sbrk> 806: fd5518e3 bne a0,s5,7d6 <malloc+0xac> 80a: 4501 li a0,0 80c: bf45 j 7bc <malloc+0x92> 000000000000080e <mem_init>: 80e: 1141 addi sp,sp,-16 810: e406 sd ra,8(sp) 812: e022 sd s0,0(sp) 814: 0800 addi s0,sp,16 816: 6505 lui a0,0x1 818: 00000097 auipc ra,0x0 81c: b62080e7 jalr -1182(ra) # 37a <sbrk> 820: 00000797 auipc a5,0x0 824: 10a7b823 sd a0,272(a5) # 930 <alloc> 828: 00850793 addi a5,a0,8 # 1008 <__BSS_END__+0x6b8> 82c: e11c sd a5,0(a0) 82e: 60a2 ld ra,8(sp) 830: 6402 ld s0,0(sp) 832: 0141 addi sp,sp,16 834: 8082 ret 0000000000000836 <l_alloc>: 836: 1101 addi sp,sp,-32 838: ec06 sd ra,24(sp) 83a: e822 sd s0,16(sp) 83c: e426 sd s1,8(sp) 83e: 1000 addi s0,sp,32 840: 84aa mv s1,a0 842: 00000797 auipc a5,0x0 846: 0e67a783 lw a5,230(a5) # 928 <if_init> 84a: c795 beqz a5,876 <l_alloc+0x40> 84c: 00000717 auipc a4,0x0 850: 0e473703 ld a4,228(a4) # 930 <alloc> 854: 6308 ld a0,0(a4) 856: 40e506b3 sub a3,a0,a4 85a: 6785 lui a5,0x1 85c: 37e1 addiw a5,a5,-8 85e: 9f95 subw a5,a5,a3 860: 02f4f563 bgeu s1,a5,88a <l_alloc+0x54> 864: 1482 slli s1,s1,0x20 866: 9081 srli s1,s1,0x20 868: 94aa add s1,s1,a0 86a: e304 sd s1,0(a4) 86c: 60e2 ld ra,24(sp) 86e: 6442 ld s0,16(sp) 870: 64a2 ld s1,8(sp) 872: 6105 addi sp,sp,32 874: 8082 ret 876: 00000097 auipc ra,0x0 87a: f98080e7 jalr -104(ra) # 80e <mem_init> 87e: 4785 li a5,1 880: 00000717 auipc a4,0x0 884: 0af72423 sw a5,168(a4) # 928 <if_init> 888: b7d1 j 84c <l_alloc+0x16> 88a: 4501 li a0,0 88c: b7c5 j 86c <l_alloc+0x36> 000000000000088e <l_free>: 88e: 1141 addi sp,sp,-16 890: e422 sd s0,8(sp) 892: 0800 addi s0,sp,16 894: 6422 ld s0,8(sp) 896: 0141 addi sp,sp,16 898: 8082 ret
; A300523: a(n) = (5*n + 5)*(5*n + 6)*(5*n + 7)/6. ; 35,220,680,1540,2925,4960,7770,11480,16215,22100,29260,37820,47905,59640,73150,88560,105995,125580,147440,171700,198485,227920,260130,295240,333375,374660,419220,467180,518665,573800,632710,695520,762355,833340,908600,988260,1072445,1161280,1254890,1353400,1456935,1565620,1679580,1798940,1923825,2054360,2190670,2332880,2481115,2635500,2796160,2963220,3136805,3317040,3504050,3697960,3898895,4106980,4322340,4545100,4775385,5013320,5259030,5512640,5774275,6044060,6322120,6608580,6903565,7207200,7519610,7840920,8171255,8510740,8859500,9217660,9585345,9962680,10349790,10746800,11153835,11571020,11998480,12436340,12884725,13343760,13813570,14294280,14786015,15288900,15803060,16328620,16865705,17414440,17974950,18547360,19131795,19728380,20337240,20958500,21592285,22238720,22897930,23570040,24255175,24953460,25665020,26389980,27128465,27880600,28646510,29426320,30220155,31028140,31850400,32687060,33538245,34404080,35284690,36180200,37090735,38016420,38957380,39913740,40885625,41873160,42876470,43895680,44930915,45982300,47049960,48134020,49234605,50351840,51485850,52636760,53804695,54989780,56192140,57411900,58649185,59904120,61176830,62467440,63776075,65102860,66447920,67811380,69193365,70594000,72013410,73451720,74909055,76385540,77881300,79396460,80931145,82485480,84059590,85653600,87267635,88901820,90556280,92231140,93926525,95642560,97379370,99137080,100915815,102715700,104536860,106379420,108243505,110129240,112036750,113966160,115917595,117891180,119887040,121905300,123946085,126009520,128095730,130204840,132336975,134492260,136670820,138872780,141098265,143347400,145620310,147917120,150237955,152582940,154952200,157345860,159764045,162206880,164674490,167167000,169684535,172227220,174795180,177388540,180007425,182651960,185322270,188018480,190740715,193489100,196263760,199064820,201892405,204746640,207627650,210535560,213470495,216432580,219421940,222438700,225482985,228554920,231654630,234782240,237937875,241121660,244333720,247574180,250843165,254140800,257467210,260822520,264206855,267620340,271063100,274535260,278036945,281568280,285129390,288720400,292341435,295992620,299674080,303385940,307128325,310901360,314705170,318539880,322405615,326302500 mul $0,5 add $0,7 bin $0,3 mov $1,$0
// Commodore 64 PRG executable file .file [name="iterarray.prg", type="prg", segments="Program"] .segmentdef Program [segments="Basic, Code, Data"] .segmentdef Basic [start=$0801] .segmentdef Code [start=$80d] .segmentdef Data [startAfter="Code"] .segment Basic :BasicUpstart(main) .segment Code main: { .label buf = $1100 ldx #5 __b1: // 2+i+2 txa clc adc #2+2 // buf[i] = 2+i+2 sta buf,x // i = i+1 inx // while(i<10) cpx #$a bcc __b1 // } rts }
#pragma once #include <ion/gfx/pixel_format.hpp> #include <ion/gfx/type.hpp> #include <ostream> #include <vector> namespace ion { namespace gfx { class Image { public: Image(const std::string&); const std::string& name() const; unsigned int width() const; unsigned int height() const; unsigned int channels() const; Format format() const; Type type() const; const std::vector<unsigned char> pixels() const; private: void load(); private: std::string _name; unsigned int _width, _height, _channels; std::vector<unsigned char> _data; }; }}
; Various sub-routines that will be useful to the boot loader code ; Output Carriage-Return/Line-Feed (CRLF) sequence to screen using BIOS Console_Write_CRLF: mov ah, 0Eh ; Output CR mov al, 0Dh int 10h mov al, 0Ah ; Output LF int 10h ret ; Write to the console using BIOS. ; ; Input: SI points to a null-terminated string Console_Write_16: mov ah, 0Eh ; BIOS call to output value in AL to screen Console_Write_16_Repeat: lodsb ; Load byte at SI into AL and increment SI test al, al ; If the byte is 0, we are done je Console_Write_16_Done int 10h ; Output character to screen jmp Console_Write_16_Repeat Console_Write_16_Done: ret ; Write string to the console using BIOS followed by CRLF ; ; Input: SI points to a null-terminated string Console_WriteLine_16: call Console_Write_16 call Console_Write_CRLF ret ; Output the value within bx as an unsigned integer value ; ; Input: BX points to the unsigned value to be displayed Console_Write_Integer: mov si, IntBuffer + 4 ; SI points to the location in memory we will store digits mov ax, bx ; Move the value to be stored into the AX register, as this is what operations are performed on GetDigit: xor dx, dx ; Clear dx register mov cx, 10 ; We will be dividing by 10, so store it in the cx register div cx ; Divide by cx register (10) add dl, 48 ; Add to the remained 48 (so we can get the ascii character) mov [si], dl ; Move to the location mentioned in SI the value within dl dec si ; Go to one value lower in memory, to store the next most significant bit cmp ax, 0 ; If we have no more bits to divide then move on jne GetDigit inc si ; Go back up a bit in SI since we would be 1 lower than the actual start otherwise call Console_Write_16 ret IntBuffer db ' ', 0 ; Write a the value within bx as 4 hex values ; ; Input: BX points to the value to be displayed Console_Write_Hex: push cx push ax push si push bx mov cx, 4 ; 4 Hex values to be output - counter HexLoop: rol bx, 4 ; Rotate the register right (values pushed out and put onto the left) mov si, bx ; Place the value we are editing into si and si, 000fh ; Run mask to get least significant hex mov al, byte[si + HexChars] ; Get the ascii char that represents this hex mov ah, 0Eh ; Bios call to output the value in AL to the screen int 10h ; Interupt dec cx ; Decrease the value in cx by 1 jnz HexLoop ; If not Zero, jump back to the start of the loop pop bx pop si pop ax pop cx ret HexChars db '0123456789ABCDEF', 0
/* TEMPLATE GENERATED TESTCASE FILE Filename: CWE761_Free_Pointer_Not_at_Start_of_Buffer__wchar_t_file_82a.cpp Label Definition File: CWE761_Free_Pointer_Not_at_Start_of_Buffer.label.xml Template File: source-sinks-82a.tmpl.cpp */ /* * @description * CWE: 761 Free Pointer not at Start of Buffer * BadSource: file Read input from a file * Sinks: * GoodSink: free() memory correctly at the start of the buffer * BadSink : free() memory not at the start of the buffer * Flow Variant: 82 Data flow: data passed in a parameter to an virtual method called via a pointer * * */ #include "std_testcase.h" #include "CWE761_Free_Pointer_Not_at_Start_of_Buffer__wchar_t_file_82.h" #ifdef _WIN32 #define FILENAME "C:\\temp\\file.txt" #else #define FILENAME "/tmp/file.txt" #endif #define SEARCH_CHAR L'S' namespace CWE761_Free_Pointer_Not_at_Start_of_Buffer__wchar_t_file_82 { #ifndef OMITBAD void bad() { wchar_t * data; data = (wchar_t *)malloc(100*sizeof(wchar_t)); if (data == NULL) {exit(-1);} data[0] = L'\0'; { /* Read input from a file */ size_t dataLen = wcslen(data); FILE * pFile; /* if there is room in data, attempt to read the input from a file */ if (100-dataLen > 1) { pFile = fopen(FILENAME, "r"); if (pFile != NULL) { /* POTENTIAL FLAW: Read data from a file */ if (fgetws(data+dataLen, (int)(100-dataLen), pFile) == NULL) { printLine("fgetws() failed"); /* Restore NUL terminator if fgetws fails */ data[dataLen] = L'\0'; } fclose(pFile); } } } CWE761_Free_Pointer_Not_at_Start_of_Buffer__wchar_t_file_82_base* baseObject = new CWE761_Free_Pointer_Not_at_Start_of_Buffer__wchar_t_file_82_bad; baseObject->action(data); delete baseObject; } #endif /* OMITBAD */ #ifndef OMITGOOD /* goodB2G uses the BadSource with the GoodSink */ static void goodB2G() { wchar_t * data; data = (wchar_t *)malloc(100*sizeof(wchar_t)); if (data == NULL) {exit(-1);} data[0] = L'\0'; { /* Read input from a file */ size_t dataLen = wcslen(data); FILE * pFile; /* if there is room in data, attempt to read the input from a file */ if (100-dataLen > 1) { pFile = fopen(FILENAME, "r"); if (pFile != NULL) { /* POTENTIAL FLAW: Read data from a file */ if (fgetws(data+dataLen, (int)(100-dataLen), pFile) == NULL) { printLine("fgetws() failed"); /* Restore NUL terminator if fgetws fails */ data[dataLen] = L'\0'; } fclose(pFile); } } } CWE761_Free_Pointer_Not_at_Start_of_Buffer__wchar_t_file_82_base* baseObject = new CWE761_Free_Pointer_Not_at_Start_of_Buffer__wchar_t_file_82_goodB2G; baseObject->action(data); delete baseObject; } void good() { goodB2G(); } #endif /* OMITGOOD */ } /* close namespace */ /* Below is the main(). It is only used when building this testcase on its own for testing or for building a binary to use in testing binary analysis tools. It is not used when compiling all the testcases as one application, which is how source code analysis tools are tested. */ #ifdef INCLUDEMAIN using namespace CWE761_Free_Pointer_Not_at_Start_of_Buffer__wchar_t_file_82; /* so that we can use good and bad easily */ int main(int argc, char * argv[]) { /* seed randomness */ srand( (unsigned)time(NULL) ); #ifndef OMITGOOD printLine("Calling good()..."); good(); printLine("Finished good()"); #endif /* OMITGOOD */ #ifndef OMITBAD printLine("Calling bad()..."); bad(); printLine("Finished bad()"); #endif /* OMITBAD */ return 0; } #endif
; Initialize the stack pointer MOV XL, 0xFF MOV XH, 0xFF MOV SP, X SUB SP, 7 ; Write the stack pointer to the Output Port C MOV X, SP OUT C ; Signal the listener that new data is available on Output Port C MOV XL, 00000010b OUT D MOV XL, 00000000b OUT D ; Write the stack pointer to the Output Port C MOV X, SP MOV XH, XL OUT C ; Signal the listener that new data is available on Output Port C MOV XL, 00000010b OUT D MOV XL, 00000000b OUT D ADD SP, 7 ; Write the stack pointer to the Output Port C MOV X, SP OUT C ; Signal the listener that new data is available on Output Port C MOV XL, 00000010b OUT D MOV XL, 00000000b OUT D ; Write the stack pointer to the Output Port C MOV X, SP MOV XH, XL OUT C ; Signal the listener that new data is available on Output Port C MOV XL, 00000010b OUT D MOV XL, 00000000b OUT D HLT
; A090996: Number of leading 1's in binary expansion of n. ; 0,1,1,2,1,1,2,3,1,1,1,1,2,2,3,4,1,1,1,1,1,1,1,1,2,2,2,2,3,3,4,5,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,4,4,5,6,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,5,5,6,7,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5 lpb $0,1 add $1,362880 mov $2,$0 div $0,2 mod $2,2 mul $1,$2 lpe div $1,362880
; A064756: a(n) = n*10^n - 1. ; 9,199,2999,39999,499999,5999999,69999999,799999999,8999999999,99999999999,1099999999999,11999999999999,129999999999999,1399999999999999,14999999999999999,159999999999999999,1699999999999999999,17999999999999999999,189999999999999999999,1999999999999999999999,20999999999999999999999,219999999999999999999999,2299999999999999999999999,23999999999999999999999999,249999999999999999999999999,2599999999999999999999999999,26999999999999999999999999999,279999999999999999999999999999 add $0,1 mov $2,10 pow $2,$0 mul $0,$2 sub $0,1
#include "pch.h" #include "Entity.h" Entity::Entity(SMALL_RECT dimensions) :Dimensions(dimensions) { } Entity::~Entity() { }
; A211813: Number of (n+1) X (n+1) -10..10 symmetric matrices with every 2 X 2 subblock having sum zero and two distinct values. ; 32,44,62,92,140,218,344,548,878,1412,2276,3674,5936,9596,15518,25100,40604,65690,106280,171956,278222,450164,728372,1178522,1906880,3085388,4992254,8077628,13069868,21147482,34217336,55364804,89582126,144946916,234529028,379475930,614004944,993480860,1607485790,2600966636,4208452412,6809419034,11017871432,17827290452,28845161870,46672452308,75517614164,122190066458,197707680608,319897747052,517605427646,837503174684,1355108602316,2192611776986,3547720379288,5740332156260,9288052535534,15028384691780,24316437227300,39344821919066,63661259146352,103006081065404,166667340211742,269673421277132,436340761488860,706014182765978,1142354944254824,1848369127020788,2990724071275598,4839093198296372,7829817269571956 mov $1,6 mov $2,4 lpb $0 sub $0,1 mov $3,$2 mov $2,$1 add $1,$3 lpe mul $1,3 add $1,14
INCLUDE "constants/hardware.inc" INCLUDE "constants/transition.inc" INCLUDE "constants/screens.inc" INCLUDE "constants/games/battleship.inc" INCLUDE "constants/actors.inc" INCLUDE "constants/sfx.inc" INCLUDE "constants/SoundSystem.inc" INCLUDE "constants/engine.inc" SECTION UNION "Game Variables", HRAM hEndDelay: DS 1 SECTION "Battleship Game Setup", ROMX xGameSetupBattleship:: ; Set palettes ld a, BATTLESHIP_BGP ldh [hBGP], a ld a, BATTLESHIP_OBP0 ldh [hOBP0], a ld a, BATTLESHIP_OBP1 ldh [hOBP1], a ; Set appropriate LCDC flags ld a, LCDCF_ON | LCDCF_BG8800 | LCDCF_BG9800 | LCDCF_BGON | LCDCF_OBJ16 | LCDCF_OBJON ldh [hLCDC], a ; Set initial Y scroll ld a, BATTLESHIP_INITIAL_Y ldh [hSCY], a ; Load background tiles ASSERT BANK(xBackgroundTiles) == BANK(@) ld de, xBackgroundTiles ld hl, $9000 ld bc, xBackgroundTiles.end - xBackgroundTiles rst LCDMemcopy ; Load sprite tiles ASSERT BANK(xSpriteTiles) == BANK(@) ASSERT xSpriteTiles == xBackgroundTiles.end ; de = xSpriteTiles ld hl, $8000 ld bc, xSpriteTiles.end - xSpriteTiles rst LCDMemcopy ; Repeat the 6-tile-high ocean pattern 3 times vertically onto the ; tilemap ASSERT BATTLESHIP_OCEAN_SIZE * 3 == SCRN_Y_B ; Load first background map ASSERT BANK(xMap1) == BANK(@) ASSERT xMap1 == xSpriteTiles.end ; de = xMap1 ld hl, _SCRN0 ld c, BATTLESHIP_OCEAN_SIZE call LCDMemcopyMap ld de, xMap1 ld c, BATTLESHIP_OCEAN_SIZE call LCDMemcopyMap ld de, xMap1 ld c, BATTLESHIP_OCEAN_SIZE call LCDMemcopyMap ; 1 extra time for scrolling ld de, xMap1 ld c, BATTLESHIP_OCEAN_SIZE call LCDMemcopyMap ; Load second background map ASSERT BANK(xMap2) == BANK(@) ASSERT xMap2 == xMap1.end ; de = xMap2 ld hl, _SCRN1 ld c, BATTLESHIP_OCEAN_SIZE call LCDMemcopyMap ld de, xMap2 ld c, BATTLESHIP_OCEAN_SIZE call LCDMemcopyMap ld de, xMap2 ld c, BATTLESHIP_OCEAN_SIZE call LCDMemcopyMap ; 1 extra time for scrolling ld de, xMap2 ld c, BATTLESHIP_OCEAN_SIZE call LCDMemcopyMap ; Create the Ship actor ASSERT BANK(xActorShipCannonDefinition) == BANK(@) ld de, xActorShipCannonDefinition call ActorNew ASSERT BANK(xActorShipDefinition) == BANK(@) ASSERT xActorShipDefinition == xActorShipCannonDefinition.end ; de = xActorShipDefinition call ActorNew ; Delay after the music ends ld a, END_DELAY ldh [hEndDelay], a ; Set up game data ld c, BANK(xHitTableBattleship) ld hl, xHitTableBattleship jp EngineInit xBackgroundTiles: INCBIN "res/battleship/background.bg.2bpp" .end xSpriteTiles: INCBIN "res/battleship/ship-obp0.obj.2bpp" INCBIN "res/battleship/ship-obp1.obj.2bpp" ; Remove the first 2 tiles which are blank on purpose to get rid of ; any blank objects in the image INCBIN "res/battleship/boat.obj.2bpp", 16 * 2 INCBIN "res/battleship/boat-motor.obj.2bpp" INCBIN "res/battleship/projectile.obj.2bpp" INCBIN "res/battleship/small-explosion.obj.2bpp" .end xMap1: INCBIN "res/battleship/background.bg.tilemap", 0, BATTLESHIP_OCEAN_SIZE * SCRN_X_B .end xMap2: INCBIN "res/battleship/background.bg.tilemap", BATTLESHIP_OCEAN_SIZE * SCRN_X_B .end xActorShipCannonDefinition: DB ACTOR_SHIP_CANNON DB BATTLESHIP_CANNON_X, BATTLESHIP_CANNON_Y DB 0, 0 .end xActorShipDefinition: DB ACTOR_SHIP DB BATTLESHIP_SHIP_X, BATTLESHIP_SHIP_Y DB 0, 0 SECTION "Battleship Game Loop", ROMX xGameBattleship:: rst WaitVBlank ; Check if currently transitioning to another screen ldh a, [hTransitionState] ASSERT TRANSITION_STATE_OFF == 0 and a, a jr z, .noTransition call TransitionUpdate ; Check if the transition just ended ldh a, [hTransitionState] ASSERT TRANSITION_STATE_OFF == 0 and a, a jr nz, xGameBattleship ; Start music ld c, BANK(Inst_Battleship) ld de, Inst_Battleship call Music_PrepareInst ld c, BANK(Music_Battleship) ld de, Music_Battleship call Music_Play jr xGameBattleship .noTransition ; All directions perform the same action -> combine them into the ; Left bit ldh a, [hNewKeys] ld b, a and a, PADF_RIGHT | PADF_UP | PADF_DOWN jr z, .noChange ld a, b and a, LOW(~(PADF_RIGHT | PADF_UP | PADF_DOWN)) set PADB_LEFT, a ldh [hNewKeys], a .noChange call EngineUpdate call ActorsUpdate ld a, [wMusicSyncData] ASSERT SYNC_NONE == -1 inc a jr z, .noBoat dec a ; Undo inc ASSERT BATTLESHIP_BOATB_LEFT == 0 rra ; Move bit 0 into carry call c, .boatLeft ld a, [wMusicSyncData] bit BATTLESHIP_BOATB_RIGHT, a call nz, .boatRight .noBoat ; Check for shooting the cannon ldh a, [hNewKeys] bit PADB_LEFT, a jr nz, .shootLeft .retShootLeft ASSERT PADB_A == 0 rra ; Move bit 0 into carry jr c, .shootRight .retShootRight ; Scroll the background ld hl, hSCY dec [hl] jr nz, .noReset ld [hl], BATTLESHIP_INITIAL_Y .noReset ; Check if the game is over ld a, [wMusicPlayState] ASSERT MUSIC_STATE_STOPPED == 0 and a, a jr nz, .notOver ld hl, hEndDelay dec [hl] jr nz, .notOver ; Game is over -> go to the overall rating screen ld a, SCREEN_RATING call TransitionStart jr xGameBattleship .notOver ; Update the background (ocean waves) every 16 frames ldh a, [hFrameCounter] and a, 15 jr nz, xGameBattleship ; Toggle the background tilemap ldh a, [hLCDC] xor a, LCDCF_BG9800 ^ LCDCF_BG9C00 ldh [hLCDC], a jr xGameBattleship .boatLeft ASSERT BANK(xActorBoatLeftDefinition) == BANK(@) ld de, xActorBoatLeftDefinition jp ActorNew ASSERT CEL_BOAT_LEFT == 0 ; No need to modify cel .boatRight ASSERT BANK(xActorBoatRightDefinition) == BANK(@) ld de, xActorBoatRightDefinition call ActorNew ; Use right-turning animation ld hl, wActorCelTable add hl, bc ld [hl], CEL_BOAT_RIGHT ret .shootLeft ASSERT BANK(xActorProjectileLeftDefinition) == BANK(@) ld de, xActorProjectileLeftDefinition call ActorNew ASSERT CEL_BOAT_LEFT == 0 ; No need to modify cel ld b, SFX_EXPLOSION call SFX_Play ; Restore A with hNewKeys for checking shoot right ldh a, [hNewKeys] jr .retShootLeft .shootRight ASSERT BANK(xActorProjectileRightDefinition) == BANK(@) ld de, xActorProjectileRightDefinition call ActorNew ld hl, wActorCelTable add hl, bc ld [hl], CEL_PROJECTILE_RIGHT ld b, SFX_EXPLOSION call SFX_Play jr .retShootRight xActorBoatLeftDefinition: DB ACTOR_BOAT_LEFT DB BOAT_LEFT_X, BOAT_Y DB BOAT_SPEED_X, BOAT_SPEED_Y xActorBoatRightDefinition: DB ACTOR_BOAT_RIGHT DB BOAT_RIGHT_X, BOAT_Y DB BOAT_SPEED_X, BOAT_SPEED_Y xActorProjectileLeftDefinition: DB ACTOR_PROJECTILE DB PROJECTILE_X, PROJECTILE_Y DB PROJECTILE_LEFT_SPEED_X, PROJECTILE_SPEED_Y xActorProjectileRightDefinition: DB ACTOR_PROJECTILE DB PROJECTILE_X, PROJECTILE_Y DB PROJECTILE_RIGHT_SPEED_X, PROJECTILE_SPEED_Y SECTION "Battleship Left Boat Actor", ROMX xActorBoatLeft:: ; Kill if shot ldh a, [hNewKeys] bit PADB_LEFT, a ret z ; Manually kill before creating new actors ld hl, wActorTypeTable add hl, bc ld [hl], ACTOR_EMPTY ; Create explosion ASSERT BANK(xActorSmallExplosionLeft1Definition) == BANK(@) ld de, xActorSmallExplosionLeft1Definition call ActorNew ASSERT BANK(xActorSmallExplosionLeft2Definition) == BANK(@) ld de, xActorSmallExplosionLeft2Definition call ActorNew ; Skip update pop af jp ActorsUpdate.next xActorSmallExplosionLeft1Definition: DB ACTOR_SMALL_EXPLOSION DB EXPLOSION_LEFT_X, EXPLOSION_Y DB 0, 0 xActorSmallExplosionLeft2Definition: DB ACTOR_SMALL_EXPLOSION DB EXPLOSION_LEFT_X + 8, EXPLOSION_Y + 8 DB 0, 0 SECTION "Battleship Right Boat Actor", ROMX xActorBoatRight:: ; Kill if shot ldh a, [hNewKeys] bit PADB_A, a ret z ; Manually kill before creating new actors ld hl, wActorTypeTable add hl, bc ld [hl], ACTOR_EMPTY ; Create explosion ASSERT BANK(xActorSmallExplosionRight1Definition) == BANK(@) ld de, xActorSmallExplosionRight1Definition call ActorNew ASSERT BANK(xActorSmallExplosionRight2Definition) == BANK(@) ld de, xActorSmallExplosionRight2Definition call ActorNew ; Skip update pop af jp ActorsUpdate.next xActorSmallExplosionRight1Definition: DB ACTOR_SMALL_EXPLOSION DB EXPLOSION_RIGHT_X, EXPLOSION_Y DB 0, 0 xActorSmallExplosionRight2Definition: DB ACTOR_SMALL_EXPLOSION DB EXPLOSION_RIGHT_X + 8, EXPLOSION_Y + 8 DB 0, 0
#ifndef STAN_MATH_REV_CORE_VVD_VARI_HPP #define STAN_MATH_REV_CORE_VVD_VARI_HPP #include <stan/math/rev/core/vari.hpp> namespace stan { namespace math { class op_vvd_vari : public vari { protected: vari* avi_; vari* bvi_; double cd_; public: op_vvd_vari(double f, vari* avi, vari* bvi, double c) : vari(f), avi_(avi), bvi_(bvi), cd_(c) {} }; } // namespace math } // namespace stan #endif
; A056117: Expansion of (1+8*x)/(1-x)^9. ; 1,17,117,525,1815,5247,13299,30459,64350,127270,238238,425646,730626,1211250,1947690,3048474,4657983,6965343,10214875,14718275,20868705,29156985,40190085,54712125,73628100,98030556,129229452,168785452,218546900,280690740,357767652,452751684,569094669,710785725,882416145,1089249993,1337300731,1633414211,1985358375,2401920015,2893008954,3469770018,4144703178,4931792250,5846642550,6906627910,8131047470,9541292670,11161024875,13016364075,15136089111,17551849887,20298392037,23413794525,26939720665,30921683057,35409322944,40456704504,46122624600,52470938520,59570902248,67497531816,76331980296,86161933000,97082021465,109194256809,122608483053,137442851013,153824313375,171889141575,191783465115,213663833955,237697804630,264064550750,292955498550,324574988166,359140961322,396885676122,438056449650,482916429090,531745392087,584840577079,642517544339,705111068475,772976063145,846488538753,926046593901,1012071441381,1105008469500,1205328339540,1313528120164,1430132459588,1555694796348,1690798609500,1836058709100,1992122567820,2159671694565,2339423050965,2532130511625,2738586369025,2959622883971,3196113882507,3448976400207,3719172374775,4007710387890,4315647457242,4644090879714,4994200126674,5367188792350,5764326596270,6186941440758,6636421524486,7114217513091,7621844767875,8160885633615,8732991786519,9339886643373,9983367832933,10665309730625,11387666057625,12152472545400,12961849666800,13818005434800,14723238270000,15679939938000,16690598557776,17757801682192,18884239451792,20072707823025,21326111872065,22647469175397,24039913268349,25506697182759,27051197064975,28676915875395,30387487170763,32186678970446,34078397707926,36066692268750,38155758116190,40349941505874,42653743790658,45071825817018,47609012414250,50270296977775,53060846147855,55986004585035,59051299843635,62262447344625,65625355449225,69146130634581,72831082772877,76686730515252,80719806781900,84937264359740,89346281609052,93954268280484,98768871443844,103797981530100,109049738488020,114532538056893,120255038156781,126226165397761,132455121709625,138951391093515,145724746496979,152785256813943,160143294011103,167809540382250,175794995932050,184110985890810,192769168361770,201781542102470,211160454441750,220918609333950,231069075551886,241625295020187,252601091290587,264010678160775,275868668438415,288190082851957,300990359109869,314285361109929,328091388300225,342425185193520,357303951036648,372745349636616,388767519345096,405389083203000,422629159246840,440507370978584,459043858000728,478259286818313,498174861809625,518812336367325,540194024211765,562342810878255,585282165380055,609036152048875,633629442554675,659087328106566,685435731836622,712701221368422,740911021572150,770093027508090,800275817560362,831488666762754,863761560318514,897125207315975,931611054641895,967251301094403,1004078911697451,1042127632218681,1081432003892625,1122027378351165,1163949932763189,1207236685185388,1251925510126148,1298055154324500,1345665252746100,1394796344798220,1445489890765740,1497788288470140,1551734890153500,1607374019589525,1664750989423621,1723912118744057,1784904750886257,1847777271472275,1912579126687515,1979360841796767,2048174039901639,2119071460941474,2192106980939850,2267335631498770,2344813619542658,2424598347314286,2506748432624766,2591323729359750,2678385348243990,2767995677866419,2860218405967923,2955118540993983,3052762433914375,3153217800312125,3256553742743925,3362840773374225,3472150836885225,3584557333665000,3700135143276000 lpb $0,1 mov $2,$0 cal $2,52206 ; Partial sums of A050405. sub $0,1 mul $2,4 add $1,$2 lpe div $1,4 add $1,1
/* * Copyright (C) 2019-2021 Intel Corporation * * SPDX-License-Identifier: MIT * */ #include "shared/source/helpers/state_base_address.h" #include "shared/source/helpers/state_base_address_bdw_and_later.inl" #include "shared/source/helpers/state_base_address_icllp_and_later.inl" namespace NEO { template struct StateBaseAddressHelper<ICLFamily>; }
; =============================================================== ; Jan 2014 ; =============================================================== ; ; char *strerror(int errnum) ; ; Return string message corresponding to errnum. ; ; =============================================================== SECTION code_string PUBLIC asm_strerror EXTERN ASMHEAD_rodata_error_strings, __str_locate_nul asm_strerror: ; enter : hl = errnum ; ; exit : hl = char *message ; carry set if errnum was not found ; ; uses : af, bc, e, hl ld a,h or a jr nz, use_default or l jr z, use_ok ld e,l ld hl,ASMHEAD_rodata_error_strings ld a,(hl) search_loop: cp e inc hl ret z ; if found string call __str_locate_nul inc hl ld a,(hl) or a jr nz, search_loop ; if end of strings not met use_default: ld hl,__error_string_default scf ret use_ok: ld hl,__error_string_ok ret __error_string_default: IF __CLIB_OPT_ERROR & $02 defm "ERR - Unknown" defb 0 ELSE defm "ERR" defb 0 ENDIF __error_string_ok: IF __CLIB_OPT_ERROR & $02 defm "EOK - No error" defb 0 ELSE defm "EOK" defb 0 ENDIF
/**************************************************************************/ /*! @file RTClib.cpp @mainpage Adafruit RTClib @section intro Introduction This is a fork of JeeLab's fantastic real time clock library for Arduino. For details on using this library with an RTC module like the DS1307, PCF8523, or DS3231, see the guide at: https://learn.adafruit.com/ds1307-real-time-clock-breakout-board-kit/overview Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! @section classes Available classes This library provides the following classes: - Classes for manipulating dates, times and durations: - DateTime represents a specific point in time; this is the data type used for setting and reading the supported RTCs - TimeSpan represents the length of a time interval - Interfacing specific RTC chips: - RTC_DS1307 - RTC_DS3231 - RTC_PCF8523 - RTC emulated in software; do not expect much accuracy out of these: - RTC_Millis is based on `millis()` - RTC_Micros is based on `micros()`; its drift rate can be tuned by the user @section license License Original library by JeeLabs https://jeelabs.org/pub/docs/rtclib/, released to the public domain. This version: MIT (see LICENSE) */ /**************************************************************************/ #include "RTClib.h" #if defined(__AVR__) && !defined(TWCR) && defined(USICR) #include <TinyWireM.h> #define Wire TinyWireM #else #include <Wire.h> #endif #ifdef __AVR__ #include <avr/pgmspace.h> #elif defined(ESP8266) #include <pgmspace.h> #elif defined(ARDUINO_ARCH_SAMD) // nothing special needed #elif defined(ARDUINO_SAM_DUE) #define PROGMEM #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) #define Wire Wire1 #endif #if (ARDUINO >= 100) #define _I2C_WRITE write ///< Modern I2C write #define _I2C_READ read ///< Modern I2C read #else #include <WProgram.h> #define _I2C_WRITE send ///< Legacy I2C write #define _I2C_READ receive ///< legacy I2C read #endif /**************************************************************************/ /*! @brief Read a byte from an I2C register @param addr I2C address @param reg Register address @return Register value */ /**************************************************************************/ static uint8_t read_i2c_register(uint8_t addr, uint8_t reg) { Wire.beginTransmission(addr); Wire._I2C_WRITE((byte)reg); Wire.endTransmission(); Wire.requestFrom(addr, (byte)1); return Wire._I2C_READ(); } /**************************************************************************/ /*! @brief Write a byte to an I2C register @param addr I2C address @param reg Register address @param val Value to write */ /**************************************************************************/ static void write_i2c_register(uint8_t addr, uint8_t reg, uint8_t val) { Wire.beginTransmission(addr); Wire._I2C_WRITE((byte)reg); Wire._I2C_WRITE((byte)val); Wire.endTransmission(); } /**************************************************************************/ // utility code, some of this could be exposed in the DateTime API if needed /**************************************************************************/ /** Number of days in each month, from January to November. December is not needed. Omitting it avoids an incompatibility with Paul Stoffregen's Time library. C.f. https://github.com/adafruit/RTClib/issues/114 */ const uint8_t daysInMonth[] PROGMEM = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30}; /**************************************************************************/ /*! @brief Given a date, return number of days since 2000/01/01, valid for 2000--2099 @param y Year @param m Month @param d Day @return Number of days */ /**************************************************************************/ static uint16_t date2days(uint16_t y, uint8_t m, uint8_t d) { if (y >= 2000U) y -= 2000U; uint16_t days = d; for (uint8_t i = 1; i < m; ++i) days += pgm_read_byte(daysInMonth + i - 1); if (m > 2 && y % 4 == 0) ++days; return days + 365 * y + (y + 3) / 4 - 1; } /**************************************************************************/ /*! @brief Given a number of days, hours, minutes, and seconds, return the total seconds @param days Days @param h Hours @param m Minutes @param s Seconds @return Number of seconds total */ /**************************************************************************/ static uint32_t time2ulong(uint16_t days, uint8_t h, uint8_t m, uint8_t s) { return ((days * 24UL + h) * 60 + m) * 60 + s; } /**************************************************************************/ /*! @brief Constructor from [Unix time](https://en.wikipedia.org/wiki/Unix_time). This builds a DateTime from an integer specifying the number of seconds elapsed since the epoch: 1970-01-01 00:00:00. This number is analogous to Unix time, with two small differences: - The Unix epoch is specified to be at 00:00:00 [UTC](https://en.wikipedia.org/wiki/Coordinated_Universal_Time), whereas this class has no notion of time zones. The epoch used in this class is then at 00:00:00 on whatever time zone the user chooses to use, ignoring changes in DST. - Unix time is conventionally represented with signed numbers, whereas this constructor takes an unsigned argument. Because of this, it does _not_ suffer from the [year 2038 problem](https://en.wikipedia.org/wiki/Year_2038_problem). If called without argument, it returns the earliest time representable by this class: 2000-01-01 00:00:00. @see The `unixtime()` method is the converse of this constructor. @param t Time elapsed in seconds since 1970-01-01 00:00:00. */ /**************************************************************************/ DateTime::DateTime(uint32_t t) { t -= SECONDS_FROM_1970_TO_2000; // bring to 2000 timestamp from 1970 ss = t % 60; t /= 60; mm = t % 60; t /= 60; hh = t % 24; uint16_t days = t / 24; uint8_t leap; for (yOff = 0;; ++yOff) { leap = yOff % 4 == 0; if (days < 365U + leap) break; days -= 365 + leap; } for (m = 1; m < 12; ++m) { uint8_t daysPerMonth = pgm_read_byte(daysInMonth + m - 1); if (leap && m == 2) ++daysPerMonth; if (days < daysPerMonth) break; days -= daysPerMonth; } d = days + 1; } /**************************************************************************/ /*! @brief Constructor from (year, month, day, hour, minute, second). @warning If the provided parameters are not valid (e.g. 31 February), the constructed DateTime will be invalid. @see The `isValid()` method can be used to test whether the constructed DateTime is valid. @param year Either the full year (range: 2000--2099) or the offset from year 2000 (range: 0--99). @param month Month number (1--12). @param day Day of the month (1--31). @param hour,min,sec Hour (0--23), minute (0--59) and second (0--59). */ /**************************************************************************/ DateTime::DateTime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t min, uint8_t sec) { if (year >= 2000U) year -= 2000U; yOff = year; m = month; d = day; hh = hour; mm = min; ss = sec; } /**************************************************************************/ /*! @brief Copy constructor. @param copy DateTime to copy. */ /**************************************************************************/ DateTime::DateTime(const DateTime &copy) : yOff(copy.yOff), m(copy.m), d(copy.d), hh(copy.hh), mm(copy.mm), ss(copy.ss) {} /**************************************************************************/ /*! @brief Convert a string containing two digits to uint8_t, e.g. "09" returns 9 @param p Pointer to a string containing two digits */ /**************************************************************************/ static uint8_t conv2d(const char *p) { uint8_t v = 0; if ('0' <= *p && *p <= '9') v = *p - '0'; return 10 * v + *++p - '0'; } /**************************************************************************/ /*! @brief Constructor for generating the build time. This constructor expects its parameters to be strings in the format generated by the compiler's preprocessor macros `__DATE__` and `__TIME__`. Usage: ``` DateTime buildTime(__DATE__, __TIME__); ``` @note The `F()` macro can be used to reduce the RAM footprint, see the next constructor. @param date Date string, e.g. "Apr 16 2020". @param time Time string, e.g. "18:34:56". */ /**************************************************************************/ DateTime::DateTime(const char *date, const char *time) { yOff = conv2d(date + 9); // Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec switch (date[0]) { case 'J': m = (date[1] == 'a') ? 1 : ((date[2] == 'n') ? 6 : 7); break; case 'F': m = 2; break; case 'A': m = date[2] == 'r' ? 4 : 8; break; case 'M': m = date[2] == 'r' ? 3 : 5; break; case 'S': m = 9; break; case 'O': m = 10; break; case 'N': m = 11; break; case 'D': m = 12; break; } d = conv2d(date + 4); hh = conv2d(time); mm = conv2d(time + 3); ss = conv2d(time + 6); } /**************************************************************************/ /*! @brief Memory friendly constructor for generating the build time. This version is intended to save RAM by keeping the date and time strings in program memory. Use it with the `F()` macro: ``` DateTime buildTime(F(__DATE__), F(__TIME__)); ``` @param date Date PROGMEM string, e.g. F("Apr 16 2020"). @param time Time PROGMEM string, e.g. F("18:34:56"). */ /**************************************************************************/ DateTime::DateTime(const __FlashStringHelper *date, const __FlashStringHelper *time) { char buff[11]; memcpy_P(buff, date, 11); yOff = conv2d(buff + 9); // Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec switch (buff[0]) { case 'J': m = (buff[1] == 'a') ? 1 : ((buff[2] == 'n') ? 6 : 7); break; case 'F': m = 2; break; case 'A': m = buff[2] == 'r' ? 4 : 8; break; case 'M': m = buff[2] == 'r' ? 3 : 5; break; case 'S': m = 9; break; case 'O': m = 10; break; case 'N': m = 11; break; case 'D': m = 12; break; } d = conv2d(buff + 4); memcpy_P(buff, time, 8); hh = conv2d(buff); mm = conv2d(buff + 3); ss = conv2d(buff + 6); } /**************************************************************************/ /*! @brief Constructor for creating a DateTime from an ISO8601 date string. This constructor expects its parameters to be a string in the https://en.wikipedia.org/wiki/ISO_8601 format, e.g: "2020-06-25T15:29:37" Usage: ``` DateTime dt("2020-06-25T15:29:37"); ``` @note The year must be > 2000, as only the yOff is considered. @param iso8601dateTime A dateTime string in iso8601 format, e.g. "2020-06-25T15:29:37". */ /**************************************************************************/ DateTime::DateTime(const char *iso8601dateTime) { char ref[] = "2000-01-01T00:00:00"; memcpy(ref, iso8601dateTime, min(strlen(ref), strlen(iso8601dateTime))); yOff = conv2d(ref + 2); m = conv2d(ref + 5); d = conv2d(ref + 8); hh = conv2d(ref + 11); mm = conv2d(ref + 14); ss = conv2d(ref + 17); } /**************************************************************************/ /*! @brief Check whether this DateTime is valid. @return true if valid, false if not. */ /**************************************************************************/ bool DateTime::isValid() const { if (yOff >= 100) return false; DateTime other(unixtime()); return yOff == other.yOff && m == other.m && d == other.d && hh == other.hh && mm == other.mm && ss == other.ss; } /**************************************************************************/ /*! @brief Writes the DateTime as a string in a user-defined format. The _buffer_ parameter should be initialized by the caller with a string specifying the requested format. This format string may contain any of the following specifiers: | specifier | output | |-----------|--------------------------------------------------------| | YYYY | the year as a 4-digit number (2000--2099) | | YY | the year as a 2-digit number (00--99) | | MM | the month as a 2-digit number (01--12) | | MMM | the abbreviated English month name ("Jan"--"Dec") | | DD | the day as a 2-digit number (01--31) | | DDD | the abbreviated English day of the week ("Mon"--"Sun") | | AP | either "AM" or "PM" | | ap | either "am" or "pm" | | hh | the hour as a 2-digit number (00--23 or 01--12) | | mm | the minute as a 2-digit number (00--59) | | ss | the second as a 2-digit number (00--59) | If either "AP" or "ap" is used, the "hh" specifier uses 12-hour mode (range: 01--12). Otherwise it works in 24-hour mode (range: 00--23). The specifiers within _buffer_ will be overwritten with the appropriate values from the DateTime. Any characters not belonging to one of the above specifiers are left as-is. __Example__: The format "DDD, DD MMM YYYY hh:mm:ss" generates an output of the form "Thu, 16 Apr 2020 18:34:56. @see The `timestamp()` method provides similar functionnality, but it returns a `String` object and supports a limited choice of predefined formats. @param[in,out] buffer Array of `char` for holding the format description and the formatted DateTime. Before calling this method, the buffer should be initialized by the user with the format string. The method will overwrite the buffer with the formatted date and/or time. @return A pointer to the provided buffer. This is returned for convenience, in order to enable idioms such as `Serial.println(now.toString(buffer));` */ /**************************************************************************/ char *DateTime::toString(char *buffer) { uint8_t apTag = (strstr(buffer, "ap") != nullptr) || (strstr(buffer, "AP") != nullptr); uint8_t hourReformatted = 0, isPM = false; if (apTag) { // 12 Hour Mode if (hh == 0) { // midnight isPM = false; hourReformatted = 12; } else if (hh == 12) { // noon isPM = true; hourReformatted = 12; } else if (hh < 12) { // morning isPM = false; hourReformatted = hh; } else { // 1 o'clock or after isPM = true; hourReformatted = hh - 12; } } for (size_t i = 0; i < strlen(buffer) - 1; i++) { if (buffer[i] == 'h' && buffer[i + 1] == 'h') { if (!apTag) { // 24 Hour Mode buffer[i] = '0' + hh / 10; buffer[i + 1] = '0' + hh % 10; } else { // 12 Hour Mode buffer[i] = '0' + hourReformatted / 10; buffer[i + 1] = '0' + hourReformatted % 10; } } if (buffer[i] == 'm' && buffer[i + 1] == 'm') { buffer[i] = '0' + mm / 10; buffer[i + 1] = '0' + mm % 10; } if (buffer[i] == 's' && buffer[i + 1] == 's') { buffer[i] = '0' + ss / 10; buffer[i + 1] = '0' + ss % 10; } if (buffer[i] == 'D' && buffer[i + 1] == 'D' && buffer[i + 2] == 'D') { static PROGMEM const char day_names[] = "SunMonTueWedThuFriSat"; const char *p = &day_names[3 * dayOfTheWeek()]; buffer[i] = pgm_read_byte(p); buffer[i + 1] = pgm_read_byte(p + 1); buffer[i + 2] = pgm_read_byte(p + 2); } else if (buffer[i] == 'D' && buffer[i + 1] == 'D') { buffer[i] = '0' + d / 10; buffer[i + 1] = '0' + d % 10; } if (buffer[i] == 'M' && buffer[i + 1] == 'M' && buffer[i + 2] == 'M') { static PROGMEM const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; const char *p = &month_names[3 * (m - 1)]; buffer[i] = pgm_read_byte(p); buffer[i + 1] = pgm_read_byte(p + 1); buffer[i + 2] = pgm_read_byte(p + 2); } else if (buffer[i] == 'M' && buffer[i + 1] == 'M') { buffer[i] = '0' + m / 10; buffer[i + 1] = '0' + m % 10; } if (buffer[i] == 'Y' && buffer[i + 1] == 'Y' && buffer[i + 2] == 'Y' && buffer[i + 3] == 'Y') { buffer[i] = '2'; buffer[i + 1] = '0'; buffer[i + 2] = '0' + (yOff / 10) % 10; buffer[i + 3] = '0' + yOff % 10; } else if (buffer[i] == 'Y' && buffer[i + 1] == 'Y') { buffer[i] = '0' + (yOff / 10) % 10; buffer[i + 1] = '0' + yOff % 10; } if (buffer[i] == 'A' && buffer[i + 1] == 'P') { if (isPM) { buffer[i] = 'P'; buffer[i + 1] = 'M'; } else { buffer[i] = 'A'; buffer[i + 1] = 'M'; } } else if (buffer[i] == 'a' && buffer[i + 1] == 'p') { if (isPM) { buffer[i] = 'p'; buffer[i + 1] = 'm'; } else { buffer[i] = 'a'; buffer[i + 1] = 'm'; } } } return buffer; } /**************************************************************************/ /*! @brief Return the hour in 12-hour format. @return Hour (1--12). */ /**************************************************************************/ uint8_t DateTime::twelveHour() const { if (hh == 0 || hh == 12) { // midnight or noon return 12; } else if (hh > 12) { // 1 o'clock or later return hh - 12; } else { // morning return hh; } } /**************************************************************************/ /*! @brief Return the day of the week. @return Day of week as an integer from 0 (Sunday) to 6 (Saturday). */ /**************************************************************************/ uint8_t DateTime::dayOfTheWeek() const { uint16_t day = date2days(yOff, m, d); return (day + 6) % 7; // Jan 1, 2000 is a Saturday, i.e. returns 6 } /**************************************************************************/ /*! @brief Return Unix time: seconds since 1 Jan 1970. @see The `DateTime::DateTime(uint32_t)` constructor is the converse of this method. @return Number of seconds since 1970-01-01 00:00:00. */ /**************************************************************************/ uint32_t DateTime::unixtime() const { uint32_t t; uint16_t days = date2days(yOff, m, d); t = time2ulong(days, hh, mm, ss); t += SECONDS_FROM_1970_TO_2000; // seconds from 1970 to 2000 return t; } /**************************************************************************/ /*! @brief Convert the DateTime to seconds since 1 Jan 2000 The result can be converted back to a DateTime with: ```cpp DateTime(SECONDS_FROM_1970_TO_2000 + value) ``` @return Number of seconds since 2000-01-01 00:00:00. */ /**************************************************************************/ uint32_t DateTime::secondstime() const { uint32_t t; uint16_t days = date2days(yOff, m, d); t = time2ulong(days, hh, mm, ss); return t; } /**************************************************************************/ /*! @brief Add a TimeSpan to the DateTime object @param span TimeSpan object @return New DateTime object with span added to it. */ /**************************************************************************/ DateTime DateTime::operator+(const TimeSpan &span) { return DateTime(unixtime() + span.totalseconds()); } /**************************************************************************/ /*! @brief Subtract a TimeSpan from the DateTime object @param span TimeSpan object @return New DateTime object with span subtracted from it. */ /**************************************************************************/ DateTime DateTime::operator-(const TimeSpan &span) { return DateTime(unixtime() - span.totalseconds()); } /**************************************************************************/ /*! @brief Subtract one DateTime from another @note Since a TimeSpan cannot be negative, the subtracted DateTime should be less (earlier) than or equal to the one it is subtracted from. @param right The DateTime object to subtract from self (the left object) @return TimeSpan of the difference between DateTimes. */ /**************************************************************************/ TimeSpan DateTime::operator-(const DateTime &right) { return TimeSpan(unixtime() - right.unixtime()); } /**************************************************************************/ /*! @author Anton Rieutskyi @brief Test if one DateTime is less (earlier) than another. @warning if one or both DateTime objects are invalid, returned value is meaningless @see use `isValid()` method to check if DateTime object is valid @param right Comparison DateTime object @return True if the left DateTime is earlier than the right one, false otherwise. */ /**************************************************************************/ bool DateTime::operator<(const DateTime &right) const { return (yOff + 2000U < right.year() || (yOff + 2000U == right.year() && (m < right.month() || (m == right.month() && (d < right.day() || (d == right.day() && (hh < right.hour() || (hh == right.hour() && (mm < right.minute() || (mm == right.minute() && ss < right.second())))))))))); } /**************************************************************************/ /*! @author Anton Rieutskyi @brief Test if two DateTime objects are equal. @warning if one or both DateTime objects are invalid, returned value is meaningless @see use `isValid()` method to check if DateTime object is valid @param right Comparison DateTime object @return True if both DateTime objects are the same, false otherwise. */ /**************************************************************************/ bool DateTime::operator==(const DateTime &right) const { return (right.year() == yOff + 2000U && right.month() == m && right.day() == d && right.hour() == hh && right.minute() == mm && right.second() == ss); } /**************************************************************************/ /*! @brief Return a ISO 8601 timestamp as a `String` object. The generated timestamp conforms to one of the predefined, ISO 8601-compatible formats for representing the date (if _opt_ is `TIMESTAMP_DATE`), the time (`TIMESTAMP_TIME`), or both (`TIMESTAMP_FULL`). @see The `toString()` method provides more general string formatting. @param opt Format of the timestamp @return Timestamp string, e.g. "2020-04-16T18:34:56". */ /**************************************************************************/ String DateTime::timestamp(timestampOpt opt) { char buffer[25]; // large enough for any DateTime, including invalid ones // Generate timestamp according to opt switch (opt) { case TIMESTAMP_TIME: // Only time sprintf(buffer, "%02d:%02d:%02d", hh, mm, ss); break; case TIMESTAMP_DATE: // Only date sprintf(buffer, "%u-%02d-%02d", 2000U + yOff, m, d); break; default: // Full sprintf(buffer, "%u-%02d-%02dT%02d:%02d:%02d", 2000U + yOff, m, d, hh, mm, ss); } return String(buffer); } /**************************************************************************/ /*! @brief Create a new TimeSpan object in seconds @param seconds Number of seconds */ /**************************************************************************/ TimeSpan::TimeSpan(int32_t seconds) : _seconds(seconds) {} /**************************************************************************/ /*! @brief Create a new TimeSpan object using a number of days/hours/minutes/seconds e.g. Make a TimeSpan of 3 hours and 45 minutes: new TimeSpan(0, 3, 45, 0); @param days Number of days @param hours Number of hours @param minutes Number of minutes @param seconds Number of seconds */ /**************************************************************************/ TimeSpan::TimeSpan(int16_t days, int8_t hours, int8_t minutes, int8_t seconds) : _seconds((int32_t)days * 86400L + (int32_t)hours * 3600 + (int32_t)minutes * 60 + seconds) {} /**************************************************************************/ /*! @brief Copy constructor, make a new TimeSpan using an existing one @param copy The TimeSpan to copy */ /**************************************************************************/ TimeSpan::TimeSpan(const TimeSpan &copy) : _seconds(copy._seconds) {} /**************************************************************************/ /*! @brief Add two TimeSpans @param right TimeSpan to add @return New TimeSpan object, sum of left and right */ /**************************************************************************/ TimeSpan TimeSpan::operator+(const TimeSpan &right) { return TimeSpan(_seconds + right._seconds); } /**************************************************************************/ /*! @brief Subtract a TimeSpan @param right TimeSpan to subtract @return New TimeSpan object, right subtracted from left */ /**************************************************************************/ TimeSpan TimeSpan::operator-(const TimeSpan &right) { return TimeSpan(_seconds - right._seconds); } /**************************************************************************/ /*! @brief Convert a binary coded decimal value to binary. RTC stores time/date values as BCD. @param val BCD value @return Binary value */ /**************************************************************************/ static uint8_t bcd2bin(uint8_t val) { return val - 6 * (val >> 4); } /**************************************************************************/ /*! @brief Convert a binary value to BCD format for the RTC registers @param val Binary value @return BCD value */ /**************************************************************************/ static uint8_t bin2bcd(uint8_t val) { return val + 6 * (val / 10); } /**************************************************************************/ /*! @brief Start I2C for the DS1307 and test succesful connection @return True if Wire can find DS1307 or false otherwise. */ /**************************************************************************/ bool RTC_DS1307::begin() { Wire.begin(); Wire.beginTransmission(DS1307_ADDRESS); if (Wire.endTransmission() == 0) return true; return false; } /**************************************************************************/ /*! @brief Is the DS1307 running? Check the Clock Halt bit in register 0 @return 1 if the RTC is running, 0 if not */ /**************************************************************************/ uint8_t RTC_DS1307::isrunning() { Wire.beginTransmission(DS1307_ADDRESS); Wire._I2C_WRITE((byte)0); Wire.endTransmission(); Wire.requestFrom(DS1307_ADDRESS, 1); uint8_t ss = Wire._I2C_READ(); return !(ss >> 7); } /**************************************************************************/ /*! @brief Set the date and time in the DS1307 @param dt DateTime object containing the desired date/time */ /**************************************************************************/ void RTC_DS1307::adjust(const DateTime &dt) { Wire.beginTransmission(DS1307_ADDRESS); Wire._I2C_WRITE((byte)0); // start at location 0 Wire._I2C_WRITE(bin2bcd(dt.second())); Wire._I2C_WRITE(bin2bcd(dt.minute())); Wire._I2C_WRITE(bin2bcd(dt.hour())); Wire._I2C_WRITE(bin2bcd(0)); Wire._I2C_WRITE(bin2bcd(dt.day())); Wire._I2C_WRITE(bin2bcd(dt.month())); Wire._I2C_WRITE(bin2bcd(dt.year() - 2000U)); Wire.endTransmission(); } /**************************************************************************/ /*! @brief Get the current date and time from the DS1307 @return DateTime object containing the current date and time */ /**************************************************************************/ DateTime RTC_DS1307::now() { Wire.beginTransmission(DS1307_ADDRESS); Wire._I2C_WRITE((byte)0); Wire.endTransmission(); Wire.requestFrom(DS1307_ADDRESS, 7); uint8_t ss = bcd2bin(Wire._I2C_READ() & 0x7F); uint8_t mm = bcd2bin(Wire._I2C_READ()); uint8_t hh = bcd2bin(Wire._I2C_READ()); Wire._I2C_READ(); uint8_t d = bcd2bin(Wire._I2C_READ()); uint8_t m = bcd2bin(Wire._I2C_READ()); uint16_t y = bcd2bin(Wire._I2C_READ()) + 2000U; return DateTime(y, m, d, hh, mm, ss); } /**************************************************************************/ /*! @brief Read the current mode of the SQW pin @return Mode as Ds1307SqwPinMode enum */ /**************************************************************************/ Ds1307SqwPinMode RTC_DS1307::readSqwPinMode() { int mode; Wire.beginTransmission(DS1307_ADDRESS); Wire._I2C_WRITE(DS1307_CONTROL); Wire.endTransmission(); Wire.requestFrom((uint8_t)DS1307_ADDRESS, (uint8_t)1); mode = Wire._I2C_READ(); mode &= 0x93; return static_cast<Ds1307SqwPinMode>(mode); } /**************************************************************************/ /*! @brief Change the SQW pin mode @param mode The mode to use */ /**************************************************************************/ void RTC_DS1307::writeSqwPinMode(Ds1307SqwPinMode mode) { Wire.beginTransmission(DS1307_ADDRESS); Wire._I2C_WRITE(DS1307_CONTROL); Wire._I2C_WRITE(mode); Wire.endTransmission(); } /**************************************************************************/ /*! @brief Read data from the DS1307's NVRAM @param buf Pointer to a buffer to store the data - make sure it's large enough to hold size bytes @param size Number of bytes to read @param address Starting NVRAM address, from 0 to 55 */ /**************************************************************************/ void RTC_DS1307::readnvram(uint8_t *buf, uint8_t size, uint8_t address) { int addrByte = DS1307_NVRAM + address; Wire.beginTransmission(DS1307_ADDRESS); Wire._I2C_WRITE(addrByte); Wire.endTransmission(); Wire.requestFrom((uint8_t)DS1307_ADDRESS, size); for (uint8_t pos = 0; pos < size; ++pos) { buf[pos] = Wire._I2C_READ(); } } /**************************************************************************/ /*! @brief Write data to the DS1307 NVRAM @param address Starting NVRAM address, from 0 to 55 @param buf Pointer to buffer containing the data to write @param size Number of bytes in buf to write to NVRAM */ /**************************************************************************/ void RTC_DS1307::writenvram(uint8_t address, uint8_t *buf, uint8_t size) { int addrByte = DS1307_NVRAM + address; Wire.beginTransmission(DS1307_ADDRESS); Wire._I2C_WRITE(addrByte); for (uint8_t pos = 0; pos < size; ++pos) { Wire._I2C_WRITE(buf[pos]); } Wire.endTransmission(); } /**************************************************************************/ /*! @brief Shortcut to read one byte from NVRAM @param address NVRAM address, 0 to 55 @return The byte read from NVRAM */ /**************************************************************************/ uint8_t RTC_DS1307::readnvram(uint8_t address) { uint8_t data; readnvram(&data, 1, address); return data; } /**************************************************************************/ /*! @brief Shortcut to write one byte to NVRAM @param address NVRAM address, 0 to 55 @param data One byte to write */ /**************************************************************************/ void RTC_DS1307::writenvram(uint8_t address, uint8_t data) { writenvram(address, &data, 1); } /** Alignment between the milis() timescale and the Unix timescale. These two variables are updated on each call to now(), which prevents rollover issues. Note that lastMillis is **not** the millis() value of the last call to now(): it's the millis() value corresponding to the last **full second** of Unix time. */ uint32_t RTC_Millis::lastMillis; uint32_t RTC_Millis::lastUnix; /**************************************************************************/ /*! @brief Set the current date/time of the RTC_Millis clock. @param dt DateTime object with the desired date and time */ /**************************************************************************/ void RTC_Millis::adjust(const DateTime &dt) { lastMillis = millis(); lastUnix = dt.unixtime(); } /**************************************************************************/ /*! @brief Return a DateTime object containing the current date/time. Note that computing (millis() - lastMillis) is rollover-safe as long as this method is called at least once every 49.7 days. @return DateTime object containing current time */ /**************************************************************************/ DateTime RTC_Millis::now() { uint32_t elapsedSeconds = (millis() - lastMillis) / 1000; lastMillis += elapsedSeconds * 1000; lastUnix += elapsedSeconds; return lastUnix; } /** Number of microseconds reported by micros() per "true" (calibrated) second. */ uint32_t RTC_Micros::microsPerSecond = 1000000; /** The timing logic is identical to RTC_Millis. */ uint32_t RTC_Micros::lastMicros; uint32_t RTC_Micros::lastUnix; /**************************************************************************/ /*! @brief Set the current date/time of the RTC_Micros clock. @param dt DateTime object with the desired date and time */ /**************************************************************************/ void RTC_Micros::adjust(const DateTime &dt) { lastMicros = micros(); lastUnix = dt.unixtime(); } /**************************************************************************/ /*! @brief Adjust the RTC_Micros clock to compensate for system clock drift @param ppm Adjustment to make */ /**************************************************************************/ // A positive adjustment makes the clock faster. void RTC_Micros::adjustDrift(int ppm) { microsPerSecond = 1000000 - ppm; } /**************************************************************************/ /*! @brief Get the current date/time from the RTC_Micros clock. @return DateTime object containing the current date/time */ /**************************************************************************/ DateTime RTC_Micros::now() { uint32_t elapsedSeconds = (micros() - lastMicros) / microsPerSecond; lastMicros += elapsedSeconds * microsPerSecond; lastUnix += elapsedSeconds; return lastUnix; } /**************************************************************************/ /*! @brief Start I2C for the PCF8523 and test succesful connection @return True if Wire can find PCF8523 or false otherwise. */ /**************************************************************************/ bool RTC_PCF8523::begin() { Wire.begin(); Wire.beginTransmission(PCF8523_ADDRESS); if (Wire.endTransmission() == 0) return true; return false; } /**************************************************************************/ /*! @brief Check the status register Oscillator Stop flag to see if the PCF8523 stopped due to power loss @details When battery or external power is first applied, the PCF8523's crystal oscillator takes up to 2s to stabilize. During this time adjust() cannot clear the 'OS' flag. See datasheet OS flag section for details. @return True if the bit is set (oscillator is or has stopped) and false only after the bit is cleared, for instance with adjust() */ /**************************************************************************/ bool RTC_PCF8523::lostPower() { return (read_i2c_register(PCF8523_ADDRESS, PCF8523_STATUSREG) >> 7); } /**************************************************************************/ /*! @brief Check control register 3 to see if we've run adjust() yet (setting the date/time and battery switchover mode) @return True if the PCF8523 has been set up, false if not */ /**************************************************************************/ bool RTC_PCF8523::initialized() { Wire.beginTransmission(PCF8523_ADDRESS); Wire._I2C_WRITE((byte)PCF8523_CONTROL_3); Wire.endTransmission(); Wire.requestFrom(PCF8523_ADDRESS, 1); uint8_t ss = Wire._I2C_READ(); return ((ss & 0xE0) != 0xE0); // 0xE0 = standby mode, set after power out } /**************************************************************************/ /*! @brief Set the date and time, set battery switchover mode @param dt DateTime to set */ /**************************************************************************/ void RTC_PCF8523::adjust(const DateTime &dt) { Wire.beginTransmission(PCF8523_ADDRESS); Wire._I2C_WRITE((byte)3); // start at location 3 Wire._I2C_WRITE(bin2bcd(dt.second())); Wire._I2C_WRITE(bin2bcd(dt.minute())); Wire._I2C_WRITE(bin2bcd(dt.hour())); Wire._I2C_WRITE(bin2bcd(dt.day())); Wire._I2C_WRITE(bin2bcd(0)); // skip weekdays Wire._I2C_WRITE(bin2bcd(dt.month())); Wire._I2C_WRITE(bin2bcd(dt.year() - 2000U)); Wire.endTransmission(); // set to battery switchover mode Wire.beginTransmission(PCF8523_ADDRESS); Wire._I2C_WRITE((byte)PCF8523_CONTROL_3); Wire._I2C_WRITE((byte)0x00); Wire.endTransmission(); } /**************************************************************************/ /*! @brief Get the current date/time @return DateTime object containing the current date/time */ /**************************************************************************/ DateTime RTC_PCF8523::now() { Wire.beginTransmission(PCF8523_ADDRESS); Wire._I2C_WRITE((byte)3); Wire.endTransmission(); Wire.requestFrom(PCF8523_ADDRESS, 7); uint8_t ss = bcd2bin(Wire._I2C_READ() & 0x7F); uint8_t mm = bcd2bin(Wire._I2C_READ()); uint8_t hh = bcd2bin(Wire._I2C_READ()); uint8_t d = bcd2bin(Wire._I2C_READ()); Wire._I2C_READ(); // skip 'weekdays' uint8_t m = bcd2bin(Wire._I2C_READ()); uint16_t y = bcd2bin(Wire._I2C_READ()) + 2000U; return DateTime(y, m, d, hh, mm, ss); } /**************************************************************************/ /*! @brief Resets the STOP bit in register Control_1 */ /**************************************************************************/ void RTC_PCF8523::start() { uint8_t ctlreg = read_i2c_register(PCF8523_ADDRESS, PCF8523_CONTROL_1); if (ctlreg & (1 << 5)) { write_i2c_register(PCF8523_ADDRESS, PCF8523_CONTROL_1, ctlreg & ~(1 << 5)); } } /**************************************************************************/ /*! @brief Sets the STOP bit in register Control_1 */ /**************************************************************************/ void RTC_PCF8523::stop() { uint8_t ctlreg = read_i2c_register(PCF8523_ADDRESS, PCF8523_CONTROL_1); if (!(ctlreg & (1 << 5))) { write_i2c_register(PCF8523_ADDRESS, PCF8523_CONTROL_1, ctlreg | (1 << 5)); } } /**************************************************************************/ /*! @brief Is the PCF8523 running? Check the STOP bit in register Control_1 @return 1 if the RTC is running, 0 if not */ /**************************************************************************/ uint8_t RTC_PCF8523::isrunning() { uint8_t ctlreg = read_i2c_register(PCF8523_ADDRESS, PCF8523_CONTROL_1); return !((ctlreg >> 5) & 1); } /**************************************************************************/ /*! @brief Read the mode of the INT/SQW pin on the PCF8523 @return SQW pin mode as a #Pcf8523SqwPinMode enum */ /**************************************************************************/ Pcf8523SqwPinMode RTC_PCF8523::readSqwPinMode() { int mode; Wire.beginTransmission(PCF8523_ADDRESS); Wire._I2C_WRITE(PCF8523_CLKOUTCONTROL); Wire.endTransmission(); Wire.requestFrom((uint8_t)PCF8523_ADDRESS, (uint8_t)1); mode = Wire._I2C_READ(); mode >>= 3; mode &= 0x7; return static_cast<Pcf8523SqwPinMode>(mode); } /**************************************************************************/ /*! @brief Set the INT/SQW pin mode on the PCF8523 @param mode The mode to set, see the #Pcf8523SqwPinMode enum for options */ /**************************************************************************/ void RTC_PCF8523::writeSqwPinMode(Pcf8523SqwPinMode mode) { Wire.beginTransmission(PCF8523_ADDRESS); Wire._I2C_WRITE(PCF8523_CLKOUTCONTROL); Wire._I2C_WRITE(mode << 3); // disables other timers Wire.endTransmission(); } /**************************************************************************/ /*! @brief Enable the Second Timer (1Hz) Interrupt on the PCF8523. @details The INT/SQW pin will pull low for a brief pulse once per second. */ /**************************************************************************/ void RTC_PCF8523::enableSecondTimer() { // Leave compatible settings intact uint8_t ctlreg = read_i2c_register(PCF8523_ADDRESS, PCF8523_CONTROL_1); uint8_t clkreg = read_i2c_register(PCF8523_ADDRESS, PCF8523_CLKOUTCONTROL); // TAM pulse int. mode (shared with Timer A), CLKOUT (aka SQW) disabled write_i2c_register(PCF8523_ADDRESS, PCF8523_CLKOUTCONTROL, clkreg | 0xB8); // SIE Second timer int. enable write_i2c_register(PCF8523_ADDRESS, PCF8523_CONTROL_1, ctlreg | (1 << 2)); } /**************************************************************************/ /*! @brief Disable the Second Timer (1Hz) Interrupt on the PCF8523. */ /**************************************************************************/ void RTC_PCF8523::disableSecondTimer() { // Leave compatible settings intact uint8_t ctlreg = read_i2c_register(PCF8523_ADDRESS, PCF8523_CONTROL_1); // SIE Second timer int. disable write_i2c_register(PCF8523_ADDRESS, PCF8523_CONTROL_1, ctlreg & ~(1 << 2)); } /**************************************************************************/ /*! @brief Enable the Countdown Timer Interrupt on the PCF8523. @details The INT/SQW pin will be pulled low at the end of a specified countdown period ranging from 244 microseconds to 10.625 days. Uses PCF8523 Timer B. Any existing CLKOUT square wave, configured with writeSqwPinMode(), will halt. The interrupt low pulse width is adjustable from 3/64ths (default) to 14/64ths of a second. @param clkFreq One of the PCF8523's Timer Source Clock Frequencies. See the #PCF8523TimerClockFreq enum for options and associated time ranges. @param numPeriods The number of clkFreq periods (1-255) to count down. @param lowPulseWidth Optional: the length of time for the interrupt pin low pulse. See the #PCF8523TimerIntPulse enum for options. */ /**************************************************************************/ void RTC_PCF8523::enableCountdownTimer(PCF8523TimerClockFreq clkFreq, uint8_t numPeriods, uint8_t lowPulseWidth) { // Datasheet cautions against updating countdown value while it's running, // so disabling allows repeated calls with new values to set new countdowns disableCountdownTimer(); // Leave compatible settings intact uint8_t ctlreg = read_i2c_register(PCF8523_ADDRESS, PCF8523_CONTROL_2); uint8_t clkreg = read_i2c_register(PCF8523_ADDRESS, PCF8523_CLKOUTCONTROL); // CTBIE Countdown Timer B Interrupt Enabled write_i2c_register(PCF8523_ADDRESS, PCF8523_CONTROL_2, ctlreg |= 0x01); // Timer B source clock frequency, optionally int. low pulse width write_i2c_register(PCF8523_ADDRESS, PCF8523_TIMER_B_FRCTL, lowPulseWidth << 4 | clkFreq); // Timer B value (number of source clock periods) write_i2c_register(PCF8523_ADDRESS, PCF8523_TIMER_B_VALUE, numPeriods); // TBM Timer B pulse int. mode, CLKOUT (aka SQW) disabled, TBC start Timer B write_i2c_register(PCF8523_ADDRESS, PCF8523_CLKOUTCONTROL, clkreg | 0x79); } /**************************************************************************/ /*! @overload @brief Enable Countdown Timer using default interrupt low pulse width. @param clkFreq One of the PCF8523's Timer Source Clock Frequencies. See the #PCF8523TimerClockFreq enum for options and associated time ranges. @param numPeriods The number of clkFreq periods (1-255) to count down. */ /**************************************************************************/ void RTC_PCF8523::enableCountdownTimer(PCF8523TimerClockFreq clkFreq, uint8_t numPeriods) { enableCountdownTimer(clkFreq, numPeriods, 0); } /**************************************************************************/ /*! @brief Disable the Countdown Timer Interrupt on the PCF8523. @details For simplicity, this function strictly disables Timer B by setting TBC to 0. The datasheet describes TBC as the Timer B on/off switch. Timer B is the only countdown timer implemented at this time. The following flags have no effect while TBC is off, they are *not* cleared: - TBM: Timer B will still be set to pulsed mode. - CTBIE: Timer B interrupt would be triggered if TBC were on. - CTBF: Timer B flag indicates that interrupt was triggered. Though typically used for non-pulsed mode, user may wish to query this later. */ /**************************************************************************/ void RTC_PCF8523::disableCountdownTimer() { // Leave compatible settings intact uint8_t clkreg = read_i2c_register(PCF8523_ADDRESS, PCF8523_CLKOUTCONTROL); // TBC disable to stop Timer B clock write_i2c_register(PCF8523_ADDRESS, PCF8523_CLKOUTCONTROL, ~1 & clkreg); } /**************************************************************************/ /*! @brief Stop all timers, clear their flags and settings on the PCF8523. @details This includes the Countdown Timer, Second Timer, and any CLKOUT square wave configured with writeSqwPinMode(). */ /**************************************************************************/ void RTC_PCF8523::deconfigureAllTimers() { disableSecondTimer(); // Surgically clears CONTROL_1 write_i2c_register(PCF8523_ADDRESS, PCF8523_CONTROL_2, 0); write_i2c_register(PCF8523_ADDRESS, PCF8523_CLKOUTCONTROL, 0); write_i2c_register(PCF8523_ADDRESS, PCF8523_TIMER_B_FRCTL, 0); write_i2c_register(PCF8523_ADDRESS, PCF8523_TIMER_B_VALUE, 0); } /**************************************************************************/ /*! @brief Compensate the drift of the RTC. @details This method sets the "offset" register of the PCF8523, which can be used to correct a previously measured drift rate. Two correction modes are available: - **PCF8523\_TwoHours**: Clock adjustments are performed on `offset` consecutive minutes every two hours. This is the most energy-efficient mode. - **PCF8523\_OneMinute**: Clock adjustments are performed on `offset` consecutive seconds every minute. Extra adjustments are performed on the last second of the minute is `abs(offset)>60`. The `offset` parameter sets the correction amount in units of roughly 4&nbsp;ppm. The exact unit depends on the selected mode: | mode | offset unit | |---------------------|----------------------------------------| | `PCF8523_TwoHours` | 4.340 ppm = 0.375 s/day = 2.625 s/week | | `PCF8523_OneMinute` | 4.069 ppm = 0.352 s/day = 2.461 s/week | See the accompanying sketch pcf8523.ino for an example on how to use this method. @param mode Correction mode, either `PCF8523_TwoHours` or `PCF8523_OneMinute`. @param offset Correction amount, from -64 to +63. A positive offset makes the clock slower. */ /**************************************************************************/ void RTC_PCF8523::calibrate(Pcf8523OffsetMode mode, int8_t offset) { uint8_t reg = (uint8_t)offset & 0x7F; reg |= mode; Wire.beginTransmission(PCF8523_ADDRESS); Wire._I2C_WRITE(PCF8523_OFFSET); Wire._I2C_WRITE(reg); Wire.endTransmission(); } // START RTC_PCF8563 implementation /**************************************************************************/ /*! @brief Start I2C for the PCF8563 and test succesful connection @return True if Wire can find PCF8563 or false otherwise. */ /**************************************************************************/ bool RTC_PCF8563::begin() { Wire.begin(); Wire.beginTransmission(PCF8563_ADDRESS); if (Wire.endTransmission() == 0) return true; return false; } /**************************************************************************/ /*! @brief Check the status of the VL bit in the VL_SECONDS register. @details The PCF8563 has an on-chip voltage-low detector. When VDD drops below Vlow, bit VL in the VL_seconds register is set to indicate that the integrity of the clock information is no longer guaranteed. @return True if the bit is set (VDD droped below Vlow) indicating that the clock integrity is not guaranteed and false only after the bit is cleared using adjust() */ /**************************************************************************/ bool RTC_PCF8563::lostPower() { return (read_i2c_register(PCF8563_ADDRESS, PCF8563_VL_SECONDS) >> 7); } /**************************************************************************/ /*! @brief Set the date and time @param dt DateTime to set */ /**************************************************************************/ void RTC_PCF8563::adjust(const DateTime &dt) { Wire.beginTransmission(PCF8563_ADDRESS); Wire._I2C_WRITE(PCF8563_VL_SECONDS); // start at location 2, VL_SECONDS Wire._I2C_WRITE(bin2bcd(dt.second())); Wire._I2C_WRITE(bin2bcd(dt.minute())); Wire._I2C_WRITE(bin2bcd(dt.hour())); Wire._I2C_WRITE(bin2bcd(dt.day())); Wire._I2C_WRITE(bin2bcd(0)); // skip weekdays Wire._I2C_WRITE(bin2bcd(dt.month())); Wire._I2C_WRITE(bin2bcd(dt.year() - 2000)); Wire.endTransmission(); } /**************************************************************************/ /*! @brief Get the current date/time @return DateTime object containing the current date/time */ /**************************************************************************/ DateTime RTC_PCF8563::now() { Wire.beginTransmission(PCF8563_ADDRESS); Wire._I2C_WRITE((byte)2); Wire.endTransmission(); Wire.requestFrom(PCF8563_ADDRESS, 7); uint8_t ss = bcd2bin(Wire._I2C_READ() & 0x7F); uint8_t mm = bcd2bin(Wire._I2C_READ() & 0x7F); uint8_t hh = bcd2bin(Wire._I2C_READ() & 0x3F); uint8_t d = bcd2bin(Wire._I2C_READ() & 0x3F); Wire._I2C_READ(); // skip 'weekdays' uint8_t m = bcd2bin(Wire._I2C_READ() & 0x1F); uint16_t y = bcd2bin(Wire._I2C_READ()) + 2000; return DateTime(y, m, d, hh, mm, ss); } /**************************************************************************/ /*! @brief Resets the STOP bit in register Control_1 */ /**************************************************************************/ void RTC_PCF8563::start() { uint8_t ctlreg = read_i2c_register(PCF8563_ADDRESS, PCF8563_CONTROL_1); if (ctlreg & (1 << 5)) { write_i2c_register(PCF8563_ADDRESS, PCF8563_CONTROL_1, ctlreg & ~(1 << 5)); } } /**************************************************************************/ /*! @brief Sets the STOP bit in register Control_1 */ /**************************************************************************/ void RTC_PCF8563::stop() { uint8_t ctlreg = read_i2c_register(PCF8563_ADDRESS, PCF8563_CONTROL_1); if (!(ctlreg & (1 << 5))) { write_i2c_register(PCF8523_ADDRESS, PCF8563_CONTROL_1, ctlreg | (1 << 5)); } } /**************************************************************************/ /*! @brief Is the PCF8563 running? Check the STOP bit in register Control_1 @return 1 if the RTC is running, 0 if not */ /**************************************************************************/ uint8_t RTC_PCF8563::isrunning() { uint8_t ctlreg = read_i2c_register(PCF8563_ADDRESS, PCF8563_CONTROL_1); return !((ctlreg >> 5) & 1); } /**************************************************************************/ /*! @brief Read the mode of the CLKOUT pin on the PCF8563 @return CLKOUT pin mode as a #Pcf8563SqwPinMode enum */ /**************************************************************************/ Pcf8563SqwPinMode RTC_PCF8563::readSqwPinMode() { int mode; Wire.beginTransmission(PCF8563_ADDRESS); Wire._I2C_WRITE(PCF8563_CLKOUTCONTROL); Wire.endTransmission(); Wire.requestFrom((uint8_t)PCF8563_ADDRESS, (uint8_t)1); mode = Wire._I2C_READ(); return static_cast<Pcf8563SqwPinMode>(mode & PCF8563_CLKOUT_MASK); } /**************************************************************************/ /*! @brief Set the CLKOUT pin mode on the PCF8563 @param mode The mode to set, see the #Pcf8563SqwPinMode enum for options */ /**************************************************************************/ void RTC_PCF8563::writeSqwPinMode(Pcf8563SqwPinMode mode) { Wire.beginTransmission(PCF8563_ADDRESS); Wire._I2C_WRITE(PCF8563_CLKOUTCONTROL); Wire._I2C_WRITE(mode); Wire.endTransmission(); } // END RTC_PCF8563 implementation /**************************************************************************/ /*! @brief Convert the day of the week to a representation suitable for storing in the DS3231: from 1 (Monday) to 7 (Sunday). @param d Day of the week as represented by the library: from 0 (Sunday) to 6 (Saturday). */ /**************************************************************************/ static uint8_t dowToDS3231(uint8_t d) { return d == 0 ? 7 : d; } /**************************************************************************/ /*! @brief Start I2C for the DS3231 and test succesful connection @return True if Wire can find DS3231 or false otherwise. */ /**************************************************************************/ bool RTC_DS3231::begin() { Wire.begin(); Wire.beginTransmission(DS3231_ADDRESS); if (Wire.endTransmission() == 0) return true; return false; } /**************************************************************************/ /*! @brief Check the status register Oscillator Stop Flag to see if the DS3231 stopped due to power loss @return True if the bit is set (oscillator stopped) or false if it is running */ /**************************************************************************/ bool RTC_DS3231::lostPower() { return (read_i2c_register(DS3231_ADDRESS, DS3231_STATUSREG) >> 7); } /**************************************************************************/ /*! @brief Set the date and flip the Oscillator Stop Flag @param dt DateTime object containing the date/time to set */ /**************************************************************************/ void RTC_DS3231::adjust(const DateTime &dt) { Wire.beginTransmission(DS3231_ADDRESS); Wire._I2C_WRITE((byte)DS3231_TIME); // start at location 0 Wire._I2C_WRITE(bin2bcd(dt.second())); Wire._I2C_WRITE(bin2bcd(dt.minute())); Wire._I2C_WRITE(bin2bcd(dt.hour())); // The RTC must know the day of the week for the weekly alarms to work. Wire._I2C_WRITE(bin2bcd(dowToDS3231(dt.dayOfTheWeek()))); Wire._I2C_WRITE(bin2bcd(dt.day())); Wire._I2C_WRITE(bin2bcd(dt.month())); Wire._I2C_WRITE(bin2bcd(dt.year() - 2000U)); Wire.endTransmission(); uint8_t statreg = read_i2c_register(DS3231_ADDRESS, DS3231_STATUSREG); statreg &= ~0x80; // flip OSF bit write_i2c_register(DS3231_ADDRESS, DS3231_STATUSREG, statreg); } /**************************************************************************/ /*! @brief Get the current date/time @return DateTime object with the current date/time */ /**************************************************************************/ DateTime RTC_DS3231::now() { Wire.beginTransmission(DS3231_ADDRESS); Wire._I2C_WRITE((byte)0); Wire.endTransmission(); Wire.requestFrom(DS3231_ADDRESS, 7); uint8_t ss = bcd2bin(Wire._I2C_READ() & 0x7F); uint8_t mm = bcd2bin(Wire._I2C_READ()); uint8_t hh = bcd2bin(Wire._I2C_READ()); Wire._I2C_READ(); uint8_t d = bcd2bin(Wire._I2C_READ()); uint8_t m = bcd2bin(Wire._I2C_READ()); uint16_t y = bcd2bin(Wire._I2C_READ()) + 2000U; return DateTime(y, m, d, hh, mm, ss); } /**************************************************************************/ /*! @brief Read the SQW pin mode @return Pin mode, see Ds3231SqwPinMode enum */ /**************************************************************************/ Ds3231SqwPinMode RTC_DS3231::readSqwPinMode() { int mode; Wire.beginTransmission(DS3231_ADDRESS); Wire._I2C_WRITE(DS3231_CONTROL); Wire.endTransmission(); Wire.requestFrom((uint8_t)DS3231_ADDRESS, (uint8_t)1); mode = Wire._I2C_READ(); mode &= 0x1C; if (mode & 0x04) mode = DS3231_OFF; return static_cast<Ds3231SqwPinMode>(mode); } /**************************************************************************/ /*! @brief Set the SQW pin mode @param mode Desired mode, see Ds3231SqwPinMode enum */ /**************************************************************************/ void RTC_DS3231::writeSqwPinMode(Ds3231SqwPinMode mode) { uint8_t ctrl; ctrl = read_i2c_register(DS3231_ADDRESS, DS3231_CONTROL); ctrl &= ~0x04; // turn off INTCON ctrl &= ~0x18; // set freq bits to 0 ctrl |= mode; write_i2c_register(DS3231_ADDRESS, DS3231_CONTROL, ctrl); // Serial.println( read_i2c_register(DS3231_ADDRESS, DS3231_CONTROL), HEX); } /**************************************************************************/ /*! @brief Get the current temperature from the DS3231's temperature sensor @return Current temperature (float) */ /**************************************************************************/ float RTC_DS3231::getTemperature() { uint8_t lsb; int8_t msb; Wire.beginTransmission(DS3231_ADDRESS); Wire._I2C_WRITE(DS3231_TEMPERATUREREG); Wire.endTransmission(); Wire.requestFrom(DS3231_ADDRESS, 2); msb = Wire._I2C_READ(); lsb = Wire._I2C_READ(); // Serial.print("msb="); // Serial.print(msb,HEX); // Serial.print(", lsb="); // Serial.println(lsb,HEX); return (float)msb + (lsb >> 6) * 0.25f; } /**************************************************************************/ /*! @brief Set alarm 1 for DS3231 @param dt DateTime object @param alarm_mode Desired mode, see Ds3231Alarm1Mode enum @return False if control register is not set, otherwise true */ /**************************************************************************/ bool RTC_DS3231::setAlarm1(const DateTime &dt, Ds3231Alarm1Mode alarm_mode) { uint8_t ctrl = read_i2c_register(DS3231_ADDRESS, DS3231_CONTROL); if (!(ctrl & 0x04)) { return false; } uint8_t A1M1 = (alarm_mode & 0x01) << 7; // Seconds bit 7. uint8_t A1M2 = (alarm_mode & 0x02) << 6; // Minutes bit 7. uint8_t A1M3 = (alarm_mode & 0x04) << 5; // Hour bit 7. uint8_t A1M4 = (alarm_mode & 0x08) << 4; // Day/Date bit 7. uint8_t DY_DT = (alarm_mode & 0x10) << 2; // Day/Date bit 6. Date when 0, day of week when 1. Wire.beginTransmission(DS3231_ADDRESS); Wire._I2C_WRITE(DS3231_ALARM1); Wire._I2C_WRITE(bin2bcd(dt.second()) | A1M1); Wire._I2C_WRITE(bin2bcd(dt.minute()) | A1M2); Wire._I2C_WRITE(bin2bcd(dt.hour()) | A1M3); if (DY_DT) { Wire._I2C_WRITE(bin2bcd(dowToDS3231(dt.dayOfTheWeek())) | A1M4 | DY_DT); } else { Wire._I2C_WRITE(bin2bcd(dt.day()) | A1M4 | DY_DT); } Wire.endTransmission(); ctrl |= 0x01; // AI1E write_i2c_register(DS3231_ADDRESS, DS3231_CONTROL, ctrl); return true; } /**************************************************************************/ /*! @brief Set alarm 2 for DS3231 @param dt DateTime object @param alarm_mode Desired mode, see Ds3231Alarm2Mode enum @return False if control register is not set, otherwise true */ /**************************************************************************/ bool RTC_DS3231::setAlarm2(const DateTime &dt, Ds3231Alarm2Mode alarm_mode) { uint8_t ctrl = read_i2c_register(DS3231_ADDRESS, DS3231_CONTROL); if (!(ctrl & 0x04)) { return false; } uint8_t A2M2 = (alarm_mode & 0x01) << 7; // Minutes bit 7. uint8_t A2M3 = (alarm_mode & 0x02) << 6; // Hour bit 7. uint8_t A2M4 = (alarm_mode & 0x04) << 5; // Day/Date bit 7. uint8_t DY_DT = (alarm_mode & 0x8) << 3; // Day/Date bit 6. Date when 0, day of week when 1. Wire.beginTransmission(DS3231_ADDRESS); Wire._I2C_WRITE(DS3231_ALARM2); Wire._I2C_WRITE(bin2bcd(dt.minute()) | A2M2); Wire._I2C_WRITE(bin2bcd(dt.hour()) | A2M3); if (DY_DT) { Wire._I2C_WRITE(bin2bcd(dowToDS3231(dt.dayOfTheWeek())) | A2M4 | DY_DT); } else { Wire._I2C_WRITE(bin2bcd(dt.day()) | A2M4 | DY_DT); } Wire.endTransmission(); ctrl |= 0x02; // AI2E write_i2c_register(DS3231_ADDRESS, DS3231_CONTROL, ctrl); return true; } /**************************************************************************/ /*! @brief Disable alarm @param alarm_num Alarm number to disable */ /**************************************************************************/ void RTC_DS3231::disableAlarm(uint8_t alarm_num) { uint8_t ctrl = read_i2c_register(DS3231_ADDRESS, DS3231_CONTROL); ctrl &= ~(1 << (alarm_num - 1)); write_i2c_register(DS3231_ADDRESS, DS3231_CONTROL, ctrl); } /**************************************************************************/ /*! @brief Clear status of alarm @param alarm_num Alarm number to clear */ /**************************************************************************/ void RTC_DS3231::clearAlarm(uint8_t alarm_num) { uint8_t status = read_i2c_register(DS3231_ADDRESS, DS3231_STATUSREG); status &= ~(0x1 << (alarm_num - 1)); write_i2c_register(DS3231_ADDRESS, DS3231_STATUSREG, status); } /**************************************************************************/ /*! @brief Get status of alarm @param alarm_num Alarm number to check status of @return True if alarm has been fired otherwise false */ /**************************************************************************/ bool RTC_DS3231::alarmFired(uint8_t alarm_num) { uint8_t status = read_i2c_register(DS3231_ADDRESS, DS3231_STATUSREG); return (status >> (alarm_num - 1)) & 0x1; } /**************************************************************************/ /*! @brief Enable 32KHz Output @details The 32kHz output is enabled by default. It requires an external pull-up resistor to function correctly */ /**************************************************************************/ void RTC_DS3231::enable32K() { uint8_t status = read_i2c_register(DS3231_ADDRESS, DS3231_STATUSREG); status |= (0x1 << 0x03); write_i2c_register(DS3231_ADDRESS, DS3231_STATUSREG, status); // Serial.println(read_i2c_register(DS3231_ADDRESS, DS3231_STATUSREG), BIN); } /**************************************************************************/ /*! @brief Disable 32KHz Output */ /**************************************************************************/ void RTC_DS3231::disable32K() { uint8_t status = read_i2c_register(DS3231_ADDRESS, DS3231_STATUSREG); status &= ~(0x1 << 0x03); write_i2c_register(DS3231_ADDRESS, DS3231_STATUSREG, status); // Serial.println(read_i2c_register(DS3231_ADDRESS, DS3231_STATUSREG), BIN); } /**************************************************************************/ /*! @brief Get status of 32KHz Output @return True if enabled otherwise false */ /**************************************************************************/ bool RTC_DS3231::isEnabled32K() { uint8_t status = read_i2c_register(DS3231_ADDRESS, DS3231_STATUSREG); return (status >> 0x03) & 0x1; }
; A054243: Number of partitions of n into distinct positive parts <= n, where parts are combined by XOR. ; 1,1,1,2,2,4,8,16,16,32,64,128,256,512,1024,2048,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,67108864,134217728,268435456,536870912,1073741824,2147483648,4294967296,8589934592,17179869184,34359738368,68719476736,137438953472,274877906944,549755813888,1099511627776,2199023255552,4398046511104,8796093022208,17592186044416,35184372088832,70368744177664,140737488355328,281474976710656,562949953421312,1125899906842624,2251799813685248,4503599627370496,9007199254740992,18014398509481984,36028797018963968,72057594037927936,144115188075855872,144115188075855872,288230376151711744,576460752303423488,1152921504606846976,2305843009213693952,4611686018427387904,9223372036854775808,18446744073709551616,36893488147419103232,73786976294838206464,147573952589676412928,295147905179352825856,590295810358705651712,1180591620717411303424,2361183241434822606848,4722366482869645213696,9444732965739290427392,18889465931478580854784,37778931862957161709568,75557863725914323419136,151115727451828646838272,302231454903657293676544,604462909807314587353088,1208925819614629174706176,2417851639229258349412352,4835703278458516698824704,9671406556917033397649408,19342813113834066795298816,38685626227668133590597632,77371252455336267181195264,154742504910672534362390528,309485009821345068724781056,618970019642690137449562112,1237940039285380274899124224,2475880078570760549798248448,4951760157141521099596496896 lpb $0 mov $1,2 add $2,$0 div $0,2 sub $2,1 sub $2,$0 lpe pow $1,$2 mov $0,$1
/* Note that the ZP being used here need to match the ZP of the pointer used by the IRQ loader */ exo_exo: lda $f0 sta opbase + 1 lda $f1 sta opbase + 2 jmp exod_decrunch exod_get_crunched_byte: lda opbase + 1 bne nowrap dec opbase + 2 nowrap: dec opbase + 1 opbase: lda $ffff rts // // Copyright (c) 2002 - 2019 Magnus Lind. // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from // the use of this software. // // Permission is granted to anyone to use this software for any purpose, // including commercial applications, and to alter it and redistribute it // freely, subject to the following restrictions: // // 1. The origin of this software must not be misrepresented// you must not // claim that you wrote the original software. If you use this software in a // product, an acknowledgment in the product documentation would be // appreciated but is not required. // // 2. Altered source versions must be plainly marked as such, and must not // be misrepresented as being the original software. // // 3. This notice may not be removed or altered from any distribution. // // 4. The names of this software and/or it's copyright holders may not be // used to endorse or promote products derived from this software without // specific prior written permission. // // ------------------------------------------------------------------- // Known quirks: // Can't handle a sequence reference that ends at $ffff. It is left in // since it is a corner case and fixing it impacts negatively on // performance or backwards compatibility. // A simple way to work around this is to not decrunch to address $ffff. // ------------------------------------------------------------------- // Controls if the shared get_bits routines should be inlined or not. //#define INLINE_GET_BITS // ------------------------------------------------------------------- // if literal sequences is not used (the data was crunched with the -c // flag) then the following line can be uncommented for shorter and. // slightly faster code. //#define LITERAL_SEQUENCES_NOT_USED // ------------------------------------------------------------------- // if the sequence length is limited to 256 (the data was crunched with // the -M256 flag) then the following line can be uncommented for // shorter and slightly faster code. //#define MAX_SEQUENCE_LENGTH_256 // ------------------------------------------------------------------- // if the sequence length 3 has its own offset table (the data was // crunched with the -P+16 flag) then the following // line must be uncommented. //#define EXTRA_TABLE_ENTRY_FOR_LENGTH_THREE // ------------------------------------------------------------------- // if sequence offsets are not reused (the data was crunched with the // -P-32 flag) then the following line must be uncommented. Uncommenting the // line will also result in shorter and slightly faster code. //#define DONT_REUSE_OFFSET // ------------------------------------------------------------------- // if decrunching forwards then the following line must be uncommented. //#define DECRUNCH_FORWARDS // ------------------------------------------------------------------- // if split encoding is used (the data is crunched with the -E flag) // then the following line must be uncommented. //#define ENABLE_SPLIT_ENCODING // ------------------------------------------------------------------- // The decruncher jsr:s to the exod_get_crunched_byte address when it wants to // read a crunched byte into A. This subroutine has to preserve X and Y // register and must not modify the state of the carry nor the overflow flag. // ------------------------------------------------------------------- // ------------------------------------------------------------------- // The exod_decrunch function is the heart of the decruncher. // It initializes the decruncher zeropage locations and precalculates the // decrunch tables and decrunches the data // This function will not change the interrupt status bit and it will not // modify the memory configuration. // ------------------------------------------------------------------- // ------------------------------------------------------------------- // zero page addresses used // ------------------------------------------------------------------- .label exod_zp_len_lo = $d0 .label exod_zp_len_hi = $d1 .label exod_zp_src_lo = $d2 .label exod_zp_src_hi = $d3 .label exod_zp_bits_hi = $d4 #if !DONT_REUSE_OFFSET .label exod_zp_ro_state = $d5 #endif .label exod_zp_bitbuf = $ed .label exod_zp_dest_lo = exod_zp_bitbuf + 1 // dest addr lo .label exod_zp_dest_hi = exod_zp_bitbuf + 2 // dest addr hi #if EXTRA_TABLE_ENTRY_FOR_LENGTH_THREE .label _encoded_entries = 68 #else .label _encoded_entries = 52 #endif .label _tabl_bi = exod_decrunch_table .label _tabl_lo = exod_decrunch_table + _encoded_entries .label _tabl_hi = exod_decrunch_table + _encoded_entries * 2 //// refill bits is always inlined .macro exod_mac_refill_bits() { pha jsr exod_get_crunched_byte rol sta exod_zp_bitbuf pla } .macro exod_mac_get_bits() { #if INLINE_GET_BITS adc #$80 // needs c=0, affects v asl bpl _gb_skip _gb_next: asl exod_zp_bitbuf bne _gb_ok :exod_mac_refill_bits() _gb_ok: rol bmi _gb_next _gb_skip: bvc _skip _gb_get_hi: sec sta exod_zp_bits_hi jsr exod_get_crunched_byte _skip: #else jsr exod_get_bits #endif } .macro exod_mac_init_zp() { // ------------------------------------------------------------------- // init zeropage and x reg. (8 bytes) // _init_zp: jsr exod_get_crunched_byte sta exod_zp_bitbuf - 1,x dex bne _init_zp } #if !INLINE_GET_BITS exod_get_bits: adc #$80 // needs c=0, affects v asl bpl _gb_skip _gb_next: asl exod_zp_bitbuf bne _gb_ok :exod_mac_refill_bits() _gb_ok: rol bmi _gb_next _gb_skip: bvs _gb_get_hi rts _gb_get_hi: sec sta exod_zp_bits_hi jmp exod_get_crunched_byte #endif // ------------------------------------------------------------------- // no code below this comment has to be modified in order to generate // a working decruncher of this source file. // However, you may want to relocate the tables last in the file to a // more suitable address. // ------------------------------------------------------------------- // ------------------------------------------------------------------- // jsr this label to decrunch, it will in turn init the tables and // call the decruncher // no constraints on register content, however the // decimal flag has to be cleared (it almost always is, otherwise do a cld) exod_decrunch: ldx #3 :exod_mac_init_zp() // ------------------------------------------------------------------- // calculate tables (64 bytes) + get_bits macro // x and y must be #0 when entering // ldy #0 clc _table_gen: tax tya and #$0f sta _tabl_lo,y beq _shortcut // start a new sequence // ------------------------------------------------------------------- txa adc _tabl_lo - 1,y sta _tabl_lo,y lda exod_zp_len_hi adc _tabl_hi - 1,y _shortcut: sta _tabl_hi,y // ------------------------------------------------------------------- lda #$01 sta <exod_zp_len_hi lda #$78 // %01111000 :exod_mac_get_bits() // ------------------------------------------------------------------- lsr tax beq _rolled php _rolle: asl exod_zp_len_hi sec ror dex bne _rolle plp _rolled: ror sta _tabl_bi,y bmi _no_fixup_lohi lda exod_zp_len_hi stx exod_zp_len_hi .byte $24 _no_fixup_lohi: txa // ------------------------------------------------------------------- iny cpy #_encoded_entries bne _table_gen // ------------------------------------------------------------------- #if ENABLE_SPLIT_ENCODING rts exod_split_decrunch: ldx #3 jsr _split_init_zp // X reg must be 0 here sec _normal_decrunch: #endif // ------------------------------------------------------------------- // prepare for main decruncher #if !DONT_REUSE_OFFSET ror exod_zp_ro_state sec #endif ldy exod_zp_dest_lo stx exod_zp_dest_lo stx exod_zp_bits_hi // ------------------------------------------------------------------- // copy one literal byte to destination (11 bytes) // _literal_start1: #if !DECRUNCH_FORWARDS tya bne _no_hi_decr dec exod_zp_dest_hi #if !DONT_REUSE_OFFSET dec exod_zp_src_hi #endif _no_hi_decr: dey #endif jsr exod_get_crunched_byte sta (exod_zp_dest_lo),y #if DECRUNCH_FORWARDS iny bne skip_hi_incr inc exod_zp_dest_hi #if !DONT_REUSE_OFFSET inc exod_zp_src_hi #endif skip_hi_incr: #endif // ------------------------------------------------------------------- // fetch sequence length index (15 bytes) // x must be #0 when entering and contains the length index + 1 // when exiting or 0 for literal byte _next_round: #if !DONT_REUSE_OFFSET ror exod_zp_ro_state #endif dex lda exod_zp_bitbuf _no_literal1: asl bne _nofetch8 jsr exod_get_crunched_byte rol _nofetch8: inx bcc _no_literal1 sta exod_zp_bitbuf // ------------------------------------------------------------------- // check for literal byte (2 bytes) // beq _literal_start1 // ------------------------------------------------------------------- // check for decrunch done and literal sequences (4 bytes) // cpx #$11 #if INLINE_GET_BITS bcc _skip_jmp jmp _exit_or_lit_seq _skip_jmp: #else bcs _exit_or_lit_seq #endif // ------------------------------------------------------------------- // calulate length of sequence (zp_len) (18(11) bytes) + get_bits macro // lda _tabl_bi - 1,x :exod_mac_get_bits() adc _tabl_lo - 1,x // we have now calculated zp_len_lo sta exod_zp_len_lo #if !MAX_SEQUENCE_LENGTH_256 lda exod_zp_bits_hi adc _tabl_hi - 1,x // c = 0 after this. sta exod_zp_len_hi // ------------------------------------------------------------------- // here we decide what offset table to use (27(26) bytes) + get_bits_nc macro // z-flag reflects zp_len_hi here // ldx exod_zp_len_lo #else tax #endif #if !MAX_SEQUENCE_LENGTH_256 lda #0 #endif #if !DONT_REUSE_OFFSET // ------------------------------------------------------------------- // here we decide to reuse latest offset or not (13(15) bytes) // bit <exod_zp_ro_state bmi _test_reuse _no_reuse: #endif // ------------------------------------------------------------------- // here we decide what offset table to use (17(15) bytes) // #if !MAX_SEQUENCE_LENGTH_256 sta <exod_zp_bits_hi #endif lda #$e1 #if EXTRA_TABLE_ENTRY_FOR_LENGTH_THREE cpx #$04 #else cpx #$03 #endif bcs _gbnc2_next lda _tabl_bit - 1,x _gbnc2_next: asl exod_zp_bitbuf bne _gbnc2_ok tax jsr exod_get_crunched_byte rol sta exod_zp_bitbuf txa _gbnc2_ok: rol bcs _gbnc2_next tax // ------------------------------------------------------------------- // calulate absolute offset (zp_src) (17 bytes) + get_bits macro // lda _tabl_bi,x :exod_mac_get_bits() #if !DECRUNCH_FORWARDS adc _tabl_lo,x sta exod_zp_src_lo lda exod_zp_bits_hi adc _tabl_hi,x adc exod_zp_dest_hi sta exod_zp_src_hi #else clc adc _tabl_lo,x eor #$ff sta exod_zp_src_lo lda exod_zp_bits_hi adc _tabl_hi,x eor #$ff adc exod_zp_dest_hi sta exod_zp_src_hi clc #endif // ------------------------------------------------------------------- // prepare for copy loop (2 bytes) // ldx exod_zp_len_lo // ------------------------------------------------------------------- // main copy loop (30 bytes) // _copy_next: #if !DECRUNCH_FORWARDS tya bne _copy_skip_hi dec exod_zp_dest_hi dec exod_zp_src_hi _copy_skip_hi: dey #endif #if !LITERAL_SEQUENCES_NOT_USED bcs _get_literal_byte #endif lda (exod_zp_src_lo),y _literal_byte_gotten: sta (exod_zp_dest_lo),y #if DECRUNCH_FORWARDS iny bne copy_skip_hi inc exod_zp_dest_hi inc exod_zp_src_hi copy_skip_hi: #endif dex bne _copy_next #if !MAX_SEQUENCE_LENGTH_256 lda exod_zp_len_hi #if INLINE_GET_BITS bne _copy_next_hi #endif #endif stx exod_zp_bits_hi #if !INLINE_GET_BITS beq _next_round #else jmp _next_round #endif #if !MAX_SEQUENCE_LENGTH_256 _copy_next_hi: dec exod_zp_len_hi jmp _copy_next #endif #if !DONT_REUSE_OFFSET // ------------------------------------------------------------------- // test for offset reuse (11 bytes) // _test_reuse: bvs _no_reuse #if MAX_SEQUENCE_LENGTH_256 lda #$00 // fetch one bit #endif asl exod_zp_bitbuf bne _gbnc1_ok pha jsr exod_get_crunched_byte rol sta exod_zp_bitbuf pla _gbnc1_ok: rol beq _no_reuse // bit == 0 => C=0, no reuse bne _copy_next // bit != 0 => C=0, reuse previous offset #endif // ------------------------------------------------------------------- // exit or literal sequence handling (16(12) bytes) // _exit_or_lit_seq: #if !LITERAL_SEQUENCES_NOT_USED beq _decr_exit jsr exod_get_crunched_byte #if !MAX_SEQUENCE_LENGTH_256 sta exod_zp_len_hi #endif jsr exod_get_crunched_byte tax bcs _copy_next _decr_exit: #endif rts #if !LITERAL_SEQUENCES_NOT_USED _get_literal_byte: jsr exod_get_crunched_byte bcs _literal_byte_gotten #endif rts #if EXTRA_TABLE_ENTRY_FOR_LENGTH_THREE // ------------------------------------------------------------------- // the static stable used for bits+offset for lengths 1, 2 and 3 (3 bytes) // bits 2, 4, 4 and offsets 64, 48, 32 corresponding to // %10010000, %11100011, %11100010 _tabl_bit: .byte $90, $e3, $e2 #else // ------------------------------------------------------------------- // the static stable used for bits+offset for lengths 1 and 2 (2 bytes) // bits 2, 4 and offsets 48, 32 corresponding to %10001100, %11100010 _tabl_bit: .byte $8c, $e2 #endif // ------------------------------------------------------------------- // end of decruncher // ------------------------------------------------------------------- // ------------------------------------------------------------------- // this 156 (204) byte table area may be relocated. It may also be // clobbered by other data between decrunches. // ------------------------------------------------------------------- exod_decrunch_table: .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 #if EXTRA_TABLE_ENTRY_FOR_LENGTH_THREE .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 #endif .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .byte 0,0,0,0,0,0,0,0,0,0,0,0 // ------------------------------------------------------------------- // end of decruncher // -------------------------------------------------------------------
; A134298: a(n) = (107*n)^5. ; 0,14025517307,448816553824,3408200705601,14362129722368,43829741584375,109062422579232,235726869378749,459588151115776,828192771461043,1402551730700000,2258823587809657,3489997522535424,5207576397467951 pow $0,5 mul $0,14025517307
#include <iostream> #include <climits> using namespace std; int main(){ // Program to find max and minimum number from the list // take min = infinity // take max = minus infinity int min = INT_MAX; int max = INT_MIN; int n,no; cin>>n; for(int i=0;i<n;i++){ cin>>no; if(no<min){ min = no; } if(no>max){ max = no; } } cout<<"The min is : "<<min<<endl; cout<<"The max is : "<<max<<endl; return 0; }
; A265100: a(n) = 9*A005836(n) + 5, n >= 1. ; 5,14,32,41,86,95,113,122,248,257,275,284,329,338,356,365,734,743,761,770,815,824,842,851,977,986,1004,1013,1058,1067,1085,1094,2192,2201,2219,2228,2273,2282,2300,2309,2435,2444,2462,2471,2516,2525 mov $35,$0 mov $37,$0 lpb $37 mov $0,$35 sub $37,1 sub $0,$37 mov $31,$0 mov $33,2 lpb $33 clr $0,31 mov $0,$31 sub $33,1 add $0,$33 sub $0,1 mov $27,$0 add $27,1 mov $28,$0 lpb $27 clr $0,25 sub $27,1 sub $0,$27 lpb $0 gcd $0,1073741824 add $3,3 lpb $0 div $0,2 mul $3,3 lpe mov $2,$3 lpe mov $1,$2 div $1,6 add $26,$1 lpe mov $1,$26 add $1,$28 mov $34,$33 lpb $34 mov $32,$1 sub $34,1 lpe lpe lpb $31 mov $31,0 sub $32,$1 lpe mov $1,$32 mul $1,2 add $1,2 add $36,$1 lpe mov $1,$36 div $1,6 mul $1,9 add $1,5
; A056084: Numbers k such that k^8 == 1 (mod 9^3). ; 1,728,730,1457,1459,2186,2188,2915,2917,3644,3646,4373,4375,5102,5104,5831,5833,6560,6562,7289,7291,8018,8020,8747,8749,9476,9478,10205,10207,10934,10936,11663,11665,12392,12394,13121,13123,13850,13852,14579,14581,15308,15310,16037,16039,16766,16768,17495,17497,18224,18226,18953,18955,19682,19684,20411,20413,21140,21142,21869,21871,22598,22600,23327,23329,24056,24058,24785,24787,25514,25516,26243,26245,26972,26974,27701,27703,28430,28432,29159,29161,29888,29890,30617,30619,31346,31348,32075,32077,32804,32806,33533,33535,34262,34264,34991,34993,35720,35722,36449,36451,37178,37180,37907,37909,38636,38638,39365,39367,40094,40096,40823,40825,41552,41554,42281,42283,43010,43012,43739,43741,44468,44470,45197,45199,45926,45928,46655,46657,47384,47386,48113,48115,48842,48844,49571,49573,50300,50302,51029,51031,51758,51760,52487,52489,53216,53218,53945,53947,54674,54676,55403,55405,56132,56134,56861,56863,57590,57592,58319,58321,59048,59050,59777,59779,60506,60508,61235,61237,61964,61966,62693,62695,63422,63424,64151,64153,64880,64882,65609,65611,66338,66340,67067,67069,67796,67798,68525,68527,69254,69256,69983,69985,70712,70714,71441,71443,72170,72172,72899,72901,73628,73630,74357,74359,75086,75088,75815,75817,76544,76546,77273,77275,78002,78004,78731,78733,79460,79462,80189,80191,80918,80920,81647,81649,82376,82378,83105,83107,83834,83836,84563,84565,85292,85294,86021,86023,86750,86752,87479,87481,88208,88210,88937,88939,89666,89668,90395,90397,91124 mov $1,3 mov $2,$0 lpb $0 add $0,1 trn $0,3 add $1,725 lpe sub $1,2 mov $3,$2 mul $3,2 add $1,$3
; A220753: Expansion of (1+4*x+5*x^2-x^3)/((1-x)*(1+x)*(1-2*x^2)). ; 1,4,8,11,22,25,50,53,106,109,218,221,442,445,890,893,1786,1789,3578,3581,7162,7165,14330,14333,28666,28669,57338,57341,114682,114685,229370,229373,458746,458749,917498,917501,1835002,1835005,3670010,3670013 mov $1,1 mov $2,$0 lpb $2 add $1,3 sub $2,1 mov $3,$2 lpb $3 mul $1,2 mov $3,0 lpe trn $2,1 lpe mov $0,$1
global _start section .data align 16 quad1: dq 0x70ad80ad7fffffff quad2: dq 0x71ae01ff0f00ffbe quad3: dq 0xf100808080f0ff42 quad4: dq 0xffffffffffffffff mydword: dd 0xcafebabe myaddress: dq 0x00adbeefc0de00ce %include "header.inc" movq mm0, [quad1] movq mm1, [quad2] movq mm2, [quad3] movq mm3, [quad2] movq mm4, [quad4] psubd mm0, [quad2] psubd mm0, [quad1] psubd mm1, mm2 psubd mm2, [quad1] psubd mm3, [quad1] psubd mm4, [quad4] %include "footer.inc"
.686p ;BT、BTS、BTR、BTC: 位测试指令 ;BT(Bit Test): 位测试 ;BTS(Bit Test and Set): 位测试并置位 ;BTR(Bit Test and Reset): 位测试并复位 ;BTC(Bit Test and Complement): 位测试并取反 ;它们的结果影响 CF DATA_BREAKPOINT EQU 1 PORT_BREAKPOINT equ 2 INSTRUCTION_BREAKPOINT EQU 3 BD_BREAKPOINT EQU 4 BS_BREAKPOINT EQU 5 BT_BREAKPOINT EQU 6 INT3_BREAKPOINT EQU 7 ;当处理器进行算术操作时,如果最高位有向前进位或借位的情况发生,则 CF=1;否则 CF=0。 ;假定你进行的是有符号数运算,如果结果超出了目标操作数所能容纳的范围,OF=1;否则,OF=0。 ;mov ah,0x70 ;add ah,ah ;OF=1 Kernel segment para use32 assume cs:Kernel align 10h __tDebugProc proc pushad push ds push es mov ax,rwData32Seg mov ds,ax mov es,ax mov ebx,kernelData shl ebx,4 CMP dword ptr ds:[ebx + _kDebugger],0 JZ _debugIntShowErr mov eax, esp add eax,8 push eax call dword ptr ds:[ebx + _kDebugger] add esp,4 _debuggerProcEnd: pop es pop ds popad ;1 每次成功执行一条指令把RF清零 ;2 iretd不会把RF清零 ;3 RF==1,忽略调试故障和陷阱,RF==0,不忽略,引起中断故障处理程序执行 ;4 发生非调试故障时RF==1,发生调试故障时RF==0 ;bts dword ptr ss:[esp + 8],16 iretd __tDebugProc endp _debugIntShowErr: mov ebp,esp add ebp,32 add ebp,8 push dword ptr 1 push dword ptr 0 push dword ptr [ebp] push dword ptr [ebp + 4] push dword ptr [ebp + 8] test dword ptr [ebp + 4],3 jz _ktDebugKernelModeInt push dword ptr [ebp + 12] push dword ptr [ebp + 16] jmp _ktDebugShowExpInfo _ktDebugKernelModeInt: push dword ptr 0 push dword ptr 0 _ktDebugShowExpInfo: call __exceptionInfo add esp,28 jmp _debuggerProcEnd align 10h __tBreakPointProc proc pushad push ds push es mov ax,rwData32Seg mov ds,ax mov es,ax mov ebx,kernelData shl ebx,4 cmp dword ptr ds:[ebx + _kBreakPoint],0 jz __breakPointProcNotExist mov eax, esp add eax,8 push eax call dword ptr ds:[ebx + _kBreakPoint] add esp,4 jmp __tBreakPointProcEnd __breakPointProcNotExist: mov ebp,esp add ebp,32 add ebp,8 push dword ptr 3 push dword ptr 0 push dword ptr [ebp] push dword ptr [ebp + 4] push dword ptr [ebp + 8] test dword ptr [ebp + 4],3 jz _ktBreadPointKernelModeInt push dword ptr [ebp + 12] push dword ptr [ebp + 16] jmp _ktBreadPointShowExpInfo _ktBreadPointKernelModeInt: push dword ptr 0 push dword ptr 0 _ktBreadPointShowExpInfo: call __exceptionInfo add esp,28 __tBreakPointProcEnd: pop es pop ds popad iretd __tBreakPointProc endp Kernel ends
IDEAL ASSUME CS:SEG1,DS:SEG1,ES:SEG1,SS:SEG1 SEGMENT SEG1 PUBLIC mov bx, OFFSET thing mov al, 42 add dl, ch thing: int 21h ENDS END
<% import collections import pwnlib.abi import pwnlib.constants import pwnlib.shellcraft import six %> <%docstring>socketpair(domain, type, protocol, fds) -> str Invokes the syscall socketpair. See 'man 2 socketpair' for more information. Arguments: domain(int): domain type(int): type protocol(int): protocol fds(int*): fds Returns: int </%docstring> <%page args="domain=0, type=0, protocol=0, fds=0"/> <% abi = pwnlib.abi.ABI.syscall() stack = abi.stack regs = abi.register_arguments[1:] allregs = pwnlib.shellcraft.registers.current() can_pushstr = [] can_pushstr_array = [] argument_names = ['domain', 'type', 'protocol', 'fds'] argument_values = [domain, type, protocol, fds] # Load all of the arguments into their destination registers / stack slots. register_arguments = dict() stack_arguments = collections.OrderedDict() string_arguments = dict() dict_arguments = dict() array_arguments = dict() syscall_repr = [] for name, arg in zip(argument_names, argument_values): if arg is not None: syscall_repr.append('%s=%r' % (name, arg)) # If the argument itself (input) is a register... if arg in allregs: index = argument_names.index(name) if index < len(regs): target = regs[index] register_arguments[target] = arg elif arg is not None: stack_arguments[index] = arg # The argument is not a register. It is a string value, and we # are expecting a string value elif name in can_pushstr and isinstance(arg, (six.binary_type, six.text_type)): if isinstance(arg, six.text_type): arg = arg.encode('utf-8') string_arguments[name] = arg # The argument is not a register. It is a dictionary, and we are # expecting K:V paris. elif name in can_pushstr_array and isinstance(arg, dict): array_arguments[name] = ['%s=%s' % (k,v) for (k,v) in arg.items()] # The arguent is not a register. It is a list, and we are expecting # a list of arguments. elif name in can_pushstr_array and isinstance(arg, (list, tuple)): array_arguments[name] = arg # The argument is not a register, string, dict, or list. # It could be a constant string ('O_RDONLY') for an integer argument, # an actual integer value, or a constant. else: index = argument_names.index(name) if index < len(regs): target = regs[index] register_arguments[target] = arg elif arg is not None: stack_arguments[target] = arg # Some syscalls have different names on various architectures. # Determine which syscall number to use for the current architecture. for syscall in ['SYS_socketpair']: if hasattr(pwnlib.constants, syscall): break else: raise Exception("Could not locate any syscalls: %r" % syscalls) %> /* socketpair(${', '.join(syscall_repr)}) */ %for name, arg in string_arguments.items(): ${pwnlib.shellcraft.pushstr(arg, append_null=(b'\x00' not in arg))} ${pwnlib.shellcraft.mov(regs[argument_names.index(name)], abi.stack)} %endfor %for name, arg in array_arguments.items(): ${pwnlib.shellcraft.pushstr_array(regs[argument_names.index(name)], arg)} %endfor %for name, arg in stack_arguments.items(): ${pwnlib.shellcraft.push(arg)} %endfor ${pwnlib.shellcraft.setregs(register_arguments)} ${pwnlib.shellcraft.syscall(syscall)}
/*************************************************************************/ /* sample_library.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ /* */ /* 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 "sample_library.h" bool SampleLibrary::_set(const StringName& p_name, const Variant& p_value) { if (String(p_name).begins_with("samples/")) { String name=String(p_name).get_slicec('/',1); if (p_value.get_type()==Variant::NIL) sample_map.erase(name); else { SampleData sd; if (p_value.get_type()==Variant::OBJECT) sd.sample=p_value; else if (p_value.get_type()==Variant::DICTIONARY) { Dictionary d = p_value; ERR_FAIL_COND_V(!d.has("sample"),false); ERR_FAIL_COND_V(!d.has("pitch"),false); ERR_FAIL_COND_V(!d.has("db"),false); sd.sample=d["sample"]; sd.pitch_scale=d["pitch"]; sd.db=d["db"]; } sample_map[name]=sd; } return true; } return false; } bool SampleLibrary::_get(const StringName& p_name,Variant &r_ret) const { if (String(p_name).begins_with("samples/")) { String name=String(p_name).get_slicec('/',1); if(sample_map.has(name)) { Dictionary d; d["sample"]=sample_map[name].sample; d["pitch"]=sample_map[name].pitch_scale; d["db"]=sample_map[name].db; r_ret=d; } else { return false; } return true; } return false; } void SampleLibrary::add_sample(const StringName& p_name, const Ref<Sample>& p_sample) { ERR_FAIL_COND(p_sample.is_null()); SampleData sd; sd.sample=p_sample; sample_map[p_name]=sd; } Ref<Sample> SampleLibrary::get_sample(const StringName& p_name) const { ERR_FAIL_COND_V(!sample_map.has(p_name),Ref<Sample>()); return sample_map[p_name].sample; } void SampleLibrary::remove_sample(const StringName& p_name) { sample_map.erase(p_name); } void SampleLibrary::get_sample_list(List<StringName> *p_samples) { for(Map<StringName,SampleData >::Element *E=sample_map.front();E;E=E->next()) { p_samples->push_back(E->key()); } } bool SampleLibrary::has_sample(const StringName& p_name) const { return sample_map.has(p_name); } void SampleLibrary::_get_property_list(List<PropertyInfo> *p_list) const { for(Map<StringName,SampleData>::Element *E=sample_map.front();E;E=E->next()) { p_list->push_back( PropertyInfo( Variant::DICTIONARY, "samples/"+E->key(),PROPERTY_HINT_RESOURCE_TYPE,"Sample",PROPERTY_USAGE_NOEDITOR ) ); } } StringName SampleLibrary::get_sample_idx(int p_idx) const { int idx=0; for (Map<StringName, SampleData >::Element *E=sample_map.front();E;E=E->next()) { if (p_idx==idx) return E->key(); idx++; } return ""; } void SampleLibrary::sample_set_volume_db(const StringName& p_name, float p_db) { ERR_FAIL_COND( !sample_map.has(p_name) ); sample_map[p_name].db=p_db; } float SampleLibrary::sample_get_volume_db(const StringName& p_name) const{ ERR_FAIL_COND_V( !sample_map.has(p_name),0 ); return sample_map[p_name].db; } void SampleLibrary::sample_set_pitch_scale(const StringName& p_name, float p_pitch){ ERR_FAIL_COND( !sample_map.has(p_name) ); sample_map[p_name].pitch_scale=p_pitch; } float SampleLibrary::sample_get_pitch_scale(const StringName& p_name) const{ ERR_FAIL_COND_V( !sample_map.has(p_name),0 ); return sample_map[p_name].pitch_scale; } void SampleLibrary::_bind_methods() { ObjectTypeDB::bind_method(_MD("add_sample","name","sample:Sample"),&SampleLibrary::add_sample ); ObjectTypeDB::bind_method(_MD("get_sample:Sample","name"),&SampleLibrary::get_sample ); ObjectTypeDB::bind_method(_MD("has_sample","name"),&SampleLibrary::has_sample ); ObjectTypeDB::bind_method(_MD("remove_sample","name"),&SampleLibrary::remove_sample ); ObjectTypeDB::bind_method(_MD("sample_set_volume_db","name","db"),&SampleLibrary::sample_set_volume_db ); ObjectTypeDB::bind_method(_MD("sample_get_volume_db","name"),&SampleLibrary::sample_get_volume_db ); ObjectTypeDB::bind_method(_MD("sample_set_pitch_scale","name","pitch"),&SampleLibrary::sample_set_pitch_scale ); ObjectTypeDB::bind_method(_MD("sample_get_pitch_scale","name"),&SampleLibrary::sample_get_pitch_scale ); } SampleLibrary::SampleLibrary() { }
;------------------------------------------------------------------------------ ; ; Copyright (c) 2006, Intel Corporation. All rights reserved.<BR> ; This program and the accompanying materials ; are licensed and made available under the terms and conditions of the BSD License ; which accompanies this distribution. The full text of the license may be found at ; http://opensource.org/licenses/bsd-license.php. ; ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. ; ; Module Name: ; ; ReadMm3.Asm ; ; Abstract: ; ; AsmReadMm3 function ; ; Notes: ; ;------------------------------------------------------------------------------ SECTION .text ;------------------------------------------------------------------------------ ; UINT64 ; EFIAPI ; AsmReadMm3 ( ; VOID ; ); ;------------------------------------------------------------------------------ global ASM_PFX(AsmReadMm3) ASM_PFX(AsmReadMm3): push eax push eax movq [esp], mm3 pop eax pop edx ret
; A020338: Doublets: base-10 representation is the juxtaposition of two identical strings. ; 11,22,33,44,55,66,77,88,99,1010,1111,1212,1313,1414,1515,1616,1717,1818,1919,2020,2121,2222,2323,2424,2525,2626,2727,2828,2929,3030,3131,3232,3333,3434,3535,3636,3737,3838,3939,4040,4141,4242,4343,4444,4545,4646,4747,4848,4949,5050,5151,5252,5353,5454,5555,5656,5757,5858,5959,6060,6161,6262,6363,6464,6565,6666,6767,6868,6969,7070,7171,7272,7373,7474,7575,7676,7777,7878,7979,8080,8181,8282,8383,8484,8585,8686,8787,8888,8989,9090,9191,9292,9393,9494,9595,9696,9797,9898,9999,100100 mov $3,$0 add $0,1 mov $2,$0 lpb $2 mul $0,10 div $2,10 lpe add $0,$3 add $0,1
// Free and unknown voxel data, bound to each free or unknown voxel in hash table #ifndef free_unk_data_hh #define free_unk_data_hh //_//_//_//_//_//_//_//_//_//_//_//_//_//_//_//_//_//_//_//_//_//_//_//_//_//_// struct free_unk_data { int hits; free_unk_data() : hits(0), sr_extent(1) {} }; #endif
; A267708: Triangle read by rows giving successive states of cellular automaton generated by "Rule 206" initiated with a single ON (black) cell. ; 1,1,1,0,1,1,1,0,0,1,1,1,1,0,0,0,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0 mov $1,1 lpb $0,1 sub $0,$2 mov $1,$0 trn $0,1 trn $1,$0 add $2,1 trn $0,$2 lpe
; A106826: Trajectory of 1 under the morphism 1->{2,1}, 2->{2,3}, 3->{4,3}, 4->{4,1}. ; 2,3,4,3,4,1,4,3,4,1,2,1,4,1,4,3,4,1,2,1,2,3,2,1,4,1,2,1,4,1,4,3,4,1,2,1,2,3,2,1,2,3,4,3,2,3,2,1,4,1,2,1,2,3,2,1,4,1,2,1,4,1,4,3,4,1,2,1,2,3,2,1,2,3,4,3,2,3,2,1,2,3,4,3,4,1,4,3,2,3,4,3,2,3,2,1,4,1,2,1 seq $0,88748 ; a(n) = 1 + Sum_{k=0..n-1} 2 * A014577(k) - 1. mod $0,4 add $0,1
// // Generated by Microsoft (R) HLSL Shader Compiler 9.30.9200.16384 // // /// // Buffer Definitions: // // cbuffer cbCS // { // // uint g_tex_width; // Offset: 0 Size: 4 [unused] // uint g_num_block_x; // Offset: 4 Size: 4 // uint g_format; // Offset: 8 Size: 4 [unused] // uint g_mode_id; // Offset: 12 Size: 4 // uint g_start_block_id; // Offset: 16 Size: 4 // uint g_num_total_blocks; // Offset: 20 Size: 4 [unused] // // } // // Resource bind info for g_InBuff // { // // uint4 $Element; // Offset: 0 Size: 16 // // } // // Resource bind info for g_OutBuff // { // // uint4 $Element; // Offset: 0 Size: 16 // // } // // // Resource Bindings: // // Name Type Format Dim Slot Elements // ------------------------------ ---------- ------- ----------- ---- -------- // g_Input texture float4 2d 0 1 // g_InBuff texture struct r/o 1 1 // g_OutBuff UAV struct r/w 0 1 // cbCS cbuffer NA NA 0 1 // // // // Input signature: // // Name Index Mask Register SysValue Format Used // -------------------- ----- ------ -------- -------- ------- ------ // no Input // // Output signature: // // Name Index Mask Register SysValue Format Used // -------------------- ----- ------ -------- -------- ------- ------ // no Output cs_4_0 dcl_globalFlags refactoringAllowed dcl_immediateConstantBuffer { { 0x0000cccc, 15, 0, -649211347377382870000000000000000.000000}, { 0x00008888, 15, 0, 10184774488364746000000000000000.000000}, { 0x0000eeee, 15, 0, 0.000000}, { 0x0000ecc8, 15, 0, 0.000000}, { 0x0000c880, 15, 0, -33606656.000000}, { 0x0000feec, 15, 0, -33555248.000000}, { 0x0000fec8, 15, 0, 0.000000}, { 0x0000ec80, 15, 0, 0.000000}, { 0x0000c800, 15, 0, -158528860577705550000000000000.000000}, { 0x0000ffec, 15, 0, -158533394049529110000000000000.000000}, { 0x0000fe80, 15, 0, -170146051238774110000000000000000000000.000000}, { 0x0000e800, 15, 0, -0.000000}, { 0x0000ffe8, 15, 0, -0.000000}, { 0x0000ff00, 15, 0, -107024656.000000}, { 0x0000fff0, 15, 0, -1238673776977656100000000000.000000}, { 0x0000f000, 15, 0, 11409024651668811000000000000000.000000}, { 0x0000f710, 15, 0, -131291.125000}, { 142, 2, 0, 0.000000}, { 0x00007100, 8, 0, -100768128.000000}, { 2254, 2, 0, 0.000000}, { 140, 2, 0, -9903801295088772900000000000.000000}, { 0x00007310, 8, 0, 2606965549330689500000000000000000.000000}, { 0x00003100, 8, 0, -33590016.000000}, { 0x00008cce, 15, 0, 0.000000}, { 2188, 2, 0, 0.000000}, { 0x00003110, 8, 0, -5649748860036787900000000000000000000.000000}, { 0x00006666, 2, 0, 0.000000}, { 0x0000366c, 2, 0, 151823044794904950000000.000000}, { 6120, 8, 0, -286745.500000}, { 4080, 8, 0, -41538879947814649000000000000000000.000000}, { 0x0000718e, 2, 0, 0.000000}, { 0x0000399c, 2, 0, 11452183303429053000000000000000.000000}, { 0x0000aaaa, 15, 0, -1238657838990776500000000000.000000}, { 0x0000f0f0, 15, 0, 0.000000}, { 0x00005a5a, 6, 0, -1237951254905777100000000000.000000}, { 0x000033cc, 8, 0, 784.533325}, { 0x00003c3c, 2, 0, 0.000000}, { 0x000055aa, 8, 0, 672329.125000}, { 0x00009696, 15, 0, 74.080582}, { 0x0000a55a, 15, 0, 0.000000}, { 0x000073ce, 2, 0, 0.000000}, { 5064, 8, 0, -170144631470101850000000000000000000000.000000}, { 0x0000324c, 2, 0, 8841727049728.000000}, { 0x00003bdc, 2, 0, -107053440.000000}, { 0x00006996, 2, 0, 0.000000}, { 0x0000c33c, 15, 0, 272202749625043510000000.000000}, { 0x00009966, 15, 0, 0.000000}, { 1632, 6, 0, 14339452960768.000000}, { 626, 6, 0, -158507893270521610000000000000.000000}, { 1252, 2, 0, 0.000000}, { 0x00004e40, 6, 0, -0.000000}, { 0x00002720, 8, 0, -0.000000}, { 0x0000c936, 15, 0, -40945461174657352000.000000}, { 0x0000936c, 15, 0, -0.000000}, { 0x000039c6, 2, 0, -158487265973724440000000000000.000000}, { 0x0000639c, 2, 0, -0.000000}, { 0x00009336, 15, 0, -170143252266248800000000000000000000000.000000}, { 0x00009cc6, 15, 0, -2.188278}, { 0x0000817e, 15, 0, -106961280.000000}, { 0x0000e718, 15, 0, -0.000000}, { 0x0000ccf0, 15, 0, 0.000000}, { 4044, 2, 0, -36838425354228843000000000000.000000}, { 0x00007744, 2, 0, 0xfff0000a}, { 0x0000ee22, 15, 0, 11411580320851476000000000000000.000000}, { 0, 3, 15, 0}, { 0, 3, 8, 4}, { 0, 15, 8, 9}, { 1, 15, 3, 13}, { 1, 8, 15, 17}, { 1, 3, 15, 21}, { 1, 15, 3, 26}, { 2, 15, 8, 30}, { 2, 8, 15, 34}, { 2, 8, 15, 38}, { 2, 6, 15, 43}, { 2, 6, 15, 47}, { 3, 6, 15, 51}, { 3, 5, 15, 55}, { 3, 3, 15, 60}, { 3, 3, 8, 64}, { 4, 3, 15, 0}, { 4, 3, 8, 9}, { 4, 8, 15, 18}, { 4, 15, 3, 27}, { 5, 3, 15, 37}, { 5, 3, 8, 46}, { 5, 6, 15, 55}, { 5, 10, 8, 64}, { 6, 5, 3, 0}, { 6, 8, 15, 0}, { 6, 8, 6, 0}, { 6, 6, 10, 0}, { 6, 8, 15, 0}, { 7, 5, 15, 0}, { 7, 15, 10, 0}, { 7, 15, 8, 0}, { 7, 8, 15, 0}, { 8, 15, 3, 21}, { 8, 3, 15, 43}, { 8, 5, 10, 64}, { 8, 6, 10, 0}, { 9, 10, 8, 0}, { 9, 8, 9, 0}, { 9, 15, 10, 0}, { 9, 15, 6, 0}, { 10, 3, 15, 0}, { 10, 15, 8, 0}, { 10, 5, 15, 0}, { 10, 15, 3, 0}, { 10, 15, 6, 0}, { 11, 15, 6, 0}, { 11, 15, 8, 0}, { 11, 3, 15, 0}, { 11, 15, 3, 0}, { 12, 5, 15, 0}, { 12, 5, 15, 0}, { 12, 5, 15, 0}, { 12, 8, 15, 0}, { 13, 5, 15, 0}, { 13, 10, 15, 0}, { 13, 5, 15, 0}, { 13, 10, 15, 0}, { 14, 8, 15, 0}, { 14, 13, 15, 0}, { 14, 15, 3, 0}, { 14, 12, 15, 0}, { 15, 3, 15, 0}, { 15, 3, 8, 0}, { 0, 0, 0, 0}, { 0, 0, 0, 0}, { 0, 0, 0, 0}, { 0, 0, 0, 0}, { 0, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 2, 0, 0, 0}, { 2, 0, 0, 0}, { 2, 0, 0, 0}, { 2, 0, 0, 0}, { 2, 0, 0, 0}, { 2, 0, 0, 0}, { 2, 0, 0, 0}, { 2, 0, 0, 0}, { 2, 0, 0, 0}, { 3, 0, 0, 0}, { 3, 0, 0, 0}, { 3, 0, 0, 0}, { 3, 0, 0, 0}, { 3, 0, 0, 0}, { 3, 0, 0, 0}, { 3, 0, 0, 0}, { 3, 0, 0, 0}, { 3, 0, 0, 0}, { 3, 0, 0, 0}, { 4, 0, 0, 0}, { 4, 0, 0, 0}, { 4, 0, 0, 0}, { 4, 0, 0, 0}, { 4, 0, 0, 0}, { 4, 0, 0, 0}, { 4, 0, 0, 0}, { 4, 0, 0, 0}, { 4, 0, 0, 0}, { 5, 0, 0, 0}, { 5, 0, 0, 0}, { 5, 0, 0, 0}, { 5, 0, 0, 0}, { 5, 0, 0, 0}, { 5, 0, 0, 0}, { 5, 0, 0, 0}, { 5, 0, 0, 0}, { 5, 0, 0, 0}, { 6, 0, 0, 0}, { 6, 0, 0, 0}, { 6, 0, 0, 0}, { 6, 0, 0, 0}, { 6, 0, 0, 0}, { 6, 0, 0, 0}, { 6, 0, 0, 0}, { 6, 0, 0, 0}, { 6, 0, 0, 0}, { 7, 0, 0, 0}, { 7, 0, 0, 0}, { 7, 0, 0, 0}, { 7, 0, 0, 0}, { 0, 0, 0, 0}, { 0, 0, 0, 0}, { 0, 0, 0, 0}, { 0, 0, 0, 0}, { 0, 0, 0, 0}, { 0, 0, 0, 0}, { 0, 0, 0, 0}, { 0, 0, 0, 0}, { 0, 0, 0, 0}, { 0, 0, 0, 0}, { 0, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 1, 0, 0, 0}, { 2, 0, 0, 0}, { 2, 0, 0, 0}, { 2, 0, 0, 0}, { 2, 0, 0, 0}, { 2, 0, 0, 0}, { 2, 0, 0, 0}, { 2, 0, 0, 0}, { 2, 0, 0, 0}, { 2, 0, 0, 0}, { 2, 0, 0, 0}, { 2, 0, 0, 0}, { 2, 0, 0, 0}, { 2, 0, 0, 0}, { 2, 0, 0, 0}, { 2, 0, 0, 0}, { 2, 0, 0, 0}, { 2, 0, 0, 0}, { 2, 0, 0, 0}, { 2, 0, 0, 0}, { 2, 0, 0, 0}, { 2, 0, 0, 0}, { 3, 0, 0, 0}, { 3, 0, 0, 0}, { 3, 0, 0, 0}, { 3, 0, 0, 0}, { 3, 0, 0, 0}, { 3, 0, 0, 0}, { 3, 0, 0, 0}, { 3, 0, 0, 0}, { 3, 0, 0, 0}, { 3, 0, 0, 0} } dcl_constantbuffer cb0[2], immediateIndexed dcl_resource_texture2d (float,float,float,float) t0 dcl_resource_structured t1, 16 dcl_uav_structured u0, 16 dcl_input vThreadIDInGroupFlattened dcl_input vThreadGroupID.x dcl_temps 14 dcl_indexableTemp x0[8], 4 dcl_tgsm_structured g0, 68, 64 dcl_thread_group 64, 1, 1 iadd r0.x, vThreadGroupID.x, cb0[1].x ult r1.xyzw, vThreadIDInGroupFlattened.xxxx, l(16, 32, 8, 4) if_nz r1.x udiv r0.y, null, r0.x, cb0[0].y imad r0.z, -r0.y, cb0[0].y, r0.x ishl r0.z, r0.z, l(2) ishl r0.y, r0.y, l(2) and r0.w, vThreadIDInGroupFlattened.x, l(3) iadd r2.x, r0.w, r0.z ushr r0.z, vThreadIDInGroupFlattened.x, l(2) iadd r2.y, r0.z, r0.y mov r2.zw, l(0,0,0,0) ld r2.xyzw, r2.xyzw, t0.xyzw mul r2.xyzw, r2.xyzw, l(255.000000, 255.000000, 255.000000, 255.000000) ftou r2.xyzw, r2.xyzw umin r2.xyzw, r2.xyzw, l(255, 255, 255, 255) store_structured g0.xyzw, vThreadIDInGroupFlattened.x, l(0), r2.xyzw endif sync_g_t mov x0[0].x, l(-1) mov x0[1].x, l(-1) mov x0[2].x, l(-1) mov x0[3].x, l(-1) mov x0[0].y, l(0) mov x0[1].y, l(0) mov x0[2].y, l(0) mov x0[3].y, l(0) mov x0[4].x, l(-1) mov x0[5].x, l(-1) mov x0[6].x, l(-1) mov x0[7].x, l(-1) mov x0[4].y, l(0) mov x0[5].y, l(0) mov x0[6].y, l(0) mov x0[7].y, l(0) mov r0.y, l(0) loop uge r0.z, r0.y, l(16) breakc_nz r0.z ld_structured r2.xyzw, r0.y, l(0), g0.xyzw mov r0.z, vThreadIDInGroupFlattened.x ushr r0.z, icb[r0.z + 0].x, r0.y and r0.z, r0.z, l(1) ieq r0.z, r0.z, l(1) if_nz r0.z mov r3.x, x0[4].x mov r3.y, x0[5].x mov r3.z, x0[6].x mov r3.w, x0[7].x umin r3.xyzw, r2.xyzw, r3.xyzw mov x0[4].x, r3.x mov x0[5].x, r3.y mov x0[6].x, r3.z mov x0[7].x, r3.w mov r3.x, x0[4].y mov r3.y, x0[5].y mov r3.z, x0[6].y mov r3.w, x0[7].y umax r3.xyzw, r2.xyzw, r3.xyzw mov x0[4].y, r3.x mov x0[5].y, r3.y mov x0[6].y, r3.z mov x0[7].y, r3.w else mov r3.x, x0[0].x mov r3.y, x0[1].x mov r3.z, x0[2].x mov r3.w, x0[3].x umin r3.xyzw, r2.xyzw, r3.xyzw mov x0[0].x, r3.x mov x0[1].x, r3.y mov x0[2].x, r3.z mov x0[3].x, r3.w mov r3.x, x0[0].y mov r3.y, x0[1].y mov r3.z, x0[2].y mov r3.w, x0[3].y umax r2.xyzw, r2.xyzw, r3.xyzw mov x0[0].y, r2.x mov x0[1].y, r2.y mov x0[2].y, r2.z mov x0[3].y, r2.w endif iadd r0.y, r0.y, l(1) endloop ieq r0.yz, cb0[0].wwww, l(0, 1, 7, 0) if_nz r0.y mov r2.x, x0[0].x mov r2.y, x0[1].x mov r2.z, x0[2].x mov r3.x, x0[0].y mov r3.y, x0[1].y mov r3.z, x0[2].y and r4.xyz, r2.xyzx, l(3, 3, 3, 0) and r5.xyz, r3.xyzx, l(3, 3, 3, 0) iadd r4.xyz, r4.xyzx, r5.xyzx iadd r0.y, r4.z, r4.y iadd r0.y, r0.y, r4.x udiv r0.y, null, r0.y, l(6) and r0.y, r0.y, l(2) and r2.xyz, r2.xyzx, l(252, 252, 252, 0) iadd r2.xzw, r0.yyyy, r2.zzxy and r3.xyz, r3.xyzx, l(252, 252, 252, 0) iadd r3.xyz, r0.yyyy, r3.yxzy mov r2.y, r3.z mov r3.w, r2.w mov r0.yw, r3.wwwx mov r3.x, r2.z mov r4.x, x0[4].x mov r4.y, x0[5].x mov r4.z, x0[6].x mov r5.x, x0[4].y mov r5.y, x0[5].y mov r5.z, x0[6].y and r6.xyz, r4.xyzx, l(3, 3, 3, 0) and r7.xyz, r5.xyzx, l(3, 3, 3, 0) iadd r6.xyz, r6.xyzx, r7.xyzx iadd r4.w, r6.z, r6.y iadd r4.w, r4.w, r6.x udiv r4.w, null, r4.w, l(6) and r4.xyzw, r4.xyzw, l(252, 252, 252, 2) iadd r6.xzw, r4.wwww, r4.zzxy and r4.xyz, r5.xyzx, l(252, 252, 252, 0) iadd r4.xyz, r4.wwww, r4.yxzy mov r6.y, r4.z mov r4.w, r6.w mov r5.xy, r4.wxww mov r4.x, r6.z else ieq r5.z, cb0[0].w, l(3) if_nz r5.z mov r7.x, x0[0].x mov r7.y, x0[1].x mov r7.z, x0[2].x mov r8.x, x0[0].y mov r8.y, x0[1].y mov r8.z, x0[2].y and r9.xyz, r7.xyzx, l(1, 1, 1, 0) iadd r5.w, r9.z, r9.y iadd r5.w, r5.w, r9.x and r7.xyz, r7.xyzx, l(254, 254, 254, 0) udiv r5.w, null, r5.w, l(3) iadd r2.xzw, r5.wwww, r7.zzxy and r7.xyz, r8.xyzx, l(1, 1, 1, 0) iadd r5.w, r7.z, r7.y iadd r5.w, r5.w, r7.x and r7.xyz, r8.xyzx, l(254, 254, 254, 0) udiv r5.w, null, r5.w, l(3) iadd r3.xyz, r5.wwww, r7.yxzy mov r2.y, r3.z mov r3.w, r2.w mov r0.yw, r3.wwwx mov r3.x, r2.z else mov r7.x, x0[0].x mov r7.y, x0[1].x mov r7.z, x0[2].x mov r7.w, x0[3].x mov r8.x, x0[0].y mov r8.y, x0[1].y mov r8.z, x0[2].y mov r8.w, x0[3].y and r9.xyzw, r7.xyzw, l(7, 7, 7, 7) iadd r2.z, r9.z, r9.y iadd r2.z, r9.w, r2.z iadd r2.z, r2.z, r9.x and r7.xyzw, r7.xyzw, l(248, 248, 248, 248) ushr r2.z, r2.z, l(2) and r2.z, r2.z, l(4) iadd r7.xyzw, r2.zzzz, r7.xyzw and r9.xyzw, r8.xyzw, l(7, 7, 7, 7) iadd r2.z, r9.z, r9.y iadd r2.z, r9.w, r2.z iadd r2.z, r2.z, r9.x and r8.xyzw, r8.xyzw, l(248, 248, 248, 248) ushr r2.z, r2.z, l(2) and r2.z, r2.z, l(4) iadd r3.xyzw, r2.zzzz, r8.yxzw mov x0[3].x, r7.w mov x0[3].y, r3.w mov r2.x, r7.z mov r2.y, r3.z mov r0.y, r7.y mov r0.w, r3.x mov r3.x, r7.x endif if_nz r5.z mov r7.x, x0[4].x mov r7.y, x0[5].x mov r7.z, x0[6].x mov r8.x, x0[4].y mov r8.y, x0[5].y mov r8.z, x0[6].y and r9.xyz, r7.xyzx, l(1, 1, 1, 0) iadd r2.z, r9.z, r9.y iadd r2.z, r2.z, r9.x and r7.xyz, r7.xyzx, l(254, 254, 254, 0) udiv r2.z, null, r2.z, l(3) iadd r6.xzw, r2.zzzz, r7.zzxy and r7.xyz, r8.xyzx, l(1, 1, 1, 0) iadd r2.z, r7.z, r7.y iadd r2.z, r2.z, r7.x and r7.xyz, r8.xyzx, l(254, 254, 254, 0) udiv r2.z, null, r2.z, l(3) iadd r4.xyz, r2.zzzz, r7.yxzy mov r6.y, r4.z mov r4.w, r6.w mov r5.xy, r4.wxww mov r4.x, r6.z else mov r7.x, x0[4].x mov r7.y, x0[5].x mov r7.z, x0[6].x mov r7.w, x0[7].x mov r8.x, x0[4].y mov r8.y, x0[5].y mov r8.z, x0[6].y mov r8.w, x0[7].y and r9.xyzw, r7.xyzw, l(7, 7, 7, 7) iadd r2.z, r9.z, r9.y iadd r2.z, r9.w, r2.z iadd r2.z, r2.z, r9.x and r7.xyzw, r7.xyzw, l(248, 248, 248, 248) ushr r2.z, r2.z, l(2) and r2.z, r2.z, l(4) iadd r7.xyzw, r2.zzzz, r7.xyzw and r9.xyzw, r8.xyzw, l(7, 7, 7, 7) iadd r2.z, r9.z, r9.y iadd r2.z, r9.w, r2.z iadd r2.z, r2.z, r9.x and r8.xyzw, r8.xyzw, l(248, 248, 248, 248) ushr r2.z, r2.z, l(2) and r2.z, r2.z, l(4) iadd r4.xyzw, r2.zzzz, r8.yxzw mov x0[7].x, r7.w mov x0[7].y, r4.w mov r6.x, r7.z mov r6.y, r4.z mov r5.x, r7.y mov r5.y, r4.x mov r4.x, r7.x endif endif mov r7.w, x0[3].y mov r2.z, x0[3].x ineg r8.x, r3.x ineg r8.y, r0.y ineg r8.zw, r2.xxxz mov r7.x, r3.y mov r7.y, r0.w mov r7.z, r2.y iadd r9.xyzw, r7.xyzw, r8.xyzw mov r10.w, x0[7].y mov r2.w, x0[7].x ineg r11.x, r4.x ineg r11.y, r5.x ineg r11.z, r6.x ineg r11.w, r2.w mov r10.x, r4.y mov r10.y, r5.y mov r10.z, r6.y iadd r12.xyzw, r10.xyzw, r11.xyzw ine r3.zw, cb0[0].wwww, l(0, 0, 7, 1) movc r12.w, r3.z, l(0), r12.w movc r9.w, r3.z, l(0), r9.w imul null, r4.zw, r9.xxxy, r9.xxxy iadd r4.z, r4.w, r4.z imad r4.z, r9.z, r9.z, r4.z imad r4.z, r9.w, r9.w, r4.z imul null, r5.zw, r12.xxxy, r12.xxxy iadd r4.w, r5.w, r5.z imad r4.w, r12.z, r12.z, r4.w imad r4.w, r12.w, r12.w, r4.w ld_structured r13.xyzw, l(0), l(0), g0.xyzw iadd r8.xyzw, r8.xyzw, r13.xyzw imul null, r5.zw, r8.xxxy, r9.xxxy iadd r5.z, r5.w, r5.z imad r5.z, r9.z, r8.z, r5.z imad r5.z, r9.w, r8.w, r5.z ilt r5.w, l(0), r4.z ilt r6.z, l(0), r5.z and r5.w, r5.w, r6.z itof r5.z, r5.z mul r5.z, r5.z, l(63.499989) ftou r5.z, r5.z ishl r6.z, r4.z, l(5) ult r5.z, r6.z, r5.z and r5.z, r5.z, r5.w ineg r8.xyzw, r9.xyzw movc r8.xyzw, r5.zzzz, r8.xyzw, r9.xyzw movc r3.xy, r5.zzzz, r3.yxyy, r3.xyxx mov x0[0].x, r3.x movc r0.yw, r5.zzzz, r0.wwwy, r0.yyyw mov x0[1].x, r0.y movc r2.xy, r5.zzzz, r2.yxyy, r2.xyxx mov x0[2].x, r2.x movc r5.w, r5.z, r7.w, r2.z mov x0[3].x, r5.w mov x0[0].y, r3.y mov x0[1].y, r0.w mov x0[2].y, r2.y movc r0.w, r5.z, r2.z, r7.w mov x0[3].y, r0.w mov r0.w, vThreadIDInGroupFlattened.x mov r2.y, icb[r0.w + 0].y ld_structured r7.xyzw, r2.y, l(0), g0.xyzw iadd r7.xyzw, r11.xyzw, r7.xyzw imul null, r2.yz, r7.xxyx, r12.xxyx iadd r2.y, r2.z, r2.y imad r2.y, r12.z, r7.z, r2.y imad r2.y, r12.w, r7.w, r2.y ilt r2.z, l(0), r4.w ilt r3.y, l(0), r2.y and r2.z, r2.z, r3.y itof r2.y, r2.y mul r2.y, r2.y, l(63.499989) ftou r2.y, r2.y ishl r3.y, r4.w, l(5) ult r2.y, r3.y, r2.y and r2.y, r2.y, r2.z ineg r7.xyzw, r12.xyzw movc r7.xyzw, r2.yyyy, r7.xyzw, r12.xyzw movc r4.xy, r2.yyyy, r4.yxyy, r4.xyxx mov x0[4].x, r4.x movc r5.xy, r2.yyyy, r5.yxyy, r5.xyxx mov x0[5].x, r5.x movc r6.xy, r2.yyyy, r6.yxyy, r6.xyxx mov x0[6].x, r6.x movc r2.z, r2.y, r10.w, r2.w mov x0[7].x, r2.z mov x0[4].y, r4.y mov x0[5].y, r5.y mov x0[6].y, r6.y movc r2.y, r2.y, r2.w, r10.w mov x0[7].y, r2.y ineg r9.x, r4.x ineg r9.y, r5.x ineg r9.z, r6.x ineg r9.w, r2.z ige r2.y, l(0), r4.w ineg r6.x, r3.x ineg r6.y, r0.y ineg r6.z, r2.x ineg r6.w, r5.w ige r0.y, l(0), r4.z itof r2.xz, r4.zzwz movc r3.xyw, r3.wwww, l(128,3,0,32), l(64,7,0,16) mov r5.xy, l(0,0,0,0) loop uge r2.w, r5.y, l(16) breakc_nz r2.w ushr r2.w, icb[r0.w + 0].x, r5.y and r2.w, r2.w, l(1) ieq r4.x, r2.w, l(1) if_nz r4.x ld_structured r10.xyzw, r5.y, l(0), g0.xyzw iadd r10.xyzw, r9.xyzw, r10.xyzw imul null, r4.xy, r7.xyxx, r10.xyxx iadd r4.x, r4.y, r4.x imad r4.x, r7.z, r10.z, r4.x imad r4.x, r7.w, r10.w, r4.x ige r4.y, l(0), r4.x or r4.y, r2.y, r4.y ilt r5.w, r4.x, r4.w itof r4.x, r4.x mul r4.x, r4.x, l(63.499989) div r4.x, r4.x, r2.z ftou r4.x, r4.x iadd r4.x, r3.x, r4.x movc r4.x, r5.w, icb[r4.x + 64].x, r3.y movc r4.x, r4.y, l(0), r4.x else ld_structured r10.xyzw, r5.y, l(0), g0.xyzw iadd r10.xyzw, r6.xyzw, r10.xyzw imul null, r10.xy, r8.xyxx, r10.xyxx iadd r4.y, r10.y, r10.x imad r4.y, r8.z, r10.z, r4.y imad r4.y, r8.w, r10.w, r4.y ige r5.w, l(0), r4.y or r5.w, r0.y, r5.w ilt r10.x, r4.y, r4.z itof r4.y, r4.y mul r4.y, r4.y, l(63.499989) div r4.y, r4.y, r2.x ftou r4.y, r4.y iadd r4.y, r3.x, r4.y movc r4.y, r10.x, icb[r4.y + 64].x, r3.y movc r4.x, r5.w, l(0), r4.y endif iadd r10.yz, r5.yyyy, l(0, 15, 1, 0) ushr r4.y, icb[r0.w + 0].w, r10.y and r4.y, r4.y, l(2) ushr r5.w, icb[r0.w + 0].w, r5.y and r5.w, r5.w, l(1) iadd r4.y, r4.y, r5.w movc r2.w, r0.z, r2.w, r4.y iadd r4.x, r3.w, r4.x iadd r4.y, l(64), -icb[r4.x + 64].w ishl r2.w, r2.w, l(2) mov r11.x, x0[r2.w + 0].x mov r11.y, x0[r2.w + 1].x mov r11.z, x0[r2.w + 2].x mov r11.w, x0[r2.w + 3].x mov r12.x, x0[r2.w + 0].y mov r12.y, x0[r2.w + 1].y mov r12.z, x0[r2.w + 2].y mov r12.w, x0[r2.w + 3].y imul null, r12.xyzw, r12.xyzw, icb[r4.x + 64].wwww imad r11.xyzw, r4.yyyy, r11.xyzw, r12.xyzw iadd r11.xyzw, r11.xyzw, l(32, 32, 32, 32) ushr r11.xyzw, r11.xyzw, l(6) ld_structured r12.xyzw, r5.y, l(0), g0.xyzw iadd r11.xyzw, r11.xyzw, -r12.xyzw movc r2.w, r3.z, l(0), r11.w imul null, r4.xy, r11.xyxx, r11.xyxx iadd r4.x, r4.y, r4.x imad r4.x, r11.z, r11.z, r4.x imad r2.w, r2.w, r2.w, r4.x iadd r10.x, r2.w, r5.x mov r5.xy, r10.xzxx endloop mov r5.y, cb0[0].w mov r5.z, vThreadIDInGroupFlattened.x store_structured g0.xyz, vThreadIDInGroupFlattened.x, l(16), r5.xyzx sync_g_t if_nz r1.y iadd r0.y, vThreadIDInGroupFlattened.x, l(32) ld_structured r2.yzw, r0.y, l(16), g0.xxyz ult r0.z, r2.y, r5.x if_nz r0.z ld_structured r2.x, r0.y, l(16), g0.xxxx store_structured g0.xyz, vThreadIDInGroupFlattened.x, l(16), r2.xzwx endif endif if_nz r1.x ld_structured r2.x, vThreadIDInGroupFlattened.x, l(16), g0.xxxx iadd r0.y, vThreadIDInGroupFlattened.x, l(16) ld_structured r3.yzw, r0.y, l(16), g0.xxyz ult r0.z, r3.y, r2.x if_nz r0.z ld_structured r3.x, r0.y, l(16), g0.xxxx store_structured g0.xyz, vThreadIDInGroupFlattened.x, l(16), r3.xzwx endif endif if_nz r1.z ld_structured r2.x, vThreadIDInGroupFlattened.x, l(16), g0.xxxx iadd r0.y, vThreadIDInGroupFlattened.x, l(8) ld_structured r3.yzw, r0.y, l(16), g0.xxyz ult r0.z, r3.y, r2.x if_nz r0.z ld_structured r3.x, r0.y, l(16), g0.xxxx store_structured g0.xyz, vThreadIDInGroupFlattened.x, l(16), r3.xzwx endif endif if_nz r1.w ld_structured r1.x, vThreadIDInGroupFlattened.x, l(16), g0.xxxx iadd r0.y, vThreadIDInGroupFlattened.x, l(4) ld_structured r2.yzw, r0.y, l(16), g0.xxyz ult r0.z, r2.y, r1.x if_nz r0.z ld_structured r2.x, r0.y, l(16), g0.xxxx store_structured g0.xyz, vThreadIDInGroupFlattened.x, l(16), r2.xzwx endif endif ult r0.yz, vThreadIDInGroupFlattened.xxxx, l(0, 2, 1, 0) if_nz r0.y ld_structured r1.x, vThreadIDInGroupFlattened.x, l(16), g0.xxxx iadd r0.y, vThreadIDInGroupFlattened.x, l(2) ld_structured r2.yzw, r0.y, l(16), g0.xxyz ult r0.w, r2.y, r1.x if_nz r0.w ld_structured r2.x, r0.y, l(16), g0.xxxx store_structured g0.xyz, vThreadIDInGroupFlattened.x, l(16), r2.xzwx endif endif if_nz r0.z ld_structured r1.x, vThreadIDInGroupFlattened.x, l(16), g0.xxxx iadd r0.y, vThreadIDInGroupFlattened.x, l(1) ld_structured r2.yzw, r0.y, l(16), g0.xxyz ult r0.z, r2.y, r1.x if_nz r0.z ld_structured r2.x, r0.y, l(16), g0.xxxx store_structured g0.xyz, vThreadIDInGroupFlattened.x, l(16), r2.xzwx endif ld_structured r1.x, r0.x, l(0), t1.xxxx ld_structured r2.x, vThreadIDInGroupFlattened.x, l(16), g0.xxxx ult r0.y, r2.x, r1.x if_nz r0.y ld_structured r1.xyz, vThreadIDInGroupFlattened.x, l(16), g0.xyzx mov r1.w, l(0) else ld_structured r1.xyzw, r0.x, l(0), t1.xyzw endif store_structured u0.xyzw, r0.x, l(0), r1.xyzw endif ret // Approximately 496 instruction slots used
; A164120: Partial sums of A162396. ; 5,7,17,21,41,49,89,105,185,217,377,441,761,889,1529,1785,3065,3577,6137,7161,12281,14329,24569,28665,49145,57337,98297,114681,196601,229369,393209,458745,786425,917497,1572857,1835001,3145721,3670009,6291449,7340025,12582905,14680057,25165817,29360121,50331641,58720249,100663289,117440505,201326585,234881017,402653177,469762041,805306361,939524089,1610612729,1879048185,3221225465,3758096377,6442450937,7516192761,12884901881,15032385529,25769803769,30064771065,51539607545,60129542137,103079215097,120259084281,206158430201,240518168569,412316860409,481036337145,824633720825,962072674297,1649267441657,1924145348601,3298534883321,3848290697209,6597069766649,7696581394425,13194139533305,15393162788857,26388279066617,30786325577721,52776558133241,61572651155449,105553116266489,123145302310905,211106232532985,246290604621817,422212465065977,492581209243641,844424930131961,985162418487289,1688849860263929,1970324836974585,3377699720527865,3940649673949177,6755399441055737,7881299347898361 mov $3,$0 mod $0,2 add $0,1 mov $1,$0 mul $3,2 add $3,2 mov $0,$3 sub $0,1 mov $2,18 add $2,$1 add $0,$2 add $0,3 lpb $0,1 sub $0,4 mul $1,2 add $1,5 lpe sub $1,190 div $1,64 mul $1,2 add $1,1
;------------------------------------------------------------------------------ ; ; Copyright (c) 2019, Intel Corporation. All rights reserved.<BR> ; SPDX-License-Identifier: BSD-2-Clause-Patent ; ;------------------------------------------------------------------------------- %include "Nasm.inc" DEFAULT REL SECTION .text global ASM_PFX(DisableCet) ASM_PFX(DisableCet): ; Skip the pushed data for call mov rax, 1 INCSSP_RAX mov rax, cr4 btr eax, 23 ; clear CET mov cr4, rax ret global ASM_PFX(EnableCet) ASM_PFX(EnableCet): mov rax, cr4 bts eax, 23 ; set CET mov cr4, rax ; use jmp to skip the check for ret pop rax jmp rax
;// demo2.asm ;// ;// Copyright (C)2005-2012 The NASMX Project ;// ;// Purpose: ;// This program demonstrates how to use command line ;// arguments and how to use the stack for storing values. ;// ;// Contributors: ;// Bryant Keller ;// Rob Neff ;// %include 'nasmx.inc' %include 'bsd/libc.inc' ENTRY demo2 SECTION .text proc demo2, ptrdiff_t count, ptrdiff_t cmdline locals local index, uint32_t endlocals mov esi, dword [argv(.cmdline)] mov ecx, dword [argv(.count)] dec ecx mov eax, 4 .scan_args: push ecx cmp ecx, 0 je .done ;// decrement arg count dec ecx ;// get ptr to next string mov ebx, dword [esi + eax] or ebx, ebx je .done ;// index to next arg and save add eax, 4 mov dword [var(.index)], eax ;// call puts to display string invoke puts, ebx mov eax, dword [var(.index)] pop ecx jmp .scan_args .done: pop ecx xor eax, eax invoke exit, eax endproc
; A041494: Numerators of continued fraction convergents to sqrt(264). ; Submitted by Jon Maiga ; 16,65,2096,8449,272464,1098305,35418224,142771201,4604096656,18559157825,598497147056,2412547746049,77800025020624,313612647828545,10113404755534064,40767231669964801,1314664818194407696,5299426504447595585,170896312960517466416,688884678346517461249,22215206020049076226384,89549708758542822366785,2887805886293419391963504,11640773253932220390220801,375392550012124471879029136,1513210973302430107906337345,48798143695689887924881824176,196705785756061981807433634049 add $0,1 mov $3,1 lpb $0 sub $0,1 add $2,$3 mov $3,$1 mov $1,$2 dif $2,8 mul $2,16 add $3,$2 lpe mov $0,$3