File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -12410,6 +12410,12 @@ JG vs JA and JL vs JB:
12410
12410
* https://stackoverflow.com/questions/9617877/assembly-jg-jnle-jl-jnge-after-cmp/56613928#56613928
12411
12411
* https://stackoverflow.com/questions/20906639/difference-between-ja-and-jg-in-assembly
12412
12412
12413
+ ==== x86 LOOP instruction
12414
+
12415
+ link:userland/arch/x86_64/loop.S[LOOP]
12416
+
12417
+ Vs <<x86-jcc-instructions,Jcc>>: https://stackoverflow.com/questions/6805692/x86-assembly-programming-loops-with-ecx-and-loop-instruction-versus-jmp-jcond Holy CISC!
12418
+
12413
12419
=== x86 SIMD
12414
12420
12415
12421
History:
Original file line number Diff line number Diff line change
1
+ /* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-loop-instruction */
2
+
3
+ #include <lkmc.h>
4
+
5
+ LKMC_PROLOGUE
6
+
7
+ /* LOOP
8
+ *
9
+ * ....
10
+ * rcx--;
11
+ * if (rcx != 0) goto label
12
+ * ....
13
+ */
14
+ mov $0 , %rax
15
+ mov $3 , %rcx
16
+ loop_label:
17
+ inc %rax
18
+ loop loop_label
19
+ LKMC_ASSERT_EQ(%rax , $3 )
20
+
21
+ /* LOOPE
22
+ *
23
+ * ....
24
+ * rcx--;
25
+ * if (ecx != 0 && ZF == 1) goto label
26
+ * ....
27
+ *
28
+ * Application: search for first non-zero element in a range.
29
+ *
30
+ * If found, rax will contain the element index.
31
+ *
32
+ * Otherwise, rax contains length + 1.
33
+ */
34
+ .section .rodata
35
+ loope_array: .byte 0 , 0 , 1 , 0
36
+ .text
37
+ /* Array length. */
38
+ mov $4 , %rcx
39
+ mov $-1 , %rax
40
+ loope_label:
41
+ inc %rax
42
+ cmpb $0 , loope_array(%rax )
43
+ loope loope_label
44
+ /* The first non-zero item (1) was at index 2. */
45
+ LKMC_ASSERT_EQ(%rax , $2 )
46
+
47
+ /* LOOPNE
48
+ *
49
+ * ....
50
+ * ecx--; if (ecx != 0 && ZF == 0) goto lbl
51
+ * ....
52
+ */
53
+ LKMC_EPILOGUE
You can’t perform that action at this time.
0 commit comments