Live data from Hacker News

Trimming spaces from strings faster with SVE on an Amazon Graviton 3 processor

lemire.me

21–30 of 51 posts

Re: Trimming spaces from strings faster with SVE on an Amazon Graviton 3 processor

#21
post #14
post #9

Earlier quoted context omitted.

That's been around since C++11 although it's kind of weird to see it used for a char*

A bit weird, but I would support a local style guide that limits initialization style choices to parens for calling non-initializer-list constructors and braces for everything else — for simplicity, consistency, less confusion with assignment, and that odd case where it would actually catch an error (unindended narrowing conversion).

[deleted]

Re: Trimming spaces from strings faster with SVE on an Amazon Graviton 3 processor

#22
post #10

Thanks for sharing. Is understanding how best to utilize computer hardware part of a classic CS program or is most learned on the job? I studied Econ in college and been a python guy for last 8 years but have no knowledge of how the machine actually interacts with my code. Is there a formal name for understanding that?

Yes, a BS in computer engineering is typically what you want for a 50/50 mix of software and hardware. Basically if you get that degree you understand and can build a machine from digital logic/basic circuits all the way up to it boots to an operating system (that you wrote) and its login prompt. It's a deep dive into machine architecture and system programming. An electrical engineering degree doesn't focus as much on the software side, and a regular CS degree doesn't focus as much on the hardware--computer engineering is in the middle.

Re: Trimming spaces from strings faster with SVE on an Amazon Graviton 3 processor

#23
post #20

Earlier quoted context omitted.

No matter how advanced we think we are we are still worrying about minutiae like trimming spaces from strings.

humans putting text into form fields will never go away probably, so you will always have to do this at some point.

I'm aware. It's still interesting, especially since it all still boils down to machine instructions.

Re: Trimming spaces from strings faster with SVE on an Amazon Graviton 3 processor

#24
post #10

Thanks for sharing. Is understanding how best to utilize computer hardware part of a classic CS program or is most learned on the job? I studied Econ in college and been a python guy for last 8 years but have no knowledge of how the machine actually interacts with my code. Is there a formal name for understanding that?

At MIT, at least, everybody in EECS (all one department) has to take 6.004 where you build a simple computer from the transistors up which at least gives you a framework for thinking about this stuff. The simple processor doesn't have caches, of course, so that's a big whole in terms of things you have to understand for optimization, but it's the basics at least.

EDIT: Link to course in OpenCourseware if you want to virtually take it: https://ocw.mit.edu/courses/6-004-computation-structures-spr...

Re: Trimming spaces from strings faster with SVE on an Amazon Graviton 3 processor

#25
post #20

Earlier quoted context omitted.

No matter how advanced we think we are we are still worrying about minutiae like trimming spaces from strings.

humans putting text into form fields will never go away probably, so you will always have to do this at some point.

This doesn't appear to implement trimming the front and back, just the entire string.

Re: Trimming spaces from strings faster with SVE on an Amazon Graviton 3 processor

#26

SVE and SVE2 are similar to Intel's AVX512-etc for vector, I would use intrinsics instead of hand crafting ASM code, unless it's a performance bottleneck. And yes if you want to play with SVE, Amazon's own ARM chip is the best one available now, maybe the only one in fact, for the general public.

Just to be clear, SVE is similar to AVX512 but the “Scalable” part is that the length is not hard-coded to any set number of bits or elements. It is more like the vector computers of old, such as the Cray-1.

This means there is no need for continually updating the instruction set with longer and longer versions of the same instructions. Hopefully this leads to a more stable base and wider adoption, we’ll see how that works in practice though!

Re: Trimming spaces from strings faster with SVE on an Amazon Graviton 3 processor

#27
post #9
post #6

> char * init_out{out}; Are the curly braces in the initialization some new C++ syntax? I haven't been keeping up with C++ developments in the last decade or so. Based on the code that follows I would expect char* init_out = out;

That's been around since C++11 although it's kind of weird to see it used for a char*

I use it for everything, even loop variables.

Re: Trimming spaces from strings faster with SVE on an Amazon Graviton 3 processor

#28
post #10

Thanks for sharing. Is understanding how best to utilize computer hardware part of a classic CS program or is most learned on the job? I studied Econ in college and been a python guy for last 8 years but have no knowledge of how the machine actually interacts with my code. Is there a formal name for understanding that?

I don’t really know of many computer science programs that focus on this kind of thing. The other comments talk about little hobby computers, which is not a bad thing to learn about, but trying to apply principles from an 8-bit toy computer to a modern superscalar, pipelined, and heavily OoO machine is like comparing a toy rocket to the Space Shuttle.

If you’re interested in learning more about microarchitectural optimization I find that getting a basic understanding of how a modern processor has evolved and then reading posts like these (looking things up when necessary) can get you mostly up to speed with the area. Most people don’t use these details in their everyday code so if you’re just looking to make your code fast learning how to measure algorithmic complexity and use a profiler is likely to be much more valuable.

Re: Trimming spaces from strings faster with SVE on an Amazon Graviton 3 processor

#29
In order for this to matter, you'd need to expect the possibility of strings with huge numbers of leading spaces. Why then would you use this naive algorithm for comparison? An obvious and more straight forward improvement would be to compare 4 bytes at a time with 0x20202020. (or maybe 8) There would be a maximum of 3 spaces to identify individually.
Post reply on HN