mirror of https://github.com/svaarala/duktape.git
Browse Source
* Makefile: more threads * Util: longer debug buffer * Add some misc dev test code (bitfield tests) * Minor debugger web UI tweakpull/2485/head
Sami Vaarala
3 years ago
6 changed files with 174 additions and 6 deletions
@ -0,0 +1,64 @@ |
|||
/* Test bitfield patterns. */ |
|||
|
|||
/*
|
|||
* 1050: 48 83 ec 08 sub $0x8,%rsp |
|||
* 1054: 8b 05 d6 2f 00 00 mov 0x2fd6(%rip),%eax # 4030 <val> |
|||
* 105a: f6 c4 01 test $0x1,%ah |
|||
* 105d: 75 4c jne 10ab <main+0x5b> |
|||
* 105f: 8b 05 cb 2f 00 00 mov 0x2fcb(%rip),%eax # 4030 <val> |
|||
* 1065: f6 c4 01 test $0x1,%ah |
|||
* 1068: 74 6b je 10d5 <main+0x85> |
|||
* 106a: 8b 05 c0 2f 00 00 mov 0x2fc0(%rip),%eax # 4030 <val> |
|||
* 1070: f6 c4 0f test $0xf,%ah |
|||
* 1073: 74 52 je 10c7 <main+0x77> |
|||
* 1075: 8b 05 b5 2f 00 00 mov 0x2fb5(%rip),%eax # 4030 <val> |
|||
* 107b: f6 c4 0f test $0xf,%ah |
|||
* 107e: 75 39 jne 10b9 <main+0x69> |
|||
* 1080: 8b 05 aa 2f 00 00 mov 0x2faa(%rip),%eax # 4030 <val> |
|||
* 1086: 25 00 0f 00 00 and $0xf00,%eax |
|||
* 108b: 3d 00 0f 00 00 cmp $0xf00,%eax |
|||
* 1090: 74 5f je 10f1 <main+0xa1> |
|||
* 1092: 8b 05 98 2f 00 00 mov 0x2f98(%rip),%eax # 4030 <val> |
|||
* 1098: 25 00 0f 00 00 and $0xf00,%eax |
|||
* 109d: 3d 00 0c 00 00 cmp $0xc00,%eax |
|||
* 10a2: 74 3f je 10e3 <main+0x93> |
|||
* 10a4: 31 c0 xor %eax,%eax |
|||
* 10a6: 48 83 c4 08 add $0x8,%rsp |
|||
* 10aa: c3 retq |
|||
*/ |
|||
|
|||
#include <stdio.h> |
|||
|
|||
volatile int val = 0xdeadbeef; |
|||
|
|||
int main(int argc, const char *argv[]) { |
|||
/* Single-bit test for 0 or 1: single TEST on x64. */ |
|||
if ((val & 0x100) != 0) { |
|||
printf("1\n"); |
|||
} |
|||
if ((val & 0x100) == 0) { |
|||
printf("2\n"); |
|||
} |
|||
|
|||
/* Multi-bit test for all zeroes: single TEST on x64. */ |
|||
if ((val & 0xf00) == 0) { |
|||
printf("3\n"); |
|||
} |
|||
|
|||
/* Multi-bit test for not all zeroes (>= one-bit): single TEST on x64. */ |
|||
if ((val & 0xf00) != 0) { |
|||
printf("3\n"); |
|||
} |
|||
|
|||
/* Multi-bit test for all ones: AND + CMP on x64. */ |
|||
if ((val & 0xf00) == 0xf00) { |
|||
printf("4\n"); |
|||
} |
|||
|
|||
/* Multi-bit test for arbitrary value: AND + CMP on x64. */ |
|||
if ((val & 0xf00) == 0xc00) { |
|||
printf("5\n"); |
|||
} |
|||
|
|||
return 0; |
|||
} |
@ -0,0 +1,105 @@ |
|||
/* Test return by value or write to out pointer. */ |
|||
|
|||
/* For gcc 9.4.0 -O2 (loop highlighted):
|
|||
|
|||
0000000000001170 <run1>: |
|||
1170: b8 00 e1 f5 05 mov $0x5f5e100,%eax |
|||
1175: 0f 1f 00 nopl (%rax) |
|||
=============================================================================== |
|||
1178: c7 44 24 e8 7b 00 00 movl $0x7b,-0x18(%rsp) |
|||
117f: 00 |
|||
1180: f2 0f 10 05 88 2e 00 movsd 0x2e88(%rip),%xmm0 # 4010 <dbl> |
|||
1187: 00 |
|||
1188: f2 0f 11 44 24 f0 movsd %xmm0,-0x10(%rsp) |
|||
118e: 83 e8 01 sub $0x1,%eax |
|||
1191: 75 e5 jne 1178 <run1+0x8> |
|||
=============================================================================== |
|||
1193: 8b 54 24 e8 mov -0x18(%rsp),%edx |
|||
1197: 48 8d 35 66 0e 00 00 lea 0xe66(%rip),%rsi # 2004 <_IO_stdin_used+0x4> |
|||
119e: bf 01 00 00 00 mov $0x1,%edi |
|||
11a3: 31 c0 xor %eax,%eax |
|||
11a5: e9 a6 fe ff ff jmpq 1050 <__printf_chk@plt> |
|||
11aa: 66 0f 1f 44 00 00 nopw 0x0(%rax,%rax,1) |
|||
|
|||
00000000000011b0 <run2>: |
|||
11b0: 48 bf 00 00 00 00 ff movabs $0xffffffff00000000,%rdi |
|||
11b7: ff ff ff |
|||
11ba: be 00 e1 f5 05 mov $0x5f5e100,%esi |
|||
11bf: 90 nop |
|||
=============================================================================== |
|||
11c0: 48 89 c1 mov %rax,%rcx |
|||
11c3: f2 0f 10 05 45 2e 00 movsd 0x2e45(%rip),%xmm0 # 4010 <dbl> |
|||
11ca: 00 |
|||
11cb: 48 21 f9 and %rdi,%rcx |
|||
11ce: 48 83 c9 7b or $0x7b,%rcx |
|||
11d2: 48 89 4c 24 e8 mov %rcx,-0x18(%rsp) |
|||
11d7: 48 89 c8 mov %rcx,%rax |
|||
11da: 66 0f d6 44 24 f0 movq %xmm0,-0x10(%rsp) |
|||
11e0: 83 ee 01 sub $0x1,%esi |
|||
11e3: 75 db jne 11c0 <run2+0x10> |
|||
=============================================================================== |
|||
11e5: 8b 54 24 e8 mov -0x18(%rsp),%edx |
|||
11e9: 48 8d 35 14 0e 00 00 lea 0xe14(%rip),%rsi # 2004 <_IO_stdin_used+0x4> |
|||
11f0: bf 01 00 00 00 mov $0x1,%edi |
|||
11f5: 31 c0 xor %eax,%eax |
|||
11f7: e9 54 fe ff ff jmpq 1050 <__printf_chk@plt> |
|||
11fc: 0f 1f 40 00 nopl 0x0(%rax) |
|||
*/ |
|||
|
|||
#include <stdio.h> |
|||
|
|||
typedef struct { |
|||
int t; |
|||
union { |
|||
double d; |
|||
void *p; |
|||
} u; |
|||
} tval; |
|||
|
|||
volatile double dbl = 123.0; |
|||
|
|||
static void test1(volatile tval *out) { |
|||
out->t = 123; |
|||
out->u.d = dbl; |
|||
} |
|||
|
|||
static tval test2(void) { |
|||
tval tv; |
|||
tv.t = 123; |
|||
tv.u.d = dbl; |
|||
return tv; |
|||
} |
|||
|
|||
static __attribute__((noinline)) void run1(void) { |
|||
volatile tval tv1; |
|||
int i; |
|||
|
|||
for (i = 0; i < 100000000; i++) { |
|||
#if 1 |
|||
test1(&tv1); |
|||
#endif |
|||
} |
|||
printf("%d\n", tv1.t); |
|||
|
|||
} |
|||
|
|||
static __attribute__((noinline)) void run2(void) { |
|||
volatile tval tv2; |
|||
int i; |
|||
|
|||
for (i = 0; i < 100000000; i++) { |
|||
#if 1 |
|||
tv2 = test2(); |
|||
#endif |
|||
} |
|||
printf("%d\n", tv2.t); |
|||
} |
|||
|
|||
int main(int argc, const char *argv[]) { |
|||
(void) argc; |
|||
(void) argv; |
|||
|
|||
run1(); |
|||
run2(); |
|||
return 0; |
|||
} |
Loading…
Reference in new issue