Наши проекты:
Журнал · Discuz!ML · Wiki · DRKB · Помощь проекту |
||
ПРАВИЛА | FAQ | Помощь | Поиск | Участники | Календарь | Избранное | RSS |
[18.223.32.230] |
|
Сообщ.
#1
,
|
|
|
Люди, скажите мне, пожалуйста, может ли за 1 такт выполниться несколько инструкций?
.MODEL Tiny<br>.586<br>.CODE<br>ORG 100h<br><br>rdtsc macro<br> db 0Fh,31h<br>endm<br><br>Start:<br><br> cli<br> rdtsc<br> xchg cx,ax<br>; xor bx,bx<br> rdtsc<br> sub ax,cx<br> sub ax,21h<br> int 29h<br> mov al,ah<br> int 29h<br> sti<br> int 20h<br><br>END Start Программа вычисляет число тактов со-процессора, прошедших между 2-мя rdtsc. Из этого числа вычитается 21h (время выполнения xchg+rdtsc.... по крайней мере, у меня). Соответственно, на экран выводятся 2 нуля (2 байта с кодом 0). Но! Если раскомментировать xor bx,bx выведутся два символа с кодом 0FFh (т.е. время выполнения xor bx,bx = -1 такт). Что это за глюк? А если xor bx,bx заменить на 1 или 2 xor ax,ax, то получится 0, а если на 3 раза по xor ax,ax, то будет 1. Но! Если поставить 4 инструкции xor ax,ax, то результат опять будет нулевым..... Как это понимать? Kernel Panic что-то говорил о пайпах.... Можно поподробнее на эту тему? |
Сообщ.
#2
,
|
|
|
Не знаю, у меня в мануалах написано, что rdtsc занимает от 20 до 24 циклов, а xchg ax,reg16 - 3 цикла. Может, в этом проблема?
В общем, две инструкции могут выполняться за один такт, если это простые инструкции, обе не содержат одновременно и явного адреса, и непосредственного значения.. И там ещё куча условий.. Поищи доки.. |
Сообщ.
#3
,
|
|
|
Вообще есть ещё таблица парабельности команд. Для первого пня -- в два конвейера. Для других невидел.
|
Сообщ.
#4
,
|
|
|
Может, адресок подскажете (про спаренности, пайпы и т.д)?
Мышки на сервере, ты про какой конвейер говоришь? Конвейер на пне? |
Сообщ.
#5
,
|
|
|
http://emanual.ru/download/1200.html
|
Сообщ.
#6
,
|
|
|
Премного благодарен.......
Почитаем ;D |
Сообщ.
#7
,
|
|
|
Ну ссылку не скажу - не знаю. Но есть у меня тетрадка, куда я в раннем младенчестве сию инфу передрал. Вот коротенький её пример:
ADC PU ADD UV AND UV CALL PV CMP UV DEC UV INC UV ... и гэтак далей. Что сие означает. Есть 2 конвейера -- U и V. PU - команда парабельна с конвейером U PV - команда парабельна с конвейером V UV - команда парабельна с любым конвейером. Например: ADD ax,bx AND cx,1 выполнятся за один такт, поскольку полностью парабельны. ADC ax,bx CALL [bx] тоже за один проход. ADC парабельна для U, а CALL для V И т.д. в том же духе.... Я точно не помню, там вроде были ограничения на то, что бы команды не изменяли одни и теже регистры... это надо уточнить. |
Сообщ.
#8
,
|
|
|
Да, 'за один такт' -- выражение образное. Команды-то будут выполняться вместе, но вот если один из операндов одной из команд находится в памяти и почему-то незакэшировался -- получи 2-5 тактов штрафа. Нюансов там ещё много...
|
Сообщ.
#9
,
|
|
|
Ну, блин.. Так недалеко и до RISC-овых машин. Типа: а выровняла ли ты на ночь адреса переменных, Дездемона??.. А если не выровняла - то полный, прошу пардону, писец ей, в виде страшных мук в аду процессорных исключений..
Короче, вот приблизительная инструкция по спариваемости (вы уж извините за двусмысленность слова) инструкций процессора (скомунизжено не помню откуда): <br>Pairing Pentium Instructions<br><br>1. Both instructions must be simple.<br><br>2. Shifts or rotates can only pair in the U pipe. <br> (SHL, SHR, SAL, SAR, ROL, ROR, RCL or RCR)<br><br>3. ADC and SBB can only pair in the U pipe.<br><br>4. JMP, CALL and Jcc can only pair in the V pipe. (Jcc = jump on condition code).<br><br>5. Neither instruction can contain BOTH a displacement and an immediate operand. For example:<br><br>mov [bx+2], 3 ; 2 is a displacement, 3 is immediate<br>mov mem1, 4 ; mem1 is a displacement, 4 is immediate<br><br>6. Prefixed instructions can only pair in the U pipe. This includes extended instructions that start with 0Fh except for the special case of the 16-bit conditional jumps of the 386 and above. Examples of prefixed instructions:<br><br>mov ES:[bx],<br>mov eax, [si] ; 32-bit operand in 16-bit code segment<br>mov ax, [esi] ; 16-bit operand in 32-bit code segment<br><br>7. The U pipe instruction must be only 1 byte in length or it will not pair until the second time it executes from the cache.<br><br>8. There can be no read-after-write or write-after-write register dependencies between the instructions except for special cases for the flags register and the stack pointer (rules 9 and 10).<br><br>mov ebx, 2 ; writes to EBX<br>add ecx, ebx ; reads EBX and ECX, writes to ECX<br> ; EBX is read after being written, no pairing<br>mov ebx, 1 ; writes to EBX<br>mov ebx, 2 ; writes to EBX<br> ; write after write, no pairing<br><br>9. The flags register exception allows an ALU instruction to be paired with a Jcc even though the ALU instruction writes the flags and Jcc reads the flags. For example:<br><br>cmp al, 0 ; CMP modifies the flags<br>je addr ; JE reads the flags, but pairs<br>dec cx ; DEC modifies the flags<br>jnz loop1 ; JNZ reads the flags, but pairs<br><br>10. The stack pointer exception allows two PUSHes or two POPs to be paired even though they both read and write to the SP (or ESP) register.<br><br>push eax ; ESP is read and modified<br>push ebx ; ESP is read and modified, but still pairs<br><br>Simple Instructions (for Pentium pairing)<br><br>The following is a list of simple instructions, as required by rule #1 above.<br><br>Instruction format 16-bit example 32-bit example<br>------------------------------------------------------------<br>MOV reg, reg mov ax, bx mov eax, edx<br>MOV reg, mem mov ax, [bx] mov eax, [edx]<br>MOV reg, imm mov ax, 1 mov eax, 1<br>MOV mem, reg mov [bx], ax mov [edx], eax<br>MOV mem, imm mov [bx], 1 mov [edx], 1<br>alu reg, reg add ax, bx cmp eax, edx<br>alu reg, mem add ax, [bx] cmp eax, [edx]<br>alu reg, imm add ax, 1 cmp eax, 1<br>alu mem, reg add [bx], ax cmp [edx], eax<br>alu mem, imm add [bx], 1 cmp [edx], 1<br><br>where alu = add, adc, and, or, xor, sub, sbb, cmp, test<br><br>INC reg inc ax inc eax<br>INC mem inc var1 inc [eax]<br>DEC reg dec bx dec ebx<br>DEC mem dec [bx] dec var2<br>PUSH reg push ax push eax<br>POP reg pop ax pop eax<br>LEA reg, mem lea ax, [si+2] lea eax, [eax+4*esi+8]<br>JMP near jmp label jmp lable2<br>CALL near call proc call proc2<br>Jcc near jz lbl jnz lbl2<br><br>where Jcc = ja, jae, jb, jbe, jg, jge, jl, jle, je, jne, jc, js,<br> jnp, jo, jp, jnbe, jnb, jnae, jna, jnle, jnl, jnge,<br> jng, jz, jnz, jnc, jns, jpo, jno, jpe<br><br>NOP nop nop<br>shift reg, 1 shl ax, 1 rcl eax, 1<br>shift mem, 1 shr [bx], 1 rcr [ebx], 1<br>shift reg, imm sal ax, 2 rol esi, 2<br>shift mem, imm sar ax, 15 ror [esi], 31<br><br>where shift = shl, shr, sal, sar, rcl, rcr, rol, ror<br><br>Notes:<br><br>rcl and rcr are not pairable with immediate counts other than 1<br>all memory-immediate (mem, imm) instructions are not pairable with a displacement in the memory operand<br>instructions with segment registers are not pairable.<br> |