Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #55381
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Any ideas on faster TLS ? |
| Date | 2017-03-03 12:55 +0000 |
| Organization | Institut fuer Computersprachen, Technische Universitaet Wien |
| Message-ID | <2017Mar3.135535@mips.complang.tuwien.ac.at> (permalink) |
| References | (1 earlier) <yuednW2Kf9GZZC7FnZ2dnUU7-KHNnZ2d@supernews.com> <o911tb$rfl$1@dont-email.me> <2017Mar1.133612@mips.complang.tuwien.ac.at> <o96h6k$fc6$1@dont-email.me> <o9ag4s$fp2$1@dont-email.me> |
Alex <alex@rivadpm.com> writes:
>The problem is surely the double indirection. For a "standard" variable,
>I generate
>
>variable x ok
>: foo 10 x ! ; ok
> ok
>see foo
>: foo ( ? -- ? )
>\ foo is defined in (console)
>\ call compiled
>\ code=$41CA5E len=10 type=130
>( $0 ) mov dword { $80537C } $A \ C7057C5380000A000000
>( $A ) ret \ C3 ( end ) ok
>
>whereas a TLS variable based on a register (eg EBX) (a "user" variable)
>generates (the offset of Y up the TLS is $8C)
>
>0 user y ok
>: bar 10 y ! ; ok
>see bar
>: bar ( ? -- ? )
>\ bar is defined in (console)
>\ call compiled
>\ code=$41CAC8 len=10 type=129
>( $0 ) mov dword { $8C ebx } $A \ C7838C0000000A000000
>( $A ) ret \ C3 ( end ) ok
>
>If the TLS is addressed by FS: then it would be (and this code hand
>cranked, because my Forth doesn't generate this);
>
>code tls ok
>mov ecx { fs: $e10 } \ first TLS slot in the TEB at $E10 ok
>mov { ecx $8c } $a \ offset $8C for the TLS var ok[1]
>next; ok
>see tls
>code tls ( ? -- ? )
>\ tls is defined in (console)
>\ call compiled
>\ code=$41CA4F len=17 type=129
>( $0 ) mov ecx dword { fs: $E10 } \ 648B0D100E0000
>( $7 ) mov dword { $8C ecx } $A \ C7818C0000000A000000
>( $11 ) ret \ C3 ( end ) ok
>
>That's a lot more expensive; every reference is now twice through memory
>and with an FS segreg overide on one of the.
It's not clear why you would code it like this. I looked what gcc
generates for
volatile __thread long a;
int main()
{
long l=0;
long i;
for (i=0; i<100000000; i++)
a=10;
return 0;
}
and the inner loop becomes
5: movq $0xa,%fs:0x0
12: sub $0x1,%rax
16: jne 5 <main+0x5>
(the 0x0 is later filled with something sensible by the linker). For
this loop I see 1.00-1.17 cycles/iteration on a Haswell
(1 cycle/iteration is the limit, because the Haswell can only perform
one store per cycle).
Interestingly, without the "__thread" this becomes often slower in 64-bit
mode, with the inner loop looking as follows:
5: movq $0xa,0x0(%rip) # 10 <main+0x10>
10: sub $0x1,%rax
14: jne 5 <main+0x5>
With this I see 1.07-1.43 cycles per iteration.
The large variation in performance for both variants is interesting.
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2016: http://www.euroforth.org/ef16/
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Any ideas on faster TLS ? Ron Aaron <rambamist@gmail.com> - 2017-02-27 07:30 +0200
Re: Any ideas on faster TLS ? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2017-02-27 04:01 -0600
Re: Any ideas on faster TLS ? Ron Aaron <rambamist@gmail.com> - 2017-02-27 13:19 +0200
Re: Any ideas on faster TLS ? Alex <alex@rivadpm.com> - 2017-02-27 12:56 +0000
Re: Any ideas on faster TLS ? Ron Aaron <rambamist@gmail.com> - 2017-02-27 15:10 +0200
Re: Any ideas on faster TLS ? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2017-02-27 17:08 +0100
Re: Any ideas on faster TLS ? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2017-02-27 08:06 -0600
Re: Any ideas on faster TLS ? Ron Aaron <rambamist@gmail.com> - 2017-02-27 16:10 +0200
Re: Any ideas on faster TLS ? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2017-02-27 09:31 -0600
Re: Any ideas on faster TLS ? Ron Aaron <rambamist@gmail.com> - 2017-02-28 07:05 +0200
Re: Any ideas on faster TLS ? Paul Rubin <no.email@nospam.invalid> - 2017-02-27 23:15 -0800
Re: Any ideas on faster TLS ? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2017-02-28 04:02 -0600
Re: Any ideas on faster TLS ? Bernd Paysan <bernd@net2o.de> - 2017-03-11 19:58 +0000
Re: Any ideas on faster TLS ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-03-01 12:36 +0000
Re: Any ideas on faster TLS ? Ron Aaron <rambamist@gmail.com> - 2017-03-01 15:11 +0200
Re: Any ideas on faster TLS ? Alex <alex@rivadpm.com> - 2017-03-03 01:18 +0000
Re: Any ideas on faster TLS ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-03-03 12:55 +0000
Re: Any ideas on faster TLS ? Alex <alex@rivadpm.com> - 2017-03-03 14:59 +0000
Re: Any ideas on faster TLS ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-03-03 16:15 +0000
Optimizing (was: Any ideas on faster TLS ?) Ron Aaron <rambamist@gmail.com> - 2017-03-17 13:14 +0200
Re: Any ideas on faster TLS ? rickman <gnuarm@gmail.com> - 2017-02-28 01:13 -0500
Re: Any ideas on faster TLS ? Paul Rubin <no.email@nospam.invalid> - 2017-02-27 22:48 -0800
Re: Any ideas on faster TLS ? rickman <gnuarm@gmail.com> - 2017-02-28 03:50 -0500
csiph-web