1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
/* <copyright>
This file is provided under a dual BSD/GPLv2 license. When using or
redistributing this file, you may do so under either license.
GPL LICENSE SUMMARY
Copyright (c) 2017-2020 Intel Corporation. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation.
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 St - Fifth Floor, Boston, MA 02110-1301 USA.
The full GNU General Public License is included in this distribution
in the file called LICENSE.GPL.
Contact Information:
http://software.intel.com/en-us/articles/intel-vtune-amplifier-xe/
BSD LICENSE
Copyright (c) 2017-2020 Intel Corporation. All rights reserved.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of Intel Corporation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</copyright> */
// /////////////////////////////////////////////////////////////////////////
////// Intel Processor Trace Marker Functionality
////////////////////////////////////////////////////////////////////////////
.text
.align 16
.globl __itt_pt_mark
.globl __itt_pt_event
.globl __itt_pt_mark_event
.globl __itt_pt_mark_threshold
.globl __itt_pt_byte
.globl __itt_pt_write
/// void __itt_pt_mark(unsigned char index);
__itt_pt_mark:
__itt_pt_mark_int:
and $0xff, %rdi
call __itt_pt_mark_pic
__itt_pt_mark_pic:
popq %rax
lea (__itt_pt_mark_call_table - __itt_pt_mark_pic) (%rax,%rdi,4), %rdi
jmp *%rdi
.long 0, 1, 2, 3 // GUID
.long 0xfadefade
__itt_pt_mark_call_table:
retq
retq $0x0
retq
retq $0x1
retq
retq $0x2
retq
retq $0x3
retq
retq $0x4
retq
retq $0x5
retq
retq $0x6
retq
retq $0x7
retq
retq $0x8
retq
retq $0x9
retq
retq $0xa
retq
retq $0xb
retq
retq $0xc
retq
retq $0xd
retq
retq $0xe
retq
retq $0xf
retq
retq $0x10
retq
retq $0x11
retq
retq $0x12
retq
retq $0x13
retq
retq $0x14
retq
retq $0x15
retq
retq $0x16
retq
retq $0x17
retq
retq $0x18
retq
retq $0x19
retq
retq $0x1a
retq
retq $0x1b
retq
retq $0x1c
retq
retq $0x1d
retq
retq $0x1e
retq
retq $0x1f
retq
retq $0x20
retq
retq $0x21
retq
retq $0x22
retq
retq $0x23
retq
retq $0x24
retq
retq $0x25
retq
retq $0x26
retq
retq $0x27
retq
retq $0x28
retq
retq $0x29
retq
retq $0x2a
retq
retq $0x2b
retq
retq $0x2c
retq
retq $0x2d
retq
retq $0x2e
retq
retq $0x2f
retq
retq $0x30
retq
retq $0x31
retq
retq $0x32
retq
retq $0x33
retq
retq $0x34
retq
retq $0x35
retq
retq $0x36
retq
retq $0x37
retq
retq $0x38
retq
retq $0x39
retq
retq $0x3a
retq
retq $0x3b
retq
retq $0x3c
retq
retq $0x3d
retq
retq $0x3e
retq
retq $0x3f
retq
retq $0x40
retq
retq $0x41
retq
retq $0x42
retq
retq $0x43
retq
retq $0x44
retq
retq $0x45
retq
retq $0x46
retq
retq $0x47
retq
retq $0x48
retq
retq $0x49
retq
retq $0x4a
retq
retq $0x4b
retq
retq $0x4c
retq
retq $0x4d
retq
retq $0x4e
retq
retq $0x4f
retq
retq $0x50
retq
retq $0x51
retq
retq $0x52
retq
retq $0x53
retq
retq $0x54
retq
retq $0x55
retq
retq $0x56
retq
retq $0x57
retq
retq $0x58
retq
retq $0x59
retq
retq $0x5a
retq
retq $0x5b
retq
retq $0x5c
retq
retq $0x5d
retq
retq $0x5e
retq
retq $0x5f
retq
retq $0x60
retq
retq $0x61
retq
retq $0x62
retq
retq $0x63
retq
retq $0x64
retq
retq $0x65
retq
retq $0x66
retq
retq $0x67
retq
retq $0x68
retq
retq $0x69
retq
retq $0x6a
retq
retq $0x6b
retq
retq $0x6c
retq
retq $0x6d
retq
retq $0x6e
retq
retq $0x6f
retq
retq $0x70
retq
retq $0x71
retq
retq $0x72
retq
retq $0x73
retq
retq $0x74
retq
retq $0x75
retq
retq $0x76
retq
retq $0x77
retq
retq $0x78
retq
retq $0x79
retq
retq $0x7a
retq
retq $0x7b
retq
retq $0x7c
retq
retq $0x7d
retq
retq $0x7e
retq
retq $0x7f
retq
retq $0x80
retq
retq $0x81
retq
retq $0x82
retq
retq $0x83
retq
retq $0x84
retq
retq $0x85
retq
retq $0x86
retq
retq $0x87
retq
retq $0x88
retq
retq $0x89
retq
retq $0x8a
retq
retq $0x8b
retq
retq $0x8c
retq
retq $0x8d
retq
retq $0x8e
retq
retq $0x8f
retq
retq $0x90
retq
retq $0x91
retq
retq $0x92
retq
retq $0x93
retq
retq $0x94
retq
retq $0x95
retq
retq $0x96
retq
retq $0x97
retq
retq $0x98
retq
retq $0x99
retq
retq $0x9a
retq
retq $0x9b
retq
retq $0x9c
retq
retq $0x9d
retq
retq $0x9e
retq
retq $0x9f
retq
retq $0xa0
retq
retq $0xa1
retq
retq $0xa2
retq
retq $0xa3
retq
retq $0xa4
retq
retq $0xa5
retq
retq $0xa6
retq
retq $0xa7
retq
retq $0xa8
retq
retq $0xa9
retq
retq $0xaa
retq
retq $0xab
retq
retq $0xac
retq
retq $0xad
retq
retq $0xae
retq
retq $0xaf
retq
retq $0xb0
retq
retq $0xb1
retq
retq $0xb2
retq
retq $0xb3
retq
retq $0xb4
retq
retq $0xb5
retq
retq $0xb6
retq
retq $0xb7
retq
retq $0xb8
retq
retq $0xb9
retq
retq $0xba
retq
retq $0xbb
retq
retq $0xbc
retq
retq $0xbd
retq
retq $0xbe
retq
retq $0xbf
retq
retq $0xc0
retq
retq $0xc1
retq
retq $0xc2
retq
retq $0xc3
retq
retq $0xc4
retq
retq $0xc5
retq
retq $0xc6
retq
retq $0xc7
retq
retq $0xc8
retq
retq $0xc9
retq
retq $0xca
retq
retq $0xcb
retq
retq $0xcc
retq
retq $0xcd
retq
retq $0xce
retq
retq $0xcf
retq
retq $0xd0
retq
retq $0xd1
retq
retq $0xd2
retq
retq $0xd3
retq
retq $0xd4
retq
retq $0xd5
retq
retq $0xd6
retq
retq $0xd7
retq
retq $0xd8
retq
retq $0xd9
retq
retq $0xda
retq
retq $0xdb
retq
retq $0xdc
retq
retq $0xdd
retq
retq $0xde
retq
retq $0xdf
retq
retq $0xe0
retq
retq $0xe1
retq
retq $0xe2
retq
retq $0xe3
retq
retq $0xe4
retq
retq $0xe5
retq
retq $0xe6
retq
retq $0xe7
retq
retq $0xe8
retq
retq $0xe9
retq
retq $0xea
retq
retq $0xeb
retq
retq $0xec
retq
retq $0xed
retq
retq $0xee
retq
retq $0xef
retq
retq $0xf0
retq
retq $0xf1
retq
retq $0xf2
retq
retq $0xf3
retq
retq $0xf4
retq
retq $0xf5
retq
retq $0xf6
retq
retq $0xf7
retq
retq $0xf8
retq
retq $0xf9
retq
retq $0xfa
retq
retq $0xfb
retq
retq $0xfc
retq
retq $0xfd
retq
retq $0xfe
retq
retq $0xff
.align 16
__itt_pt_byte:
__itt_pt_byte_int:
and $0xff, %rdi
call __itt_pt_byte_pic
__itt_pt_byte_pic:
popq %rcx
lea (__itt_pt_byte_call_table - __itt_pt_byte_pic) (%rcx,%rdi,1), %rdi
jmp *%rdi
.align 4
.long 0, 1, 2, 3 // GUID
.long 0xfadedeaf
__itt_pt_byte_call_table:
.fill 256,1,0xc3
.align 16
__itt_pt_event:
__itt_pt_event_int:
pushq %rcx
mov %rdi,%rcx
rdpmc
xor %rdi, %rdi
mov %al, %dil
call __itt_pt_byte_int
shr $8, %eax
mov %al, %dil
call __itt_pt_byte_int
shr $8, %eax
mov %al, %dil
call __itt_pt_byte_int
shr $8, %eax
mov %al, %dil
call __itt_pt_byte_int
mov %dl, %dil
call __itt_pt_byte_int
shr $8, %edx
mov %dl, %dil
call __itt_pt_byte_int
shr $8, %edx
mov %dl, %dil
call __itt_pt_byte_int
shr $8, %edx
mov %dl, %dil
call __itt_pt_byte_int
popq %rcx
ret
.align 16
__itt_pt_mark_event:
test $1, %rdi
jnz odd
mov %rdi, %rsi
xor %rdi,%rdi
call __itt_pt_event_int
mov %rsi, %rdi
jmp __itt_pt_mark_int
odd:
call __itt_pt_mark_int
xor %rdi,%rdi
jmp __itt_pt_event_int
.align 16
__itt_pt_flush:
call __itt_pt_flush_pic
__itt_pt_flush_pic:
popq %rdx
lea (__itt_pt_mark_flush_1 - __itt_pt_flush_pic) (%rdx), %rax
jmp *%rax
.align 16
nop
__itt_pt_mark_flush_1:
lea (__itt_pt_mark_flush_2 - __itt_pt_flush_pic) (%rdx), %rax
jmp *%rax
.align 16
nop
nop
__itt_pt_mark_flush_2:
lea (__itt_pt_mark_flush_3 - __itt_pt_flush_pic) (%rdx), %rax
jmp *%rax
.align 16
nop
nop
nop
__itt_pt_mark_flush_3:
ret
.align 16
// int __itt_pt_mark_threshold(unsigned char index, unsigned long long* tmp, int threshold);
__itt_pt_mark_threshold:
// rdi == index
// rsi == tmp
// rdx == threshold
mov %rdx, %r8 // r8 = threshold
xor %rdx, %rdx
xor %rax, %rax
test $1, %rdi
jnz mark_end
mark_begin:
mov $((1 << 30) + 1),%rcx
rdpmc
shl $32, %rdx
or %rax, %rdx
mov %rdx, (%rsi)
jmp __itt_pt_mark_int
mark_end:
mov $((1 << 30) + 1),%rcx
rdpmc
shl $32, %rdx
or %rax, %rdx
sub (%rsi), %rdx
cmp %r8, %rdx // threshold
jnc found
jmp __itt_pt_mark_int
found:
call __itt_pt_mark_int
jmp __itt_pt_flush
// PTWRITE
.align 16
// void __itt_pt_write(unsigned long long value);
.long 0, 1, 2, 3 // GUID
__itt_pt_write:
// ptwrite rcx
.byte 0xF3, 0x48, 0x0F, 0xAE, 0xE1
ret