Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems trying to compile exprtk tests adapted #88

Closed
mingodad opened this issue Aug 30, 2022 · 9 comments
Closed

Problems trying to compile exprtk tests adapted #88

mingodad opened this issue Aug 30, 2022 · 9 comments

Comments

@mingodad
Copy link
Contributor

While testing xcc/wcc with an adapted version of the tests from https://github.com/ArashPartow/exprtk the online wcc compile and give different results from gcc, the xcc takes for ever to compile and I aborted it, see attached file.

It's a good source to profile the compiler.

exprtk.c.zip

@mingodad
Copy link
Contributor Author

Here is the output of gdb while trying to compile the preprocessed eprtk.c interrupted at several intervals of several seconds:

./xcc -E exprtk.c > exprtk.pp.c
xcc-dad$ ./cc1 exprtk.pp.c 
^C

xcc-dad$ gdb --args ./cc1 exprtk.pp.c 
GNU gdb (Ubuntu 10.2-0ubuntu1~18.04~2) 10.2
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./cc1...
(gdb) r
Starting program: xcc-dad/cc1 exprtk.pp.c
^C
Program received signal SIGINT, Interrupt.
0x0000555555576c66 in vec_contains (vec=0x55555b048f50, elem=0x5555582d3ef0) at src/util/util.c:404
404	    if (vec->data[i] == elem)
(gdb) bt
#0  0x0000555555576c66 in vec_contains (vec=0x55555b048f50, elem=0x5555582d3ef0) at src/util/util.c:404
#1  0x000055555555da58 in analyze_reg_flow (bbcon=0x5555557932f0) at src/cc/regalloc.c:332
#2  0x000055555555e2ef in alloc_physical_registers (ra=0x555555793460, bbcon=0x5555557932f0, reserved_size=0)
    at src/cc/regalloc.c:520
#3  0x000055555556b8bd in gen_defun (func=0x5555557a3720) at src/cc/codegen.c:522
#4  0x000055555556b92e in gen_decl (decl=0x555557e105f0) at src/cc/codegen.c:535
#5  0x000055555556b9a5 in gen (decls=0x555555783930) at src/cc/codegen.c:554
#6  0x000055555556a088 in main (argc=2, argv=0x7fffffffd998) at src/cc/cc1.c:77
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) n
Program not restarted.
(gdb) c
Continuing.
^C
Program received signal SIGINT, Interrupt.
vec_contains (vec=0x55555b048f50, elem=0x5555596b21a0) at src/util/util.c:404
404	    if (vec->data[i] == elem)
(gdb) bt
#0  vec_contains (vec=0x55555b048f50, elem=0x5555596b21a0) at src/util/util.c:404
#1  0x000055555555da58 in analyze_reg_flow (bbcon=0x5555557932f0) at src/cc/regalloc.c:332
#2  0x000055555555e2ef in alloc_physical_registers (ra=0x555555793460, bbcon=0x5555557932f0, reserved_size=0)
    at src/cc/regalloc.c:520
#3  0x000055555556b8bd in gen_defun (func=0x5555557a3720) at src/cc/codegen.c:522
#4  0x000055555556b92e in gen_decl (decl=0x555557e105f0) at src/cc/codegen.c:535
#5  0x000055555556b9a5 in gen (decls=0x555555783930) at src/cc/codegen.c:554
#6  0x000055555556a088 in main (argc=2, argv=0x7fffffffd998) at src/cc/cc1.c:77
(gdb) c
Continuing.
^C
Program received signal SIGINT, Interrupt.
vec_contains (vec=0x55555b048f50, elem=0x55555a2ce120) at src/util/util.c:404
404	    if (vec->data[i] == elem)
(gdb) bt
#0  vec_contains (vec=0x55555b048f50, elem=0x55555a2ce120) at src/util/util.c:404
#1  0x000055555555da58 in analyze_reg_flow (bbcon=0x5555557932f0) at src/cc/regalloc.c:332
#2  0x000055555555e2ef in alloc_physical_registers (ra=0x555555793460, bbcon=0x5555557932f0, reserved_size=0)
    at src/cc/regalloc.c:520
#3  0x000055555556b8bd in gen_defun (func=0x5555557a3720) at src/cc/codegen.c:522
#4  0x000055555556b92e in gen_decl (decl=0x555557e105f0) at src/cc/codegen.c:535
#5  0x000055555556b9a5 in gen (decls=0x555555783930) at src/cc/codegen.c:554
#6  0x000055555556a088 in main (argc=2, argv=0x7fffffffd998) at src/cc/cc1.c:77
(gdb) c
Continuing.
^C
Program received signal SIGINT, Interrupt.
detect_living_registers (ra=0x555555793460, bbcon=0x5555557932f0, sorted_intervals=0x7ffff6a5c010, vreg_count=245237)
    at src/cc/regalloc.c:410
410	        if (((VReg*)ra->vregs->data[li->virt])->vtype->flag & VRTF_FLONUM)
(gdb) bt
#0  detect_living_registers (ra=0x555555793460, bbcon=0x5555557932f0, sorted_intervals=0x7ffff6a5c010, 
    vreg_count=245237) at src/cc/regalloc.c:410
#1  0x000055555555e637 in alloc_physical_registers (ra=0x555555793460, bbcon=0x5555557932f0, reserved_size=0)
    at src/cc/regalloc.c:584
#2  0x000055555556b8bd in gen_defun (func=0x5555557a3720) at src/cc/codegen.c:522
#3  0x000055555556b92e in gen_decl (decl=0x555557e105f0) at src/cc/codegen.c:535
#4  0x000055555556b9a5 in gen (decls=0x555555783930) at src/cc/codegen.c:554
#5  0x000055555556a088 in main (argc=2, argv=0x7fffffffd998) at src/cc/cc1.c:77
(gdb) c
Continuing.
^C
Program received signal SIGINT, Interrupt.
0x000055555555de2d in detect_living_registers (ra=0x555555793460, bbcon=0x5555557932f0, 
    sorted_intervals=0x7ffff6a5c010, vreg_count=245237) at src/cc/regalloc.c:403
403	        LiveInterval *li = sorted_intervals[k];
(gdb) c
Continuing.
^C
Program received signal SIGINT, Interrupt.
detect_living_registers (ra=0x555555793460, bbcon=0x5555557932f0, sorted_intervals=0x7ffff6a5c010, vreg_count=245237)
    at src/cc/regalloc.c:410
410	        if (((VReg*)ra->vregs->data[li->virt])->vtype->flag & VRTF_FLONUM)
(gdb) bt
#0  detect_living_registers (ra=0x555555793460, bbcon=0x5555557932f0, sorted_intervals=0x7ffff6a5c010, 
    vreg_count=245237) at src/cc/regalloc.c:410
#1  0x000055555555e637 in alloc_physical_registers (ra=0x555555793460, bbcon=0x5555557932f0, reserved_size=0)
    at src/cc/regalloc.c:584
#2  0x000055555556b8bd in gen_defun (func=0x5555557a3720) at src/cc/codegen.c:522
#3  0x000055555556b92e in gen_decl (decl=0x555557e105f0) at src/cc/codegen.c:535
#4  0x000055555556b9a5 in gen (decls=0x555555783930) at src/cc/codegen.c:554
#5  0x000055555556a088 in main (argc=2, argv=0x7fffffffd998) at src/cc/cc1.c:77
(gdb) c
Continuing.
^C
Program received signal SIGINT, Interrupt.
0x000055555555deae in detect_living_registers (ra=0x555555793460, bbcon=0x5555557932f0, 
    sorted_intervals=0x7ffff6a5c010, vreg_count=245237) at src/cc/regalloc.c:415
415	        if (nip == li->end)
(gdb) bt
#0  0x000055555555deae in detect_living_registers (ra=0x555555793460, bbcon=0x5555557932f0, 
    sorted_intervals=0x7ffff6a5c010, vreg_count=245237) at src/cc/regalloc.c:415
#1  0x000055555555e637 in alloc_physical_registers (ra=0x555555793460, bbcon=0x5555557932f0, reserved_size=0)
    at src/cc/regalloc.c:584
#2  0x000055555556b8bd in gen_defun (func=0x5555557a3720) at src/cc/codegen.c:522
#3  0x000055555556b92e in gen_decl (decl=0x555557e105f0) at src/cc/codegen.c:535
#4  0x000055555556b9a5 in gen (decls=0x555555783930) at src/cc/codegen.c:554
#5  0x000055555556a088 in main (argc=2, argv=0x7fffffffd998) at src/cc/cc1.c:77
(gdb) 

@mingodad
Copy link
Contributor Author

Here is the profile output from a trimmed down exprtk.c to allow it to finish:

Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls   s/call   s/call  name    
 83.10      1.18     1.18        2     0.59     0.59  detect_living_registers
 14.79      1.39     0.21    55549     0.00     0.00  vec_contains
  0.70      1.40     0.01    14236     0.00     0.00  var_find
  0.70      1.41     0.01        4     0.00     0.00  check_live_interval
  0.70      1.42     0.01        2     0.01     0.71  alloc_physical_registers
  0.00      1.42     0.00  1344993     0.00     0.00  equal_name
  0.00      1.42     0.00   390940     0.00     0.00  fetch_token
  0.00      1.42     0.00   387900     0.00     0.00  match
  0.00      1.42     0.00   312158     0.00     0.00  sort_live_interval
  0.00      1.42     0.00    49796     0.00     0.00  is_flonum
  0.00      1.42     0.00    45835     0.00     0.00  vec_push
  0.00      1.42     0.00    45478     0.00     0.00  isutf8first
  0.00      1.42     0.00    43922     0.00     0.00  expire_old_intervals
  0.00      1.42     0.00    43922     0.00     0.00  remove_active
  0.00      1.42     0.00    37717     0.00     0.00  find_entry
  0.00      1.42     0.00    28589     0.00     0.00  table_get
  0.00      1.42     0.00    22084     0.00     0.00  skip_whitespaces
  0.00      1.42     0.00    21961     0.00     0.00  insert_active
  0.00      1.42     0.00    21487     0.00     0.00  skip_whitespace_or_comment

@tyfkda
Copy link
Owner

tyfkda commented Aug 30, 2022

@mingodad Thank you to testing the compiler!

It seems detect_living_registers function is inefficient
if a function has many expressions.
It should be optimized.

@mingodad
Copy link
Contributor Author

mingodad commented Sep 1, 2022

Leaving xcc compiling ends up with this error message:

/usr/bin/time ./xcc exprtk.c 
cc1: src/cc/arch/x64/ir_x64.c:204: ir_out: Assertion `ir->dst->phys == ir->opr1->phys' failed.
Command exited with non-zero status 1
837.09user 0.36system 13:57.47elapsed 99%CPU (0avgtext+0avgdata 121672maxresident)k
0inputs+0outputs (0major+53735minor)pagefaults 0swaps

@mingodad
Copy link
Contributor Author

mingodad commented Sep 2, 2022

While trying to output the inequalities in exprtk.c I noticed that wcc cant output %.16f and looking into vsnprintf.c and changing some long by long long fixed the problem (probably should also do the same in other places):

@@ -240,17 +240,17 @@ vsnprintf(char *out, size_t n, const char *fmt_, va_list ap)
       double x = va_arg(ap, double);
 
       o += sprintsign(out + o, x < 0, sign, &order);
       x = x < 0 ? -x : x;
 
-      long intPart = x >= 0 ? (long)x : -(long)(-x);
+      long long intPart = x >= 0 ? (long long)x : -(long long)(-x);
       o += snprintulong(out + o, n - o, intPart, 10, kHexDigits,
                         order, padding);
       if (o < n) {
         out[o++] = '.';
         suborder = suborder > 0 ? suborder : 6;
-        unsigned long fraction = (unsigned long)((x - intPart) * pow10(suborder));
+        unsigned long long fraction = (unsigned long long)((x - intPart) * pow10(suborder));
         o += snprintulong(out + o, n - o, fraction, 10, kHexDigits,
                           suborder, '0');
       }
 #endif
     } else {

Changes to exprtk.c:

void equal(double a, double b) {
	++total_count;
	if(a == b) {
		++total_eq;
	}
	else printf("%d : %.16f != %.16f\n", total_count, a, b); //!!!<<< added this line 
}

wcc onine before:

RuntimeError: float unrepresentable in integer range

wcc online after:

3 : 0.0000001016675003 != 0.0000001016675003
5 : -0.0000002061871832 != -0.0000002061871831
13 : 0.0000000051749797 != 0.0000000051749797
15 : 0.0000000167198425 != 0.0000000167198425
17 : 0.0000000051749797 != 0.0000000051749797
30 : 0.0000001016675020 != 0.0000001016675021
...

@mingodad
Copy link
Contributor Author

mingodad commented Sep 2, 2022

It seems like using long in several places for wasm should be replaced by long long (that also would help in xcc to possible port it to windows).

@mingodad
Copy link
Contributor Author

mingodad commented Sep 2, 2022

When lexing integers we need to check the value range to classify then properly .

@tyfkda
Copy link
Owner

tyfkda commented Sep 5, 2022

I suspect that the difference between gcc/xcc-compiled and online-wcc
is caused from my own strtod implementation is inaccurate.

I think using printf("%.16f") is other topic and
I want it as is (or split issue).

@tyfkda
Copy link
Owner

tyfkda commented Feb 21, 2023

I'm gonna close this issue.

@tyfkda tyfkda closed this as completed Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants