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

Optimize the strcmp chains in lex functions #12

Closed
mithro opened this issue Jul 7, 2019 · 2 comments
Closed

Optimize the strcmp chains in lex functions #12

mithro opened this issue Jul 7, 2019 · 2 comments

Comments

@mithro
Copy link
Member

mithro commented Jul 7, 2019

Currently you use the follow structure a lot;

enum_switch_type lex_switch_type(const char *in){
	if(strcmp(in, "mux") == 0){
		return enum_switch_type::MUX;
	}
	else if(strcmp(in, "tristate") == 0){
		return enum_switch_type::TRISTATE;
	}
	else if(strcmp(in, "pass_gate") == 0){
		return enum_switch_type::PASS_GATE;
	}
	else if(strcmp(in, "short") == 0){
		return enum_switch_type::SHORT;
	}
	else if(strcmp(in, "buffer") == 0){
		return enum_switch_type::BUFFER;
	}
	else throw std::runtime_error("Found unrecognized enum value " + std::string(in) + "of enum_switch_type.");
}

Do some profiling and figure out if there is a better way to do this. strcmp might actually turn out to be pretty fast here...

As doing this shouldn't change the external interface, so it is something we can leave till later.

@duck2
Copy link
Member

duck2 commented Jul 18, 2019

I found this to be a bottleneck and translated https://github.com/julian-klode/triehash to Python and integrated it with the program. It really speeds things up!

10 runs of the previous commit with some rr_graph(a month ago):
13.62 13.44 13.46 13.53 13.44 13.50 13.45 13.54 13.63
10 runs of the commit with tries:
9.43 9.67 9.38 9.46 9.49 9.34 9.39 9.49 9.36 9.43

Now, this implementation of trie depends on the fact that unaligned 64-bit accesses are not very slow in amd64 processors. However, it should be possible to add a knob and provide "flat" tries(checks every character separately) or strcmp chains for processors with slow unaligned access.

@duck2
Copy link
Member

duck2 commented Jul 31, 2019

This is done, with the remaining issue #21.

@duck2 duck2 closed this as completed Jul 31, 2019
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