Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.arch > #29292 > unrolled thread

Four significant reasons for a 12X word size

Started byjim.brakefield@ieee.org
First post2015-08-21 20:11 -0700
Last post2015-08-27 20:00 -0700
Articles 20 on this page of 138 — 30 participants

Back to article view | Back to comp.arch


Contents

  Four significant reasons for a 12X word size jim.brakefield@ieee.org - 2015-08-21 20:11 -0700
    Re: Four significant reasons for a 12X word size MitchAlsup <MitchAlsup@aol.com> - 2015-08-22 10:18 -0700
      Re: Four significant reasons for a 12X word size Quadibloc <jsavard@ecn.ab.ca> - 2015-08-22 12:16 -0700
        Re: Four significant reasons for a 12X word size Ivan Godard <ivan@millcomputing.com> - 2015-08-22 12:49 -0700
          Re: Four significant reasons for a 12X word size jim.brakefield@ieee.org - 2015-09-01 12:34 -0700
            Re: Four significant reasons for a 12X word size Ivan Godard <ivan@millcomputing.com> - 2015-09-01 12:59 -0700
              Re: Four significant reasons for a 12X word size jim.brakefield@ieee.org - 2015-09-01 13:29 -0700
                Re: Four significant reasons for a 12X word size Ivan Godard <ivan@millcomputing.com> - 2015-09-01 15:36 -0700
                  Re: Four significant reasons for a 12X word size jim.brakefield@ieee.org - 2015-09-01 17:07 -0700
                    Re: Four significant reasons for a 12X word size Ivan Godard <ivan@millcomputing.com> - 2015-09-01 18:12 -0700
                      Re: Four significant reasons for a 12X word size Quadibloc <jsavard@ecn.ab.ca> - 2015-09-01 20:39 -0700
                        Re: Four significant reasons for a 12X word size Ivan Godard <ivan@millcomputing.com> - 2015-09-01 21:30 -0700
                          Permute registers (was: Four significant reasons for a 12X word size) Stefan Monnier <monnier@iro.umontreal.ca> - 2015-09-04 15:36 -0400
                            Re: Permute registers (was: Four significant reasons for a 12X word size) jim.brakefield@ieee.org - 2015-09-04 13:18 -0700
                              Re: Permute registers Ivan Godard <ivan@millcomputing.com> - 2015-09-04 13:41 -0700
                            Re: Permute registers Ivan Godard <ivan@millcomputing.com> - 2015-09-04 13:27 -0700
                    Re: Four significant reasons for a 12X word size Ivan Godard <ivan@millcomputing.com> - 2015-09-01 18:15 -0700
                    A good Mill intro (external) Ivan Godard <ivan@millcomputing.com> - 2015-09-01 18:43 -0700
                    Re: Four significant reasons for a 12X word size Quadibloc <jsavard@ecn.ab.ca> - 2015-09-01 20:52 -0700
                      Re: Four significant reasons for a 12X word size Bruce Hoult <bruce.hoult@gmail.com> - 2015-09-02 04:03 -0700
                        Re: Four significant reasons for a 12X word size Quadibloc <jsavard@ecn.ab.ca> - 2015-09-02 05:59 -0700
                        Re: Four significant reasons for a 12X word size Quadibloc <jsavard@ecn.ab.ca> - 2015-09-02 06:11 -0700
                          Re: Four significant reasons for a 12X word size Bruce Hoult <bruce.hoult@gmail.com> - 2015-09-02 07:15 -0700
                            Re: Four significant reasons for a 12X word size Chris Gray <cg@GraySage.COM> - 2015-09-02 10:42 -0600
                              Re: Four significant reasons for a 12X word size Anssi Saari <as@sci.fi> - 2015-09-03 11:32 +0300
                            Re: Four significant reasons for a 12X word size Quadibloc <jsavard@ecn.ab.ca> - 2015-09-02 10:03 -0700
                              Re: Four significant reasons for a 12X word size Bruce Hoult <bruce.hoult@gmail.com> - 2015-09-02 11:54 -0700
                              Re: Four significant reasons for a 12X word size Chris Gray <cg@GraySage.COM> - 2015-09-03 11:00 -0600
                                Re: Four significant reasons for a 12X word size Bruce Hoult <bruce.hoult@gmail.com> - 2015-09-03 10:11 -0700
                                Re: Four significant reasons for a 12X word size Jan Coombs <Jan-54 <jenfhaomndgfwutc@murmic.plus.com>> - 2015-09-04 09:35 +0100
        Re: Four significant reasons for a 12X word size jim.brakefield@ieee.org - 2015-08-22 12:51 -0700
          Re: Four significant reasons for a 12X word size Quadibloc <jsavard@ecn.ab.ca> - 2015-08-22 13:11 -0700
            Re: Four significant reasons for a 12X word size BGB <cr88192@hotmail.com> - 2015-08-23 11:14 -0500
              Re: Four significant reasons for a 12X word size jim.brakefield@ieee.org - 2015-08-23 11:13 -0700
                Re: Four significant reasons for a 12X word size BGB <cr88192@hotmail.com> - 2015-08-23 14:33 -0500
                  Re: Four significant reasons for a 12X word size thomas.entner99@gmail.com - 2015-08-23 16:23 -0700
                    Re: Four significant reasons for a 12X word size Quadibloc <jsavard@ecn.ab.ca> - 2015-08-23 17:43 -0700
                      Re: Four significant reasons for a 12X word size thomas.entner99@gmail.com - 2015-08-23 18:00 -0700
                        Re: Four significant reasons for a 12X word size jim.brakefield@ieee.org - 2015-08-23 19:14 -0700
                      Re: Four significant reasons for a 12X word size BGB <cr88192@hotmail.com> - 2015-08-23 20:00 -0500
                      Re: Four significant reasons for a 12X word size Bruce Hoult <bruce.hoult@gmail.com> - 2015-08-24 04:59 -0700
                        Re: Four significant reasons for a 12X word size Terje Mathisen <terje.mathisen@tmsw.no> - 2015-08-24 18:45 +0200
                          Re: Four significant reasons for a 12X word size nmm@needham.csi.cam.ac.uk (Nick Maclaren) - 2015-08-24 19:09 +0100
                          Re: Four significant reasons for a 12X word size jim.brakefield@ieee.org - 2015-08-24 13:31 -0700
                          Re: Four significant reasons for a 12X word size Quadibloc <jsavard@ecn.ab.ca> - 2015-08-24 14:09 -0700
                            Re: Four significant reasons for a 12X word size jgd@cix.co.uk (John Dallman) - 2015-08-24 22:26 +0100
                              Re: Four significant reasons for a 12X word size anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-08-25 10:29 +0000
                          Re: Four significant reasons for a 12X word size Quadibloc <jsavard@ecn.ab.ca> - 2015-08-24 16:22 -0700
                          Re: Four significant reasons for a 12X word size MitchAlsup <MitchAlsup@aol.com> - 2015-08-24 16:58 -0700
                            Re: Four significant reasons for a 12X word size Quadibloc <jsavard@ecn.ab.ca> - 2015-08-24 18:48 -0700
                            Re: Four significant reasons for a 12X word size anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-08-25 09:04 +0000
                              Re: Four significant reasons for a 12X word size BGB <cr88192@hotmail.com> - 2015-08-25 09:32 -0500
                                Re: Four significant reasons for a 12X word size Bruce Hoult <bruce.hoult@gmail.com> - 2015-08-25 10:30 -0700
                                  Re: Four significant reasons for a 12X word size Terje Mathisen <terje.mathisen@tmsw.no> - 2015-08-25 21:27 +0200
                                    Re: Four significant reasons for a 12X word size Bruce Hoult <bruce.hoult@gmail.com> - 2015-08-25 13:51 -0700
                                      Re: Four significant reasons for a 12X word size Terje Mathisen <terje.mathisen@tmsw.no> - 2015-08-26 08:31 +0200
                                  Re: Four significant reasons for a 12X word size MitchAlsup <MitchAlsup@aol.com> - 2015-08-25 16:56 -0700
                                    Re: Four significant reasons for a 12X word size Ivan Godard <ivan@millcomputing.com> - 2015-08-25 17:36 -0700
                                  Re: Four significant reasons for a 12X word size BGB <cr88192@hotmail.com> - 2015-08-25 20:10 -0500
                                    Re: Four significant reasons for a 12X word size Bruce Hoult <bruce.hoult@gmail.com> - 2015-08-26 02:41 -0700
                                      Re: Four significant reasons for a 12X word size BGB <cr88192@hotmail.com> - 2015-08-26 09:28 -0500
                                  Re: Four significant reasons for a 12X word size Waldek Hebisch <hebisch@antispam.uni.wroc.pl> - 2015-08-27 00:53 +0000
                          Re: Four significant reasons for a 12X word size jgk@panix.com (Joe keane) - 2015-08-25 18:30 +0000
                            Re: Four significant reasons for a 12X word size Terje Mathisen <terje.mathisen@tmsw.no> - 2015-08-25 21:31 +0200
                              Re: Four significant reasons for a 12X word size BGB <cr88192@hotmail.com> - 2015-08-25 20:40 -0500
                                Re: Four significant reasons for a 12X word size anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-08-26 09:24 +0000
                                  Re: Four significant reasons for a 12X word size BGB <cr88192@hotmail.com> - 2015-08-26 08:09 -0500
                                    Re: Four significant reasons for a 12X word size anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-08-26 14:35 +0000
                                      Re: Four significant reasons for a 12X word size BGB <cr88192@hotmail.com> - 2015-08-26 10:29 -0500
                                        Re: Four significant reasons for a 12X word size anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-08-26 16:17 +0000
                                          Re: Four significant reasons for a 12X word size BGB <cr88192@hotmail.com> - 2015-08-26 17:42 -0500
                                            Re: Four significant reasons for a 12X word size anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-08-27 13:51 +0000
                                              Re: Four significant reasons for a 12X word size BGB <cr88192@hotmail.com> - 2015-08-27 10:50 -0500
                                              Re: Four significant reasons for a 12X word size Michael S <already5chosen@yahoo.com> - 2015-08-28 04:44 -0700
                                                Re: Four significant reasons for a 12X word size BGB <cr88192@hotmail.com> - 2015-08-28 08:22 -0500
                                        Re: Four significant reasons for a 12X word size Terje Mathisen <terje.mathisen@tmsw.no> - 2015-08-26 22:32 +0200
                                          Re: Four significant reasons for a 12X word size BGB <cr88192@hotmail.com> - 2015-08-26 18:25 -0500
                            Re: Four significant reasons for a 12X word size anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-08-26 09:15 +0000
                              Re: Four significant reasons for a 12X word size Quadibloc <jsavard@ecn.ab.ca> - 2015-08-26 06:28 -0700
                                Re: Four significant reasons for a 12X word size anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-08-26 13:54 +0000
                                Re: Four significant reasons for a 12X word size BGB <cr88192@hotmail.com> - 2015-08-26 09:53 -0500
                                Re: Four significant reasons for a 12X word size Stefan Monnier <monnier@iro.umontreal.ca> - 2015-08-28 11:22 -0400
                                  Re: Four significant reasons for a 12X word size BGB <cr88192@hotmail.com> - 2015-08-28 16:09 -0500
                                    Re: Four significant reasons for a 12X word size Terje Mathisen <terje.mathisen@tmsw.no> - 2015-08-29 14:54 +0200
                                      character encoding (was: Four significant reasons for a 12X word size) anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-08-29 14:05 +0000
                                        Re: character encoding Terje Mathisen <terje.mathisen@tmsw.no> - 2015-08-29 19:10 +0200
                                          Re: character encoding nmm@needham.csi.cam.ac.uk (Nick Maclaren) - 2015-08-29 18:25 +0100
                                            Re: character encoding Terje Mathisen <terje.mathisen@tmsw.no> - 2015-08-29 21:03 +0200
                                        Re: character encoding Ivan Godard <ivan@millcomputing.com> - 2015-08-29 10:32 -0700
                                          Re: character encoding nmm@needham.csi.cam.ac.uk (Nick Maclaren) - 2015-08-29 18:37 +0100
                                            Re: character encoding Ivan Godard <ivan@millcomputing.com> - 2015-08-29 10:53 -0700
                                              Re: character encoding nmm@needham.csi.cam.ac.uk (Nick Maclaren) - 2015-08-29 19:12 +0100
                                          Re: character encoding anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-08-29 17:35 +0000
                                            Re: character encoding Ivan Godard <ivan@millcomputing.com> - 2015-08-29 10:44 -0700
                                              Re: character encoding anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-08-29 17:55 +0000
                                                Re: character encoding anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2015-08-31 11:23 +0000
                                                  Re: character encoding Terje Mathisen <terje.mathisen@tmsw.no> - 2015-08-31 14:18 +0200
                                              Re: character encoding Terje Mathisen <terje.mathisen@tmsw.no> - 2015-08-29 21:20 +0200
                                          Re: character encoding Terje Mathisen <terje.mathisen@tmsw.no> - 2015-08-29 21:11 +0200
                                      Re: Four significant reasons for a 12X word size BGB <cr88192@hotmail.com> - 2015-08-29 12:19 -0500
                                  Re: Four significant reasons for a 12X word size Quadibloc <jsavard@ecn.ab.ca> - 2015-08-29 07:41 -0700
                                    Re: Four significant reasons for a 12X word size Terje Mathisen <terje.mathisen@tmsw.no> - 2015-08-29 19:12 +0200
                                      Re: Four significant reasons for a 12X word size nmm@needham.csi.cam.ac.uk (Nick Maclaren) - 2015-08-29 18:23 +0100
                                        Re: Four significant reasons for a 12X word size BGB <cr88192@hotmail.com> - 2015-08-29 17:17 -0500
                                    Re: Four significant reasons for a 12X word size George Neuner <gneuner2@comcast.net> - 2015-08-29 14:57 -0400
                                      Re: Four significant reasons for a 12X word size jim.brakefield@ieee.org - 2015-08-29 12:40 -0700
                                        Re: Four significant reasons for a 12X word size Terje Mathisen <terje.mathisen@tmsw.no> - 2015-08-30 00:05 +0200
                        Re: Four significant reasons for a 12X word size EricP <ThatWouldBeTelling@thevillage.com> - 2015-08-24 13:16 -0400
                          Re: Four significant reasons for a 12X word size EricP <ThatWouldBeTelling@thevillage.com> - 2015-08-24 13:29 -0400
                          Re: Four significant reasons for a 12X word size mrs@kithrup.com (Mike Stump) - 2015-08-24 21:32 +0000
                            Re: Four significant reasons for a 12X word size Terje Mathisen <terje.mathisen@tmsw.no> - 2015-08-25 08:49 +0200
                              Re: Four significant reasons for a 12X word size mrs@kithrup.com (Mike Stump) - 2015-08-25 22:43 +0000
                                Re: Four significant reasons for a 12X word size EricP <ThatWouldBeTelling@thevillage.com> - 2015-08-25 21:55 -0400
                                  Re: Four significant reasons for a 12X word size paul wallich <pw@panix.com> - 2015-08-25 22:12 -0400
                                    Re: Four significant reasons for a 12X word size EricP <ThatWouldBeTelling@thevillage.com> - 2015-08-26 13:54 -0400
                                      Re: Four significant reasons for a 12X word size Stephen Fuld <SFuld@alumni.cmu.edu.invalid> - 2015-08-26 11:47 -0700
                                        Re: Four significant reasons for a 12X word size mac <acolvin@efunct.com> - 2015-08-27 16:15 +0000
                                          Re: Four significant reasons for a 12X word size Stephen Fuld <SFuld@alumni.cmu.edu.invalid> - 2015-08-27 10:44 -0700
                                            Re: Four significant reasons for a 12X word size rpw3@rpw3.org (Rob Warnock) - 2015-08-28 06:09 +0000
                                        Re: Four significant reasons for a 12X word size EricP <ThatWouldBeTelling@thevillage.com> - 2015-08-28 12:23 -0400
                                Re: Four significant reasons for a 12X word size Terje Mathisen <terje.mathisen@tmsw.no> - 2015-08-26 08:37 +0200
                                  Re: Four significant reasons for a 12X word size mrs@kithrup.com (Mike Stump) - 2015-08-26 22:54 +0000
                                    Re: Four significant reasons for a 12X word size Terje Mathisen <terje.mathisen@tmsw.no> - 2015-08-27 07:48 +0200
                                      Re: Four significant reasons for a 12X word size mrs@kithrup.com (Mike Stump) - 2015-08-27 16:30 +0000
                    Re: Four significant reasons for a 12X word size jim.brakefield@ieee.org - 2015-08-23 19:09 -0700
                      Re: Four significant reasons for a 12X word size Megol <golem960@gmail.com> - 2015-08-24 04:32 -0700
                        Re: Four significant reasons for a 12X word size R Kym Horsell <kym@kymhorsell.com> - 2015-08-24 11:37 +0000
    Re: Four significant reasons for a 12X word size Quadibloc <jsavard@ecn.ab.ca> - 2015-08-22 12:56 -0700
      Re: Four significant reasons for a 12X word size Quadibloc <jsavard@ecn.ab.ca> - 2015-08-22 13:10 -0700
      Re: Four significant reasons for a 12X word size Quadibloc <jsavard@ecn.ab.ca> - 2015-08-22 17:17 -0700
      Re: Four significant reasons for a 12X word size jim.brakefield@ieee.org - 2015-08-22 19:59 -0700
        Re: Four significant reasons for a 12X word size jim.brakefield@ieee.org - 2015-09-01 12:47 -0700
    Re: Four significant reasons for a 12X word size jim.brakefield@ieee.org - 2015-08-22 20:10 -0700
    Re: Four significant reasons for a 12X word size Robert Wessel <robertwessel2@yahoo.com> - 2015-08-23 21:41 -0500
      Re: Four significant reasons for a 12X word size BGB <cr88192@hotmail.com> - 2015-08-24 10:53 -0500
    Re: Four significant reasons for a 12X word size Robert Miles <robertmilesxyz@gmail.com> - 2015-08-26 17:39 -0700
      Re: Four significant reasons for a 12X word size Terje Mathisen <terje.mathisen@tmsw.no> - 2015-08-27 07:52 +0200
        Re: Four significant reasons for a 12X word size spamkiller539@gmail.com - 2015-08-27 20:00 -0700

Page 5 of 7 — ← Prev page 1 2 3 4 [5] 6 7  Next page →


#29429

FromBGB <cr88192@hotmail.com>
Date2015-08-26 09:53 -0500
Message-ID<mrkk7d$emq$1@news.albasani.net>
In reply to#29420
On 8/26/2015 8:28 AM, Quadibloc wrote:
> On Wednesday, August 26, 2015 at 3:19:09 AM UTC-6, Anton Ertl wrote:
>> Among
>> variable-width character encodings, UTF-8 is superior to UTF-16.
>
> That depends which characters you're using. With UTF-8, only 7-bit ASCII fits in 8 bits; then, a limited group of characters fits in 16 bits. With UTF-16, all the original Unicode characters are 16 bits, only the more exotic characters take up more space.
>

IIRC, pretty much all of Europe fits into the 16-bit UTF-8 space.
CJK takes it pretty hard with UTF-8, and is better stored as UTF-16.

CP-1252 does better for western Europe, as then pretty much everything 
fits in 8 bits, but doesn't deal with out-of-range characters.


a possible hack scheme could be:
00-7F: pass through (0000-007F)
A0-FF: pass through (00A0-00FF)

90-97 XX         :     0000-    07FF
98-9B XX XX      :    00000-   3FFFF
9C-9D XX XX XX   :  0000000- 1FFFFFF
9E    XX XX XX XX: 00000000-FFFFFFFF
9F <reserved>

while it loses some theoretical abilities of UTF-8, it would likely be 
more compact on-average.

[toc] | [prev] | [next] | [standalone]


#29526

FromStefan Monnier <monnier@iro.umontreal.ca>
Date2015-08-28 11:22 -0400
Message-ID<jwvwpwfsaqq.fsf-monnier+comp.arch@gnu.org>
In reply to#29420
> That depends which characters you're using. With UTF-8, only 7-bit ASCII
> fits in 8 bits; then, a limited group of characters fits in 16 bits. With
> UTF-16, all the original Unicode characters are 16 bits, only the more
> exotic characters take up more space.

UTF-16 leads to code which fails if you use characters outside of the
base-plane, because they're rare enough that the programmers just didn't
take it into account.

If you can't eliminate the "unusual case", you're often better off
making it frequent, so it's handled reliably.


        Stefan "utf-16 sucks"


PS: Other problems with utf-16 include the byte-ordering, which requires
a BOM thingy (one of those "unusual cases" which you *can* get rid of,
e.g. by using any other encoding) which is of course only present at the
beginning of documents but not in sub-chunks, hence complicating
splitting, concatenation, ...

[toc] | [prev] | [next] | [standalone]


#29538

FromBGB <cr88192@hotmail.com>
Date2015-08-28 16:09 -0500
Message-ID<mrqj03$m8g$1@news.albasani.net>
In reply to#29526
On 8/28/2015 10:22 AM, Stefan Monnier wrote:
>> That depends which characters you're using. With UTF-8, only 7-bit ASCII
>> fits in 8 bits; then, a limited group of characters fits in 16 bits. With
>> UTF-16, all the original Unicode characters are 16 bits, only the more
>> exotic characters take up more space.
>
> UTF-16 leads to code which fails if you use characters outside of the
> base-plane, because they're rare enough that the programmers just didn't
> take it into account.
>
> If you can't eliminate the "unusual case", you're often better off
> making it frequent, so it's handled reliably.
>

possible, but then one is less either with all the code needing to deal 
with UTF-8 (typical case in C), or an overly wasteful wide-character 
format (32-bit characters). in-general, UTF-32 is undesirable for 
strings, as they can already end up eating a fair bit of RAM with 
narrower encodings (ASCII or UTF-16).

the partial attraction of UTF-16 is that it works pretty good "for the 
most part", apart from the occasional need to deal with surrogate pairs, 
or one can ignore them and basically have BMP only characters (basically 
limits things to a subset of the CJK space).

though, it can be tempting to use more compact formats for cases which 
can be handled well with an ASCII codepage (more so if it can be done 
fairly transparently, so user-level code doesn't really need to 
know/care too much what codepage the string uses, it just works 
automagically).


for strings generated at runtime though, a partial issue is efficiently 
"fingerprinting" the strings, so probably only a small number of 
codepages would be supported (a basic fingerprinting based scheme could 
encode strings with 2 passes and a modest-sized lookup table, with the 
first pass identifying which codepages are applicable, and the 2nd pass 
encoding the string with the chosen codepage and/or falling back to 
UTF-16 if no match was found).

this would be left as a runtime feature and mostly invisible to 
user-level code.


>
>          Stefan "utf-16 sucks"
>
>
> PS: Other problems with utf-16 include the byte-ordering, which requires
> a BOM thingy (one of those "unusual cases" which you *can* get rid of,
> e.g. by using any other encoding) which is of course only present at the
> beginning of documents but not in sub-chunks, hence complicating
> splitting, concatenation, ...
>

big suck point for files, as well as them needing generally around 2x as 
much space for ASCII-only text.

BOM is N/A for strings, given the characters are always in whatever is 
the native endianess...


basically, text files and string literals are very different use-cases...

[toc] | [prev] | [next] | [standalone]


#29548

FromTerje Mathisen <terje.mathisen@tmsw.no>
Date2015-08-29 14:54 +0200
Message-ID<mrsa2u$1q1$1@speranza.aioe.org>
In reply to#29538
BGB wrote:
> On 8/28/2015 10:22 AM, Stefan Monnier wrote:
>> If you can't eliminate the "unusual case", you're often better off
>> making it frequent, so it's handled reliably.
>>
Very true words!

I've been arguing for years that distributed/fault-tolerant systems 
needs to be exercised about once per month, by pulling the cord on one 
or more instances: Only when you are comfortable doing this can you also 
schedule all maintenance for regular operating hours, with no need for 
all those late nights and weekends that the families of IT people have 
come to hate.
>
> possible, but then one is less either with all the code needing to deal
> with UTF-8 (typical case in C), or an overly wasteful wide-character
> format (32-bit characters). in-general, UTF-32 is undesirable for
> strings, as they can already end up eating a fair bit of RAM with
> narrower encodings (ASCII or UTF-16).

David Stafford's version of my .sig replaces caching by compression: 
utf-8 is a quite effective way to encode text for an international audience.

If there is significant/frequent need for random access into very long 
text strings, then we should look at various alternative encodings:

a) Flat 32-bit/char allows O(1) lookup but wastes almost 75% for most text.

b) Plain utf-8 adds a few percent to the size of a fixed 8-bit only 
character set like the one used by classic Windows, but cannot handle 
but increases the average random access time from O(1) to O(N)

c) utf-8 plus a strided index, i.e. an array of pointers into every M 
starting positions adds 32/M bits of overhead per char but allows 
effectively fixed-time O(1) access to any given character position.

d) A variant of (c) is an array of variably sized chunks, like 
paragraphs, with a header stating the current chunk size (used and 
allocated).

I've written a couple of editors which used (d), it makes it easy/fast 
to get to any given position. With the classic gap approach where the 
spare room in the current chunk is located just after the cursor you can 
both insert and delete text without having to move anything around.

Terje
-- 
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"

[toc] | [prev] | [next] | [standalone]


#29552 — character encoding (was: Four significant reasons for a 12X word size)

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2015-08-29 14:05 +0000
Subjectcharacter encoding (was: Four significant reasons for a 12X word size)
Message-ID<2015Aug29.160513@mips.complang.tuwien.ac.at>
In reply to#29548
Terje Mathisen <terje.mathisen@tmsw.no> writes:
>If there is significant/frequent need for random access into very long 
>text strings,

I thought about such needs for quite a while, and the only things I
came up with were palindrome checkers and anagram generators; and come
to think of it, both can be coded without random access (palindromes
need backwards stride, but that's just as easy as forward stride in
UTF-8).

So, is there actually a real-world application of random
character-count access into long text strings that cannot be rewritten
to use a variable-width encoding like UTF-8 (or UTF-16) at a similar
or better efficiency?

> then we should look at various alternative encodings:
>
>a) Flat 32-bit/char allows O(1) lookup but wastes almost 75% for most text.

Does not work because of composite characters.  But even if it there
were no composite characters, I don't see any real advantages, see
above.

>c) utf-8 plus a strided index, i.e. an array of pointers into every M 
>starting positions adds 32/M bits of overhead per char but allows 
>effectively fixed-time O(1) access to any given character position.
>
>d) A variant of (c) is an array of variably sized chunks, like 
>paragraphs, with a header stating the current chunk size (used and 
>allocated).
>
>I've written a couple of editors which used (d), it makes it easy/fast 
>to get to any given position. With the classic gap approach where the 
>spare room in the current chunk is located just after the cursor you can 
>both insert and delete text without having to move anything around.

But if you have the classic gap approach, moving to a specific
position is an O(n) operation anyway whether you specify that position
in bytes or in characters.

- anton
-- 
M. Anton Ertl                    Some things have to be seen to be believed
anton@mips.complang.tuwien.ac.at Most things have to be believed to be seen
http://www.complang.tuwien.ac.at/anton/home.html

[toc] | [prev] | [next] | [standalone]


#29554 — Re: character encoding

FromTerje Mathisen <terje.mathisen@tmsw.no>
Date2015-08-29 19:10 +0200
SubjectRe: character encoding
Message-ID<mrsp1s$5qs$1@speranza.aioe.org>
In reply to#29552
anton@mips.complang.tuwien.ac.at (Anton Ertl) wrote:
> Terje Mathisen <terje.mathisen@tmsw.no> writes:
>> If there is significant/frequent need for random access into very long
>> text strings,
>
> I thought about such needs for quite a while, and the only things I
> came up with were palindrome checkers and anagram generators; and come
> to think of it, both can be coded without random access (palindromes
> need backwards stride, but that's just as easy as forward stride in
> UTF-8).
>
> So, is there actually a real-world application of random
> character-count access into long text strings that cannot be rewritten
> to use a variable-width encoding like UTF-8 (or UTF-16) at a similar
> or better efficiency?
>
>> then we should look at various alternative encodings:
>>
>> a) Flat 32-bit/char allows O(1) lookup but wastes almost 75% for most text.
>
> Does not work because of composite characters.  But even if it there
> were no composite characters, I don't see any real advantages, see
> above.

OK, I don't like it anyway. :-)
>
>> c) utf-8 plus a strided index, i.e. an array of pointers into every M
>> starting positions adds 32/M bits of overhead per char but allows
>> effectively fixed-time O(1) access to any given character position.
>>
>> d) A variant of (c) is an array of variably sized chunks, like
>> paragraphs, with a header stating the current chunk size (used and
>> allocated).
>>
>> I've written a couple of editors which used (d), it makes it easy/fast
>> to get to any given position. With the classic gap approach where the
>> spare room in the current chunk is located just after the cursor you can
>> both insert and delete text without having to move anything around.
>
> But if you have the classic gap approach, moving to a specific
> position is an O(n) operation anyway whether you specify that position
> in bytes or in characters.

Huh?

The key idea is that you have many chunks, each of a strictly limited 
maximum size, this is what allows fast access.

Worst case you'll add an index layer providing the starting offset into 
each of these chunks, or you organize them in a tree structure to give 
O(log N) random access.

Terje

-- 
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"

[toc] | [prev] | [next] | [standalone]


#29558 — Re: character encoding

Fromnmm@needham.csi.cam.ac.uk (Nick Maclaren)
Date2015-08-29 18:25 +0100
SubjectRe: character encoding
Message-ID<mrspuh$nra$1@needham.csi.cam.ac.uk>
In reply to#29554
In article <mrsp1s$5qs$1@speranza.aioe.org>,
Terje Mathisen  <terje.mathisen@tmsw.no> wrote:
>
>The key idea is that you have many chunks, each of a strictly limited 
>maximum size, this is what allows fast access.
>
>Worst case you'll add an index layer providing the starting offset into 
>each of these chunks, or you organize them in a tree structure to give 
>O(log N) random access.

Which technique predates both of us, and has been never out of use
since.


Regards,
Nick Maclaren.

[toc] | [prev] | [next] | [standalone]


#29570 — Re: character encoding

FromTerje Mathisen <terje.mathisen@tmsw.no>
Date2015-08-29 21:03 +0200
SubjectRe: character encoding
Message-ID<mrsvml$k73$1@speranza.aioe.org>
In reply to#29558
nmm@needham.csi.cam.ac.uk (Nick Maclaren) wrote:
> In article <mrsp1s$5qs$1@speranza.aioe.org>,
> Terje Mathisen  <terje.mathisen@tmsw.no> wrote:
>>
>> The key idea is that you have many chunks, each of a strictly limited
>> maximum size, this is what allows fast access.
>>
>> Worst case you'll add an index layer providing the starting offset into
>> each of these chunks, or you organize them in a tree structure to give
>> O(log N) random access.
>
> Which technique predates both of us, and has been never out of use
> since.

Sure! Even when I first used this approach I never dreamed that I had 
just invented anything new. :-)

Terje

-- 
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"

[toc] | [prev] | [next] | [standalone]


#29559 — Re: character encoding

FromIvan Godard <ivan@millcomputing.com>
Date2015-08-29 10:32 -0700
SubjectRe: character encoding
Message-ID<mrsq8m$ug5$1@dont-email.me>
In reply to#29552
On 8/29/2015 7:05 AM, Anton Ertl wrote:
> Terje Mathisen <terje.mathisen@tmsw.no> writes:
>> If there is significant/frequent need for random access into very long
>> text strings,
>
> I thought about such needs for quite a while, and the only things I
> came up with were palindrome checkers and anagram generators; and come
> to think of it, both can be coded without random access (palindromes
> need backwards stride, but that's just as easy as forward stride in
> UTF-8).
>
> So, is there actually a real-world application of random
> character-count access into long text strings that cannot be rewritten
> to use a variable-width encoding like UTF-8 (or UTF-16) at a similar
> or better efficiency?

grep? The sub-linear search contains a p+=n step.

[toc] | [prev] | [next] | [standalone]


#29561 — Re: character encoding

Fromnmm@needham.csi.cam.ac.uk (Nick Maclaren)
Date2015-08-29 18:37 +0100
SubjectRe: character encoding
Message-ID<mrsqlm$o3d$1@needham.csi.cam.ac.uk>
In reply to#29559
In article <mrsq8m$ug5$1@dont-email.me>,
Ivan Godard  <ivan@millcomputing.com> wrote:
>On 8/29/2015 7:05 AM, Anton Ertl wrote:
>> Terje Mathisen <terje.mathisen@tmsw.no> writes:
>>> If there is significant/frequent need for random access into very long
>>> text strings,
>>
>> I thought about such needs for quite a while, and the only things I
>> came up with were palindrome checkers and anagram generators; and come
>> to think of it, both can be coded without random access (palindromes
>> need backwards stride, but that's just as easy as forward stride in
>> UTF-8).
>>
>> So, is there actually a real-world application of random
>> character-count access into long text strings that cannot be rewritten
>> to use a variable-width encoding like UTF-8 (or UTF-16) at a similar
>> or better efficiency?
>
>grep? The sub-linear search contains a p+=n step.

No, sorry.  The algorithm can be written to be purely linear.
For very long strings, there are lots of optimisations, but none
are critically dependent on random access.

There are algorithms that need some 'random' indexing, but I
don't know of any where it is as important as it is to pivoting
in linear algebra.  There may be some, of course.


Regards,
Nick Maclaren.

[toc] | [prev] | [next] | [standalone]


#29564 — Re: character encoding

FromIvan Godard <ivan@millcomputing.com>
Date2015-08-29 10:53 -0700
SubjectRe: character encoding
Message-ID<mrsrev$49k$1@dont-email.me>
In reply to#29561
On 8/29/2015 10:37 AM, Nick Maclaren wrote:
> In article <mrsq8m$ug5$1@dont-email.me>,
> Ivan Godard  <ivan@millcomputing.com> wrote:

>> grep? The sub-linear search contains a p+=n step.
>
> No, sorry.  The algorithm can be written to be purely linear.
> For very long strings, there are lots of optimisations, but none
> are critically dependent on random access.
>
> There are algorithms that need some 'random' indexing, but I
> don't know of any where it is as important as it is to pivoting
> in linear algebra.  There may be some, of course.

But the algorithm is sub-linear, and quite a bit so in practice. p+=n is 
not as bad as S[m} because n tends to be smallish while m is big, but it 
still imposes a linear search on the increment, which changes the 
algorithm from sub-linear to linear. I suspect the difference would be 
visible in use.

[toc] | [prev] | [next] | [standalone]


#29567 — Re: character encoding

Fromnmm@needham.csi.cam.ac.uk (Nick Maclaren)
Date2015-08-29 19:12 +0100
SubjectRe: character encoding
Message-ID<mrssmb$us4$1@needham.csi.cam.ac.uk>
In reply to#29564
In article <mrsrev$49k$1@dont-email.me>,
Ivan Godard  <ivan@millcomputing.com> wrote:
>On 8/29/2015 10:37 AM, Nick Maclaren wrote:
>> In article <mrsq8m$ug5$1@dont-email.me>,
>> Ivan Godard  <ivan@millcomputing.com> wrote:
>
>>> grep? The sub-linear search contains a p+=n step.
>>
>> No, sorry.  The algorithm can be written to be purely linear.
>> For very long strings, there are lots of optimisations, but none
>> are critically dependent on random access.
>>
>> There are algorithms that need some 'random' indexing, but I
>> don't know of any where it is as important as it is to pivoting
>> in linear algebra.  There may be some, of course.
>
>But the algorithm is sub-linear, and quite a bit so in practice. p+=n is 
>not as bad as S[m} because n tends to be smallish while m is big, but it 
>still imposes a linear search on the increment, which changes the 
>algorithm from sub-linear to linear. I suspect the difference would be 
>visible in use.

Grep?  I haven't looked at the code, but I have written several
regular expression handlers, and any sub-linearity is necessarily in
one of the optimisations.  As there are plenty to choose from, I
would just go for one or more of the others.


Regards,
Nick Maclaren.

[toc] | [prev] | [next] | [standalone]


#29562 — Re: character encoding

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2015-08-29 17:35 +0000
SubjectRe: character encoding
Message-ID<2015Aug29.193554@mips.complang.tuwien.ac.at>
In reply to#29559
Ivan Godard <ivan@millcomputing.com> writes:
>On 8/29/2015 7:05 AM, Anton Ertl wrote:
>> So, is there actually a real-world application of random
>> character-count access into long text strings that cannot be rewritten
>> to use a variable-width encoding like UTF-8 (or UTF-16) at a similar
>> or better efficiency?
>
>grep? The sub-linear search contains a p+=n step.

You mean something like Boyer-Moore search?  No need to deal with
characters, just consider the input string and the search string as
strings of bytes (or, for UTF-16, as strings of 16-bit thingies).

- anton
-- 
M. Anton Ertl                    Some things have to be seen to be believed
anton@mips.complang.tuwien.ac.at Most things have to be believed to be seen
http://www.complang.tuwien.ac.at/anton/home.html

[toc] | [prev] | [next] | [standalone]


#29563 — Re: character encoding

FromIvan Godard <ivan@millcomputing.com>
Date2015-08-29 10:44 -0700
SubjectRe: character encoding
Message-ID<mrsqu9$29e$1@dont-email.me>
In reply to#29562
On 8/29/2015 10:35 AM, Anton Ertl wrote:
> Ivan Godard <ivan@millcomputing.com> writes:
>> On 8/29/2015 7:05 AM, Anton Ertl wrote:
>>> So, is there actually a real-world application of random
>>> character-count access into long text strings that cannot be rewritten
>>> to use a variable-width encoding like UTF-8 (or UTF-16) at a similar
>>> or better efficiency?
>>
>> grep? The sub-linear search contains a p+=n step.
>
> You mean something like Boyer-Moore search?  No need to deal with
> characters, just consider the input string and the search string as
> strings of bytes (or, for UTF-16, as strings of 16-bit thingies).
>
> - anton
>

That assumes that character equivalence is binary equivalence. Is that 
true in all cases? I'm not sure that a case-insensitive Boyer-Moore is 
an option in grep, but it certainly could be and treating the input as 
bytes would fail.

[toc] | [prev] | [next] | [standalone]


#29566 — Re: character encoding

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2015-08-29 17:55 +0000
SubjectRe: character encoding
Message-ID<2015Aug29.195503@mips.complang.tuwien.ac.at>
In reply to#29563
Ivan Godard <ivan@millcomputing.com> writes:
>On 8/29/2015 10:35 AM, Anton Ertl wrote:
>> You mean something like Boyer-Moore search?  No need to deal with
>> characters, just consider the input string and the search string as
>> strings of bytes (or, for UTF-16, as strings of 16-bit thingies).
>>
>> - anton
>>
>
>That assumes that character equivalence is binary equivalence. Is that 
>true in all cases?

Codepoint equivalence is binary equivalence for proper UTF-8 code
(without overlong encodings, which are not allowed).

Character equivalence is not binary equivalence even for UTF-32, as
you can read in <https://en.wikipedia.org/wiki/Canonical_equivalence>,
so a fixed-width encoding like UTF-32 does not buy you anything in
that respect.

> I'm not sure that a case-insensitive Boyer-Moore is 
>an option in grep, but it certainly could be and treating the input as 
>bytes would fail.

You would have to invest some knowledge about case of Unicode
characters in UTF-8 encoding into the preprocessing step, but I think
that once that is done, the rest can be done with the simple
byte-oriented Boyer-Moore algorithm.

- anton
-- 
M. Anton Ertl                    Some things have to be seen to be believed
anton@mips.complang.tuwien.ac.at Most things have to be believed to be seen
http://www.complang.tuwien.ac.at/anton/home.html

[toc] | [prev] | [next] | [standalone]


#29593 — Re: character encoding

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2015-08-31 11:23 +0000
SubjectRe: character encoding
Message-ID<2015Aug31.132357@mips.complang.tuwien.ac.at>
In reply to#29566
anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:
>Ivan Godard <ivan@millcomputing.com> writes:
>> I'm not sure that a case-insensitive Boyer-Moore is 
>>an option in grep, but it certainly could be and treating the input as 
>>bytes would fail.
>
>You would have to invest some knowledge about case of Unicode
>characters in UTF-8 encoding into the preprocessing step, but I think
>that once that is done, the rest can be done with the simple
>byte-oriented Boyer-Moore algorithm.

Some more thoughts: It's helpful to have a case-insensitive character
comparison (that must therefore be UTF-8-aware), but the indexes in
the table (the result of preprocessing) can be byte indexes, so there
is no need to do character-indexed accesses there, and the algorithm
keeps the same algorithmic complexity.

Here's what <http://trac.sacrideo.us/wg/wiki/StringRepresentations>
(mentioned by someone else here) says:

|* string search [...] with UTF-8 it's possible to search at the byte
|  level, and any match is still valid because UTF-8 substrings can't
|  be shifted to invalid boundaries (that is to say strstr(3) is a
|  perfectly legitimate way to search for one UTF-8 string inside
|  another). A byte lookup table is small and fast, so UTF-8
|  technically comes out asymptotically fastest here. [...]
|
|* regular expressions [...] For similar reasons to the string search
|  case (which is just a special case regular expression) the inner
|  loop wants fast table lookups, so once again UTF-8 matching bytes
|  will be the fastest approach. This is why Google's latest RE library
|  works with UTF-8, using the same byte-level tricks IrRegex? and
|  presumably other libraries have been using for years.

- anton
-- 
M. Anton Ertl                    Some things have to be seen to be believed
anton@mips.complang.tuwien.ac.at Most things have to be believed to be seen
http://www.complang.tuwien.ac.at/anton/home.html

[toc] | [prev] | [next] | [standalone]


#29595 — Re: character encoding

FromTerje Mathisen <terje.mathisen@tmsw.no>
Date2015-08-31 14:18 +0200
SubjectRe: character encoding
Message-ID<ms1gnj$jp4$1@speranza.aioe.org>
In reply to#29593
anton@mips.complang.tuwien.ac.at (Anton Ertl) wrote:
> Some more thoughts: It's helpful to have a case-insensitive character
> comparison (that must therefore be UTF-8-aware), but the indexes in
> the table (the result of preprocessing) can be byte indexes, so there
> is no need to do character-indexed accesses there, and the algorithm
> keeps the same algorithmic complexity.

The key idea is to generate both upper and lower case versions of all 
the characters in the search pattern, including the possibility of 
multi-char combinations that change length, but this is still just an 
array of alternate substrings that is only used during full match 
verification.
>
> Here's what <http://trac.sacrideo.us/wg/wiki/StringRepresentations>
> (mentioned by someone else here) says:
>
> |* string search [...] with UTF-8 it's possible to search at the byte
> |  level, and any match is still valid because UTF-8 substrings can't
> |  be shifted to invalid boundaries (that is to say strstr(3) is a
> |  perfectly legitimate way to search for one UTF-8 string inside
> |  another). A byte lookup table is small and fast, so UTF-8
> |  technically comes out asymptotically fastest here. [...]

In my BM code I unroll the processing a few times, this works as long as 
the skip table contains zero for potential matches:

do {
   b = *buffer;
   skip = skiptable[b];
   buffer += skip;

   b = *buffer;
   skip = skiptable[b];
   buffer += skip;

   b = *buffer;
   skip = skiptable[b];
   buffer += skip;
} while (skip);

(I have of course modified the buffer by appending a matching byte at 
the end! With variable-length matching it can also be good idea to have 
a non-matching marker before the start of the buffer since a full match 
verification will step backwards looking for either of multiple 
alternate representation. This is just a more specialized case of a 
regexp looking for alternate substrings.)

> |
> |* regular expressions [...] For similar reasons to the string search
> |  case (which is just a special case regular expression) the inner
> |  loop wants fast table lookups, so once again UTF-8 matching bytes
> |  will be the fastest approach. This is why Google's latest RE library
> |  works with UTF-8, using the same byte-level tricks IrRegex? and
> |  presumably other libraries have been using for years.
:-)

Terje

-- 
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"

[toc] | [prev] | [next] | [standalone]


#29572 — Re: character encoding

FromTerje Mathisen <terje.mathisen@tmsw.no>
Date2015-08-29 21:20 +0200
SubjectRe: character encoding
Message-ID<mrt0l8$n5l$1@speranza.aioe.org>
In reply to#29563
Ivan Godard wrote:
> On 8/29/2015 10:35 AM, Anton Ertl wrote:
>> Ivan Godard <ivan@millcomputing.com> writes:
>>> On 8/29/2015 7:05 AM, Anton Ertl wrote:
>>>> So, is there actually a real-world application of random
>>>> character-count access into long text strings that cannot be rewritten
>>>> to use a variable-width encoding like UTF-8 (or UTF-16) at a similar
>>>> or better efficiency?
>>>
>>> grep? The sub-linear search contains a p+=n step.
>>
>> You mean something like Boyer-Moore search?  No need to deal with
>> characters, just consider the input string and the search string as
>> strings of bytes (or, for UTF-16, as strings of 16-bit thingies).
>>
>> - anton
>>
>
> That assumes that character equivalence is binary equivalence. Is that
> true in all cases? I'm not sure that a case-insensitive Boyer-Moore is
> an option in grep, but it certainly could be and treating the input as
> bytes would fail.

Nope! :-)

I considered this problem more than 20 years ago and figured out a way 
to solve it efficiently even for case-insensitive searches:

Instead of doing a (potentially very expensive) case conversion of each 
character while checking a potential match you setup two versions of the 
pattern, one all lower case and one upper, then use both to initialize 
the skip table.

When you find a potential match you verify it by checking that each byte 
in the target location matches at least one of the pattern versions.

Handling that german double s complicates things a bit...

Terje

-- 
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"

[toc] | [prev] | [next] | [standalone]


#29571 — Re: character encoding

FromTerje Mathisen <terje.mathisen@tmsw.no>
Date2015-08-29 21:11 +0200
SubjectRe: character encoding
Message-ID<mrt05o$lus$1@speranza.aioe.org>
In reply to#29559
Ivan Godard wrote:
> On 8/29/2015 7:05 AM, Anton Ertl wrote:
>> Terje Mathisen <terje.mathisen@tmsw.no> writes:
>>> If there is significant/frequent need for random access into very long
>>> text strings,
>>
>> I thought about such needs for quite a while, and the only things I
>> came up with were palindrome checkers and anagram generators; and come
>> to think of it, both can be coded without random access (palindromes
>> need backwards stride, but that's just as easy as forward stride in
>> UTF-8).
>>
>> So, is there actually a real-world application of random
>> character-count access into long text strings that cannot be rewritten
>> to use a variable-width encoding like UTF-8 (or UTF-16) at a similar
>> or better efficiency?
>
> grep? The sub-linear search contains a p+=n step.
>
I.e. Boyer-Moore or similar approaches?

This should work quite well with utf-8 strings using the standard 
256-entry skip length table, with both the pattern and the target search 
buffer encoded in utf-8.

I.e. searching for my wife's last name (Norløff) in either 
case-sensitive or insensitive versions.

The main/only problem is for patterns and buffers with many similar (in 
the leading bits) characters, where the skip lengths in the table will 
often show false positives for encoded characters that match in one of 
the intermediate encoding bytes, causing extra checks for a full match.

Terje

-- 
- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"

[toc] | [prev] | [next] | [standalone]


#29557

FromBGB <cr88192@hotmail.com>
Date2015-08-29 12:19 -0500
Message-ID<mrsprl$tqh$1@news.albasani.net>
In reply to#29548
On 8/29/2015 7:54 AM, Terje Mathisen wrote:
> BGB wrote:
>> On 8/28/2015 10:22 AM, Stefan Monnier wrote:
>>> If you can't eliminate the "unusual case", you're often better off
>>> making it frequent, so it's handled reliably.
>>>
> Very true words!
>
> I've been arguing for years that distributed/fault-tolerant systems
> needs to be exercised about once per month, by pulling the cord on one
> or more instances: Only when you are comfortable doing this can you also
> schedule all maintenance for regular operating hours, with no need for
> all those late nights and weekends that the families of IT people have
> come to hate.

ok.


>>
>> possible, but then one is less either with all the code needing to deal
>> with UTF-8 (typical case in C), or an overly wasteful wide-character
>> format (32-bit characters). in-general, UTF-32 is undesirable for
>> strings, as they can already end up eating a fair bit of RAM with
>> narrower encodings (ASCII or UTF-16).
>
> David Stafford's version of my .sig replaces caching by compression:
> utf-8 is a quite effective way to encode text for an international
> audience.
>

but... the topic is string literals.

external text and literals may well be in different formats (probably 
UTF-8), and it can be kept reasonably transparent. the main question is 
them what character set strings use while in the program image or in ROM.


it can be assumed that all this would mostly apply to cases where one is 
dealing with targets with a filesystem, network, and/or graphical display.

like, it is kind of a waste to use Unicode if your UI consists solely of 
using a few buttons to navigate menus and change values on an 
8-character 7-segment display or something.


> If there is significant/frequent need for random access into very long
> text strings, then we should look at various alternative encodings:
>
> a) Flat 32-bit/char allows O(1) lookup but wastes almost 75% for most text.
>

yes. this level of waste is a bit steep for memory-constrained embedded 
targets.


one general target area is mostly higher end ARM Cortex-M 
microcontrollers or lower end ARM MPUs (ARM9 and ARM11 based targets).

I may experiment with the possibility of targeting MSP430 devices, but 
they are fairly low on the viability list (I have doubts I can make the 
generated code lightweight enough to compete effectively with C on this 
target).

on a Cortex-M, it is a little easier as you generally have a lot more 
RAM and ROM to play with than on an MSP430.

note that for deployment to such targets, one would precompile the VM 
image to native code for the target prior to deployment (as opposed to 
ARM9 or ARM11 based targets where the program runs out of RAM and you 
can afford to use a JIT).

most likely the native-compiler output will be a variant of 
call-threaded code, with the native compiler pulling in runtime code for 
any parts of the ISA used. I have already started some preliminary work 
for the AOT backends (initially, I am compiling to C for testing).


> b) Plain utf-8 adds a few percent to the size of a fixed 8-bit only
> character set like the one used by classic Windows, but cannot handle
> but increases the average random access time from O(1) to O(N)
>

biggie problem in this case.


> c) utf-8 plus a strided index, i.e. an array of pointers into every M
> starting positions adds 32/M bits of overhead per char but allows
> effectively fixed-time O(1) access to any given character position.
>

not really an option in this case. while it reduces the average access 
time to O(1), and is good for big strings, it doesn't address the issue 
of fixed-time access to typically smaller strings.

big string access isn't really the issue here, but more the need to have 
traces have a reasonably predictable execution time, which is generally 
less than around 200 clock cycles (for sake of simplicity, say, assume 
each ARM or Thumb2 instruction word represents 1 cycle).

I am aiming more for under 50 or 100 cycles though (and ideally a bit 
lower if possible).


any operation which may require longer, or which may throw an exception, 
requires being broken up and executed incrementally, which is also 
something to be avoided.

there are cases where this will be done (such as dealing with dynamic 
classes), but it isn't really a desirable solution.

though, per-character access still needs to end the current trace, given 
the possibility that it can throw an exception.


> d) A variant of (c) is an array of variably sized chunks, like
> paragraphs, with a header stating the current chunk size (used and
> allocated).
>

ok. I have been on the fence about using magic prefixes to encode string 
character-sets and lengths in the string tables.

most likely strings will be packed end-to-end, ex:
"String1\x00String2\x00..."

but, one possibility is that an operation for loading a tagged string 
could look at the preceding byte, say:
   00: Interpret as untagged ASCIIZ string
   01-0F: Reserved
   10-1F: UTF-8, 1-16 chars
   20-3F: CP-1252, 1-32 chars
   40-5F: CP-437, 1-32 chars
   ...
   A0: ASCIIZ String, UTF-8
   A1: ASCIIZ String, CP-1252
   A2: ASCIIZ String, CP-437
   A3: ASCIIZ String, 8859-1 / Raw-Byte (*1)
   ...
   B0: ASCII-LB String, UTF-8
   B1: ASCII-LB String, CP-1252
   B2: ASCII-LB String, CP-437
   B3: ASCII-LB String, 8859-1 / Raw-Byte (*1)
   ...

ASCII-LB strings having a preceding length byte.
a length-word case may also be possible.


"\A1String1\x00\x27String2\x00\x40\xB2Some Much Longer String..."

with the string table literals pointing to the first logical character, 
and the prefix hinting what sort of string 'object' to create.

*1: characters identity map between byte-values and codepoints in this 
encoding. this differs from CP-1252 where 80-9F map to various other 
characters.


> I've written a couple of editors which used (d), it makes it easy/fast
> to get to any given position. With the classic gap approach where the
> spare room in the current chunk is located just after the cursor you can
> both insert and delete text without having to move anything around.
>

I have written text-editors as well, generally using an array-of-lines 
approach. last one I did IIRC internally used UCS-2 and didn't support 
non-BMP characters, but this wasn't a huge loss as personally I felt it 
unlikely to ever be used for much beyond ASCII (and font support for 
non-BMP characters is virtually non-existent anyways).

[toc] | [prev] | [next] | [standalone]


Page 5 of 7 — ← Prev page 1 2 3 4 [5] 6 7  Next page →

Back to top | Article view | comp.arch


csiph-web