[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: proposal for reading individual characters from strings faster
- From: Coroutines <coroutines@...>
- Date: Sat, 3 May 2014 14:12:27 -0700
On Sat, May 3, 2014 at 1:42 PM, Sean Conner <sean@conman.org> wrote:
> This is the realm of "compiler optimizations" and feelings about that
> differ. C has the keyword "register" to inform the C compiler that the
> following variable is to be kept in a register (and consequently, taking the
> address of such a variable is now impossible), to help the compiler with
> optimizations.
This is an optimization, but my intention is to make single-byte
comparisons clearer with this added syntax:
local LETT_A = string.byte 'a'
for x = 1, #s do if string[x] == LETT_A then do_something(s) end end
vs
for x = 1, #s do if string[x] == `a` then do_something(s) end end
The side benefit is `a` would be a compile-time transform to the
integer codepoint (an optimization), but I really feel it would look
more obvious to those reviewing.
>
> No one uses the keyword "register" anymore. The compilers have gotten
> very good about optimizing that.
If I had it my way I'd get rid of: auto, const, register, inline, and
restrict -- though something like llvm+clang still has trouble
figuring out where it can `restrict' things, so it's not totally dead.
>
> Part of the reason that Lua compiles so fast is that it does not to much
> in the way of optimization. TCC [1] is also fast [2] but does almost no
> optimization what-so-ever.
I do love TCC, a lot of people seem to use it for a C interpreter
interfaced with their IRC bots :-)
> So would
>
> @string.byte(somevar)
>
> be an error?
I don't currently want this, as I don't know in total what rules one
should follow by using it. Ideally it would evaluate if somevar
references another constant value, but if it were a simple mechanism
it would error saying it depends on the runtime value -- unless it's a
literal just error.
> [2] In 2006, a version of TCC could compile the Linux kernel in under
> ten seconds. It was used in a proof-of-concept system where, at
> boot time, the boot loader would compile Linux directly into memory.
That is really impressive! I didn't hear about that!