This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: bumming cycles out of parse_identifier()...


In article <20010910184614.A19582@daikokuya.demon.co.uk> you write:
>
>Well, we could eliminate the "cur < limit" check.  We naturally have
>to do this for every single character in the file.  The question
>becomes: does the savings of mmap () outweigh the savings of removing
>"cur < limit" checks from the fastpath?
>
>If we read the file into a buffer, like we currently do for pipes, we
>could terminate it with a NUL.  Then many of the checks could die,

You can _trivially_ do that with mmap too.

The only thing you need to do is to check if the length of the file is a
multiple of the page size, and if it is, you add one page of anonymous
mapping after the mapping of the file.  End of story - you get a '\0'
character at the end of the file for free 99.9% of the time, and the
remaining 0.1% of the time you just have to do one extra fixed mapping
at the end.  You already know the filesize through 'fstat', as you need
that for the mmap (and limit checking) anyway. 

In fact, you can, if you want to, equally trivially make sure that you
always have N number of '\0' characters at the end by just changing the
size test a bit (instead of checking for an exact multiple of the page
size, check for being "close"). 

Having extra NUL characters can help if you are going to do other
optimizations, like loading multiple characters in one go to find zeroes
or for prefetching reasons (although on every single architecture I know
of, you want that load to be aligned anyway, so you only need one '\0'
at the end - and no _sane_ architecture faults on prefetch). 

			Linus


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]