Opened 9 years ago

Last modified 9 years ago

#9232 new Bugs

Template bloat

Reported by: Domagoj Šarić Owned by: John Maddock
Milestone: To Be Determined Component: multiprecision
Version: Boost 1.54.0 Severity: Optimization
Keywords: Cc:

Description

With integers of size N powm() will instantiate divide_unsigned_helper<> for N and N*2, since this is a very large function this leads to classical template bloat. Examining the codegen it appears that both instantiations are nearly identical save for immediate constants -> this would suggest that you could refactor divide_unsigned_helper<> (and probably the rest of the library) so that it separates functionality that actually depends on template parameters from template-parameter independent code into separate functions (in this case divide_unsigned_helper would probably call a helper function that takes the size of the number as a runtime parameter).

ps. even when different function template instantiations result in identical code there are _still_ lousy compilers&linkers that will not merge them (Clang we are looking at you: http://llvm.org/bugs/show_bug.cgi?id=11633)...

Change History (2)

comment:1 by John Maddock, 9 years ago

That's not so easy: divide_unsigned_helper calls a lot of other functions (add/subtract etc) which depend on the template parameters. So I don't believe the code is as close to identical as you think. I'll have to think this one over.

in reply to:  1 comment:2 by Domagoj Šarić, 9 years ago

Replying to johnmaddock:

That's not so easy: divide_unsigned_helper calls a lot of other functions (add/subtract etc) which depend on the template parameters. So I don't believe the code is as close to identical as you think.

As I said look at the codegen (in x64 builds the functions are even identical in size, for x86 they differ in a few bytes)...maybe the abstractions are "blinding you from the Truth" XD

ps. you might find other parts of your code that could do with a similar rework (this is unfortunately a standard 'plague' of many a 'modern C++ programer', 'top of the pops' Boost ones included)...

Note: See TracTickets for help on using tickets.