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
/* <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:
movzbl 4(%esp), %eax
// and $0xff, %eax
lea __itt_pt_mark_call_table(,%eax,4), %eax
jmp *%eax
.align 4
.long 0, 1, 2, 3 // GUID
.long 0xfadefade
__itt_pt_mark_call_table:
/// .fill 256,4,(0x0000c2c3 | (( . - __itt_pt_mark_call_table) << 14))
ret
ret $0x0
ret
ret $0x1
ret
ret $0x2
ret
ret $0x3
ret
ret $0x4
ret
ret $0x5
ret
ret $0x6
ret
ret $0x7
ret
ret $0x8
ret
ret $0x9
ret
ret $0xa
ret
ret $0xb
ret
ret $0xc
ret
ret $0xd
ret
ret $0xe
ret
ret $0xf
ret
ret $0x10
ret
ret $0x11
ret
ret $0x12
ret
ret $0x13
ret
ret $0x14
ret
ret $0x15
ret
ret $0x16
ret
ret $0x17
ret
ret $0x18
ret
ret $0x19
ret
ret $0x1a
ret
ret $0x1b
ret
ret $0x1c
ret
ret $0x1d
ret
ret $0x1e
ret
ret $0x1f
ret
ret $0x20
ret
ret $0x21
ret
ret $0x22
ret
ret $0x23
ret
ret $0x24
ret
ret $0x25
ret
ret $0x26
ret
ret $0x27
ret
ret $0x28
ret
ret $0x29
ret
ret $0x2a
ret
ret $0x2b
ret
ret $0x2c
ret
ret $0x2d
ret
ret $0x2e
ret
ret $0x2f
ret
ret $0x30
ret
ret $0x31
ret
ret $0x32
ret
ret $0x33
ret
ret $0x34
ret
ret $0x35
ret
ret $0x36
ret
ret $0x37
ret
ret $0x38
ret
ret $0x39
ret
ret $0x3a
ret
ret $0x3b
ret
ret $0x3c
ret
ret $0x3d
ret
ret $0x3e
ret
ret $0x3f
ret
ret $0x40
ret
ret $0x41
ret
ret $0x42
ret
ret $0x43
ret
ret $0x44
ret
ret $0x45
ret
ret $0x46
ret
ret $0x47
ret
ret $0x48
ret
ret $0x49
ret
ret $0x4a
ret
ret $0x4b
ret
ret $0x4c
ret
ret $0x4d
ret
ret $0x4e
ret
ret $0x4f
ret
ret $0x50
ret
ret $0x51
ret
ret $0x52
ret
ret $0x53
ret
ret $0x54
ret
ret $0x55
ret
ret $0x56
ret
ret $0x57
ret
ret $0x58
ret
ret $0x59
ret
ret $0x5a
ret
ret $0x5b
ret
ret $0x5c
ret
ret $0x5d
ret
ret $0x5e
ret
ret $0x5f
ret
ret $0x60
ret
ret $0x61
ret
ret $0x62
ret
ret $0x63
ret
ret $0x64
ret
ret $0x65
ret
ret $0x66
ret
ret $0x67
ret
ret $0x68
ret
ret $0x69
ret
ret $0x6a
ret
ret $0x6b
ret
ret $0x6c
ret
ret $0x6d
ret
ret $0x6e
ret
ret $0x6f
ret
ret $0x70
ret
ret $0x71
ret
ret $0x72
ret
ret $0x73
ret
ret $0x74
ret
ret $0x75
ret
ret $0x76
ret
ret $0x77
ret
ret $0x78
ret
ret $0x79
ret
ret $0x7a
ret
ret $0x7b
ret
ret $0x7c
ret
ret $0x7d
ret
ret $0x7e
ret
ret $0x7f
ret
ret $0x80
ret
ret $0x81
ret
ret $0x82
ret
ret $0x83
ret
ret $0x84
ret
ret $0x85
ret
ret $0x86
ret
ret $0x87
ret
ret $0x88
ret
ret $0x89
ret
ret $0x8a
ret
ret $0x8b
ret
ret $0x8c
ret
ret $0x8d
ret
ret $0x8e
ret
ret $0x8f
ret
ret $0x90
ret
ret $0x91
ret
ret $0x92
ret
ret $0x93
ret
ret $0x94
ret
ret $0x95
ret
ret $0x96
ret
ret $0x97
ret
ret $0x98
ret
ret $0x99
ret
ret $0x9a
ret
ret $0x9b
ret
ret $0x9c
ret
ret $0x9d
ret
ret $0x9e
ret
ret $0x9f
ret
ret $0xa0
ret
ret $0xa1
ret
ret $0xa2
ret
ret $0xa3
ret
ret $0xa4
ret
ret $0xa5
ret
ret $0xa6
ret
ret $0xa7
ret
ret $0xa8
ret
ret $0xa9
ret
ret $0xaa
ret
ret $0xab
ret
ret $0xac
ret
ret $0xad
ret
ret $0xae
ret
ret $0xaf
ret
ret $0xb0
ret
ret $0xb1
ret
ret $0xb2
ret
ret $0xb3
ret
ret $0xb4
ret
ret $0xb5
ret
ret $0xb6
ret
ret $0xb7
ret
ret $0xb8
ret
ret $0xb9
ret
ret $0xba
ret
ret $0xbb
ret
ret $0xbc
ret
ret $0xbd
ret
ret $0xbe
ret
ret $0xbf
ret
ret $0xc0
ret
ret $0xc1
ret
ret $0xc2
ret
ret $0xc3
ret
ret $0xc4
ret
ret $0xc5
ret
ret $0xc6
ret
ret $0xc7
ret
ret $0xc8
ret
ret $0xc9
ret
ret $0xca
ret
ret $0xcb
ret
ret $0xcc
ret
ret $0xcd
ret
ret $0xce
ret
ret $0xcf
ret
ret $0xd0
ret
ret $0xd1
ret
ret $0xd2
ret
ret $0xd3
ret
ret $0xd4
ret
ret $0xd5
ret
ret $0xd6
ret
ret $0xd7
ret
ret $0xd8
ret
ret $0xd9
ret
ret $0xda
ret
ret $0xdb
ret
ret $0xdc
ret
ret $0xdd
ret
ret $0xde
ret
ret $0xdf
ret
ret $0xe0
ret
ret $0xe1
ret
ret $0xe2
ret
ret $0xe3
ret
ret $0xe4
ret
ret $0xe5
ret
ret $0xe6
ret
ret $0xe7
ret
ret $0xe8
ret
ret $0xe9
ret
ret $0xea
ret
ret $0xeb
ret
ret $0xec
ret
ret $0xed
ret
ret $0xee
ret
ret $0xef
ret
ret $0xf0
ret
ret $0xf1
ret
ret $0xf2
ret
ret $0xf3
ret
ret $0xf4
ret
ret $0xf5
ret
ret $0xf6
ret
ret $0xf7
ret
ret $0xf8
ret
ret $0xf9
ret
ret $0xfa
ret
ret $0xfb
ret
ret $0xfc
ret
ret $0xfd
ret
ret $0xfe
ret
ret $0xff
.align 16
__itt_pt_byte:
movl 4(%esp), %ecx
__itt_pt_byte_:
and $0xff, %ecx
lea __itt_pt_byte_call_table(,%ecx,1), %ecx
jmp *%ecx
.align 4
.long 0, 1, 2, 3 // GUID
.long 0xfadedeaf
__itt_pt_byte_call_table:
.fill 256,1,0xc3
.align 16
__itt_pt_event:
push %ecx
mov 8(%esp), %ecx
rdpmc
mov %al,%cl
call __itt_pt_byte_
shr $8,%eax
mov %al,%cl
call __itt_pt_byte_
shr $8,%eax
mov %al,%cl
call __itt_pt_byte_
shr $8,%eax
mov %al,%cl
call __itt_pt_byte_
mov %dl,%cl
call __itt_pt_byte_
shr $8,%edx
mov %dl,%cl
call __itt_pt_byte_
shr $8,%edx
mov %dl,%cl
call __itt_pt_byte_
shr $8,%edx
mov %dl,%cl
call __itt_pt_byte_
pop %ecx
ret
.align 16
__itt_pt_mark_event:
testl $1,4(%esp)
jnz odd
pushl $0
call __itt_pt_event
add $2,%esp
jmp __itt_pt_mark
odd:
pushl 4(%esp)
call __itt_pt_mark
add $2,%esp
movl $0,4(%esp)
jmp __itt_pt_event
.align 16
__itt_pt_flush:
lea __itt_pt_mark_flush_1,%eax
jmp *%eax
.align 16
nop
__itt_pt_mark_flush_1:
lea __itt_pt_mark_flush_2,%eax
jmp *%eax
.align 16
nop
nop
__itt_pt_mark_flush_2:
lea __itt_pt_mark_flush_3,%eax
jmp *%eax
.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:
// 4(%esp) == index
// 8(%esp) == tmp
// 12(%esp) == threshold
xor %edx,%edx
xor %eax,%eax
testl $1,4(%esp)
jnz mark_end
mark_begin:
mov $((1 << 30) + 1),%ecx
rdpmc
mov 8(%esp), %ecx
mov %eax, (%ecx)
mov %edx,4(%ecx)
jmp __itt_pt_mark
mark_end:
mov $((1 << 30) + 1),%ecx
rdpmc
mov 8(%esp), %ecx
sub (%ecx), %eax
sbb 4(%ecx), %edx
sub 12(%esp), %eax // threshold
jnc found
sbb $0, %edx
jnc found
jmp __itt_pt_mark
found:
call __itt_pt_mark
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 dword ptr [esp + 4]
.byte 0xF3, 0x0F, 0xAE, 0x64, 0x24, 0x04
ret