Hacker Newsnew | past | comments | ask | show | jobs | submit | modulovalue's commentslogin

I’m currently working on adding better SIMD support to Dart (https://github.com/dart-lang/sdk/issues/64170) and I have a question for the author or others here.

Does Rust or any other language support customizing the compiler so that interprocedural analyses can track custom subsets of, for example, doubles so that the compiler can choose the most efficient instruction sequence for example for min/max? If we know a double is never NaN then we can emit only one instruction on x86, but have to emit one more on arm64. If we know a double is never zero and never NaN, we can emit a single instruction on both.

This whole conversation between relaxed SIMD and deterministic SIMD seems to only exist because our compilers are not smart enough and/or their whole program analyses don’t support any plugin-like capabilities.

There are other examples where if we know a SIMD bitmask is canonical (all 1s per lane) then we can implement horizontal reductions more efficiently. This is very niche and I doubt that any language supports interprocedural analyses with such a rich domain, so it feels like a hole in the programming language space.


Not yet that I know of, though perhaps LLVM might be able to infer simple cases (when loading from a known constant for example).

Pattern types could potentially maybe in the future allow for the compiler to know more details though. They are a nightly feature, and afaik only for enums, integers and pointers so far. The idea would be that you can define a custom type such as "an integer between 7 and 45" and everything else become niches for niche optimisation (e.g. for `Option<MyFunkyInt>` some of those impossible values would be used to represent the None case of the wrapping Option).

But I could envisage a future in which you could say "f64 without NaN" which would both make those available for niches and potentially tell LLVM about this. However, we are very far from any of that currently. And it might not be what you want, since you would need to add checks when you perform operations to ensure the value doesn't suddenly become a NaN. Which is way more complicated than ensuring integers don't become, say, zero. It will likely be much harder to optimise away the checks.


LLVM has range flags and things like nnan that could in theory be used to replace a minimum intrinsic into a minimumnum (iirc x86 has a instruction for the latter but not the former) https://llvm.org/docs/LangRef.html#floating-point-min-max-in... I'm not sure if the optimizations use this but in theory they could

Sounds similar to https://mlir.llvm.org/

> Pattern types could potentially maybe in the future allow for the compiler to know more details though.

Thanks, I’ll take a look!


That is a big maybe though. It is very experimental (didn't even have non-placeholder syntax last I looked), and as far as I know nobody has yet even discussed it for floats.

Last time i checked; no.

But I suspect you're overvaluing the potential savings. Knowing when a float is 0.0 or NaN beforehand is almost entirely impossible, except for the most trivial of cases - like when you first initialize a variable or first enter a loop. Everything after that is very hard or impossible with floats as they are.

Those cases can be const folded at compile time.

Those cases are never a measurable bottleneck.

The closest thing I know of in the realm of the optimization you're curious about is Rust NonZero* variants, but they're used for enum compression afaik.


I’m not sure I agree on the impossible part, I feel like a sufficiently smart interprocedural analysis that also implements range analysis interprocedurally could prove a lot to where it becomes useful.

I guess what I would like to see is SIMD libraries being able to confidently say nobody needs to use intrinsics (or differentiate between relaxed/normal SIMD on the user API level) because the language + high level SIMD APIs are smart enough to choose the right implementation.

IIRC IEEE min/max with proper NaN handling needs 8 instructions on x86 vs 1 on arm64 I find it very sad that we apparently haven’t really solved that yet without forcing the user to use different APIs.


You can do it with just 3 instructions for IEEE 754-2019 minimumNumber (ignores NaN):

        vminpd          ymm2, ymm1, ymm0
        vcmpunordpd     ymm0, ymm0, ymm0
        vblendvpd       ymm0, ymm2, ymm1, ymm0
If you want proper IEEE 754-2019 minimum (propagate NaN, -0.0 < +0.0, NaN bitpattern picked in the usual way) you can do it in 6:

        vminpd          ymm1, ymm0, ymm1
        vbroadcastsd    ymm2, qword ptr [rip + .LCPI0_0]
        vandpd          ymm2, ymm0, ymm2
        vorpd           ymm1, ymm2, ymm1
        vcmpunordpd     ymm2, ymm0, ymm0
        vblendvpd       ymm0, ymm1, ymm0, ymm2
I personally find this a load of nonsense I don't care about.

If you want propagating NaNs but don't care about signed zero or NaN payload/sign, you can use

        vminpd  ymm2, ymm0, ymm1
        vminpd  ymm1, ymm1, ymm0
        vorpd   ymm0, ymm1, ymm2
What I do in Polars is a bit different, there for propagating NaNs I do

    if (self < other) | self.is_nan() { self } else { other}
this isn't fully optimal on x86-64 but it's fairly simple and autovectorizes decently on various platforms, here's AVX2:

        vcmpltpd        ymm2, ymm0, ymm1
        vcmpunordpd     ymm3, ymm0, ymm0
        vorpd           ymm2, ymm3, ymm2
        vblendvpd       ymm0, ymm1, ymm0, ymm2

That vminpd+vminpd+vorpd actually does handle signed zero properly! Screws up NaN payloads to the max though. Can be easily extended to canonicalize the NaN with 2 instrs + constant though of course. (which ends up at the same number of instrs as your proper impl (albeit with worse port distribution and latency), but you get to have a canonical NaN!)

Hit upon https://github.com/llvm/llvm-project/issues/217376 while playing around with proper minimumnum, failing to SMT-verify whatever version of LLVM I had; did find a funky working 6-instr (+ constant) version though:

    vpandn      ymm2, ymm1, ymm0
    vpcmpeqd    ymm2, ymm2, 0x80000000 # whether ymm0 is -0 and ymm1 is +0 (or other cases that magically don't cause issues)
    vcmpltpd    ymm3, ymm0, ymm1
    vcmpunordpd ymm3, ymm3, ymm1 # regular NaN-is-larger ymm0<ymm1
    vpor        ymm2, ymm2, ymm3
    vpblendvb   ymm0, ymm1, ymm0, ymm2

Stop the presses! 5 instructions!

    vpor        xmm2, xmm0, 0x80000000
    vpcmpeqd    xmm2, xmm1, xmm2
    vcmpunordps xmm2, xmm2, xmm0
    vminps      xmm0, xmm1, xmm0
    vblendvps   xmm0, xmm0, xmm1, xmm2
yay for superoptimizers

Anything without range analysis is not worth it.

Note that:

NonZerof32 * NonZerof32 -> NonNanf32

NonZerof32::from_bits(1) multiplied with itself is zero.

Doing range analysis needs the language to support it at compile time, and the dev to specify what range it is.

The only 'stable' thing i can think of is a type for 'greater-eq-one' using only addition and multiplication. Practically every other operation breaks most of the type knowledge up to that point.


> nobody needs to use intrinsics

Funnily enough, intrinsics have become almost trivial to write, with agentic tooling. I used to be an ISPC advocate but now I'm finding myself gravitate to direct use of intrinsics with bespoke dynamic/runtime dispatching more than ever.


+1 on agents making library/DIY a lot more attractive than bespoke compilers.

In C++, one can also have portable intrinsics plus simpler runtime dispatching using our Highway library :)


> using our Highway library

Yes, Highway is pretty nice but also quite elaborate when it comes to dealing with multiple vectorized versions and dispatch. The macros burn my eyes still.


:) Yeah, those are best copy-pasted from existing code.

I do think we've converged on the best that's possible in C++.


Customized compiler isn't really a thing in most languages. Because it implies changing the language, and everyone agreeing on what the language is was sort of the point of the whole exercise. Hence all the worries about macros.

SBCL has the right hooks. Jai probably does as well. You could build your own thing on LLVM relatively easily - so Rust _could_ do it if you gave it sufficient access to the compiler, but so could C++ or D.

SIMD bitmasks being ~0 instead of (00000001)+ is common and useful, but there's an annoying language design question in there about what type comparisons between vectors should be (if you don't have a <N x i1> as a type, say because you liked C too much). Shout out to std::vector<bool>.

There is probably interesting work in mojo for this. The library being in MLIR strongly encourages taking that sort of approach. I haven't looked at their implementation though. Happy hacking!


Julia also does this quite often (both using macros to write DSLs or minor modifications, and packages like GPU backends that hook the compiler functionality to compile direct GPU assembly kernels.

LLVM does do bit pattern tracking. Referred to as value tracking or known bits analysis.

I’m not sure if the vectorizer uses it a ton, but isel does (though maybe not heavily for vector ops)


Possible in Julia without patching the compiler with a compiler extension package.

I think you are looking for NotNan<f64> from ordered-float crate?

I built something similar, but I managed to compile the Dart VM, its compiler and the static analyzer to wasm using emscripten:

- repo: https://github.com/modulovalue/dart-live

- demo: https://modulovalue.com/dart-live/

It's on my todo list to support compiling dart code through the wasm bundle to wasm directly. Right now it's running the dart arm simulator on the web because it supports hot reload.

I'm wondering if there are any cool use-cases that motivate having the compiler itself run in wasm. I did it mostly for fun and besides building tooling for compiler developers themselves or IDEs, I can't come up with much.

There was one guy that wanted a sandboxed environment for agents as he couldn't find anything else. A few other people used the dart live project to build playgrounds for their own packages.

Who's the target audience for minikotlin? I'm just curious.

In any case, cool project, thanks for sharing!


I'm working on making SIMD better in Dart. Dart supports RISC-V as a target architecture for compilation, but I'm not really excited about figuring out how to map the wasm-SIMD-style primitives to RISC-V's RVV and so I don't really plan to look into it at all.

This is mostly because their approach to SIMD is so different, but also because I can't test it at all. Are there any RISC-V "machines"? that one can use to do something useful or fun with that someone here could recommend?

I guess it would be fun seeing all my SIMD-fiable use-cases become orders of magnitude faster on RISC-V, too, but I sadly never hear anything about machines that use RISC-V.


> Dart supports RISC-V as a target architecture for compilation, but I'm not really excited about figuring out how to map the wasm-SIMD-style primitives to RISC-V's RVV and so I don't really plan to look into it at all.

On the one hand, this will be quite straight forward, but on the other hand quite disappointing.

Afaik Dart has a 128-bit only SIMD abstraction (so not performance portable by default). Since the base "V" extension mandates a mininum vector length of 128-bit, you can trivially make codegen work for all vector length, by simply setting vl to 128/elementwidth.

But as with x86, if your native hardware vector length is larger than 128-bit, you leave performance on the table.

> This is mostly because their approach to SIMD is so different, but also because I can't test it at all. Are there any RISC-V "machines"?

I'd recommend using qemu for initial testing.

Hardware wise, the cheapest option is the orange pi rv2, which has 8 SpacemiT X60 cores, which are in-order and support 256-bit RVV. The Zhihe A210 is also interesting, but way to expensive for what it is.

If you have a higher budget, I'd recommend the SpacemiT K3, which is the fist RISC-V SBC with RVA23 support. It is has 8 SpacemiT X100 4-wide out-of-order cores, with 256-bit RVV.


You can try to re-vectorize the code for larger vector size.


Not if you can't prove anti-aliasing properties, which wasm doesn't carry.


I don’t think the OP is starting from WASM code; they’re starting from a language with SIMD primitives that map closely to those of WASM. There, you often have information to prove function arguments do not alias.


There are several RISC-V machines. In the microcontroller world it's becoming more and more usual, but those won't have RVV. SpacemiT K3 based machines are probably your best bet when it comes to RISC-V processors with SIMD support. There are several manufacturers: Milk-V with the Jupiter II, Sipeed, Banana Pi, ...


The THead C906 core is full Linux-capable but is microcontroller-adjacent and has an early draft version of RVV that is different in details but has the same flavour (and at least some code is binary-compatible with RVV 1.0). Recent GCCs RVV intrinsics compile to either RVV 1.0 or the 0.7 draft (named XTHeadVector now) so if you're programming at that level they're compatible. Milk-V Duo starts at $3 for a tiny board with a 1.0 GHz C906 running Linux, a 700 MHz microcontroller config C906 (no MMU etc), and 64 MB RAM. Well, I paid $3 ... then they were $5 for several years and now I see $11 at arace.tech. There are also 256MB and 512MB versions, with the larger one also having an Arm A53 core.

That's actually got full 128 bit SIMD with all data types supported up to 64 bit int and FP.

You can also buy bare CV1800B and SG200x chips (Sophgo bought original designer Cvitek and enhanced the design)


You can buy a RISC-V mainboard for the Framework Laptop, and it's relatively cheap (£170)

https://frame.work/gb/en/products/deep-computing-risc-v-main...


No don't buy this one, it doesn't support RVV. Their newer ones do, but those are a lot more expensive.


Good catch, thanks.



There are various emulators available that support RVV but they aren't going to be especially useful for benchmarking/profiling.

So you can write code that works, but it's probably a few more years still until high performance RISC-V cores are easily available for profiling RVV code and finding the best code.

Progress is steady though - it will happen soon. It's not one of those "year of desktop Linux" things.


>Are there any RISC-V "machines"? that one can use to do something useful or fun with that someone here could recommend?

Multiple boards based on the RVA23 spacemiT K3 are shipping as of recently.

They are usefully performant. Comfortable webbrowsing and playing 4K youtube without issues sort of fast.


>This is mostly because their approach to SIMD is so different, but also because I can't test it at all. Are there any RISC-V "machines"? that one can use to do something useful or fun with that someone here could recommend?

I would also be interested in RISC-V emulators etc.


QEMU. Docker, using QEMU under the hood, there automatically with Docker Desktop on Mac & Windows, install QEMU yourself on Linux and configure binfmt_misc to use it.


I forgot to thank you, I didn't know qemu supported risc-v arch! I am already using it for various vms.


It's already a breakthrough in my opinion.

Many things are possible that weren't possible before. For example, I was able to compile the Dart VM (the compiler + analyzer + VM) to wasm and run it on the web: https://github.com/modulovalue/dart-live it supports hot reload and many other cool features. It runs essentially everywhere and it's a very bare proof of concept for a fully integrated programming development system.

The problem is that things just take time if you have to coordinate across a bunch of languages and teams while trying to make everyone happy.

To give you a sense of what else is coming: the wasm ecosystem is moving towards supporting a component model. Eventually you'll be able to import any piece of code from any programming language that supports it. Wasm interface types will make that possible.


> I was able to compile the Dart VM (the compiler + analyzer + VM) to wasm and run it on the web

Is this really a representative use-case of WASM/WASI? Would'n it be much better to compile Dart to WASM (the Dart SDK even supports "dart compile wasm")?


this is a confusing question; why would it be much better to e.g. compile a C program for x86 linux musl but not the C compiler?


Your analogy doesn't quite hold. The primary use case of a compilation target is to compile programs, not the compiler itself.

With Dart specifically, "dart compile wasm" already exists precisely for that purpose. Compiling the entire Dart VM (a multi-hundred-thousand-line C++ codebase) to Wasm and then running Dart inside that is a clever in-browser IDE trick, but it's heavy, indirect, and not what Wasm/WASI was designed to showcase. It also sidesteps WasmGC, which is exactly the kind of Wasm evolution that makes Dart-to-Wasm compelling.


There's an important issue with async iterables: what's the initial value of derived "signals"?

In the Dart/Flutter world, async iterables are known as streams. The biggest problem is that they are asynchronous so if you derive new streams from existing streams, you won't have a value immediately for those streams available, you'll have to wait a frame for values to propagate. That's not a problem if you're just processing data, but if you're using them in a UI framework and your UI framework is coupled to the event loop, then you have a problem.

This doesn't happen with the ReactiveX approach because things are evaluated immediately, one doesn't have to wait for the event loop to tick. (A fun historical artifact is that ReactiveX has not caught on in the Dart/Flutter community around 2019-ish because it was eventually migrated to use Streams and the initial-value-problem was a real problem that made the benefits of ReactiveX not carry its weight nobody noticed that but I was heavily involved and I am still using a custom framework derived from my observations back then).

If we zoom out a bit, the problem is actually that we are trying to define a computation graph and then need a strategy for evaluation it. I think Elm has actually made the biggest progress on that front (here's THE talk on that topic that shows how complicated working out all the kinks can be: https://www.youtube.com/watch?v=Agu6jipKfYw)

I still think that functional reactive programming solves most of the problems we have in UI-land, but the complexity that we have to deal with when we use traditional methods of state mutation, that complexity becomes enormous when trying to define a reactive programming framework, especially in languages that are not purely functional.

I think in 10 or 20 years there will be somebody that solves this problem, I don't see it happening anytime soon, sadly. It's just too complicated and we need programming languages that are built around those ideas for them to become comfortable enough to be usable in practice.


Thanks for your feedback!

> The biggest problem is that they are asynchronous so if you derive new streams from existing streams, you won't have a value immediately for those streams available

I tested that using `myAsyncIterable.map`, which is part of the stage 2 async iterator helpers proposal, and it works fine. Maybe I miss a specific case you have in mind?

How did Dart (or you) fix the initial-value problem?

> If we zoom out a bit, the problem is actually that we are trying to define a computation graph

I agree with that considering the comfort it brings, and since you mentioned Elm I will also mention lustre (a Gleam lib) which has the exact same approach. But both those tools/languages are niche functional languages, which JS is definitely not. I'd love to discuss why but it's another debate.

Elm's and Lustre's approach imply some trade-offs too, delegating a lot of work to the rendering engine.

This idea does not aim at replacing approaches like Elm's or Lustre's, the idea is to integrate with non-functional Web APIs – DOM nodes are definitely not immutable – following the exact opposite approach like SolidJS's about putting evaluation at the lowest level (ie: DOM node) rather than highest level (app).

If your team has the skills to build web apps in another language (Elm, Gleam, OCaml, …), you should probably do that. If you are all-in on JS, I'd better have something as close as possible to the Web platform.


Very interesting, I always believed we should have more declarative frameworks in other domains and not just UI. My experience shows me this gives LLMs a much smaller space to explore which leads to better results.


Yeah, I fully agree. UI has become a pretty obvious example for declerative programming, but it probably makes sense for so many other domains as well!


NIT: That's not quite correct if your first statement is meant to imply an equality rather than a subset relation.

The idea of an index is more general, as an index can be built for many different domains. For example, B-trees can index monoidal data and inverted indexes are just an instance of such a monoid that a B-tree can efficiently index.

Furthermore, metric spaces (e.g., levenshtein distance) can also be efficiently indexed using other trees: metric trees. So calling inverted indexes just indexes would be really confusing since string data is not the only kind of data that a database might want to support having efficient indexes for.


My point is that all indexes are "inverted" in the sense that they map some searchable value to occurrences of said value. That is true even if method of comparison is not strict equality.


Most indexes people hear about are like that. However, there are indexes that work the other way around, like Postgres' Block Range Indexes (BRIN). They are mostly useful as skip indexes - for a given block, they have a summary that tells whether some given data may be there.

The trade-off this kind of index makes is that it is more optimized for (batch) writes than the more popular B-Tree indexes, but it is less optimized for reads on the other hand. If the write throughout of a given table is very high, you might want to remove all B-Tree indexes that are not strongly correlated to the insert order and have BRIN indexes instead. Combine it with table partitioning, and you can add B-Tree indexes in the cold partitions, or even migrate them to columnar storage if available (with the Citus extension).

By the way, a few years ago a Bloom BRIN variant was added, not to be confused with Postgres' Bloom indexes which are something else.


I wouldn't say BRIN indexes are "the other way around"; index structure is still one where data values are looked up to find the area where occurrences exist.

"Coarse" indexes like BRIN and ClickHouse's data-skipping indexes are still indexes in a broad sense of serving to narrow down a search.


The university I went to started its math education with groups, which is really unfortunate and they never even mentioned monoids.

Monoids are a key idea in computer science and I think that everyone should know what monoids are. Monoids are EVERYWHERE and once you recognize that you have a monoid you can immediately use known methods to compute over monoids in efficiently (e.g. https://static.googleusercontent.com/media/research.google.c...).

Once you have a certain lattice (I'm leaving out some details), you can solve problems efficiently by known methods (e.g. using dataflow solvers) and automatically have a proof that the solution always terminates.

I really wish that more people took their time to learn these fundamentals and I think this is a wonderful introductory site. I don't mean to offend anyone, but if you've never heard of most of that stuff, then I think that you don't deserve to call yourself a professional programmer. Why? You will reinvent solutions to problems that have been solved before much more efficiently then you will be able to i.e. you're an amateur.


> I don't mean to offend anyone, but if you've never heard of most of that stuff, then I think that you don't deserve to call yourself a professional programmer [...] i.e. you're an amateur.

Every person is going to have a different idea of what knowledge is essential, and as you point out, we don't know what we don't know.

It is easy to look down on people who don't know what we consider fundamental, but it takes a little bit of humility to realize that we are ignorant of what other professionals value the most. Different roles require of different knowledge.


Also, one important thing I've learnt is not to take in advice from obnoxious people.


I'm using euro cents as weights in my weighted vest.

When I started doing this I didn't want to afford dedicated weights as it seemed like a waste of money, but I had many cents saved up from my childhood, which I started to use instead.

I have roughly 15kg in euro cents in my vest and I'm regularly talking walks with it.

To get one kilo you need 435 cents and it turns out that in Germany you can also "buy" coins "for free" at the "Bundesbank", that is, you can exchange actual money for weights without any fees. You give 4 euros and 35 cents and you get a kilo. Once you need the money back, you can also sell those coins back to them for free.


You can also go to the beach and get unlimited amounts of weight for free too. That's what's most budget weights are made of


Just FYI this is illegal in many areas.


It's illegal to fill a bucket with sand?!


Sand is not an infinite resource. It's crucial for both protection (if you remove all the sand from the beach, there will be nothing to cushion the waves and currents and etc. and it will result in more erosion, which can be deadly for any constructions nearby) and construction.

As such, it's completely normal that you can't just take sand or stones from many beaches. The very famous Étretat town in France with its accompanying beach and rocks, have a very strict "don't take souvenirs from the beach because you'd be actively destroying it" policy.


Sometimes someone has paid money to place the sand at the beach because it wasn't a sand beach from the start. So no, you can't go fill your sacks with sand anywhere you like, not even in Sweden were we can pick berries in the forest for free. Stones, trees and sand is not allowed without permission.


Definitely a euro thing then.


Not particularly, it's prohibited in US National Parks, National Historic Sites, National Memorials, National Wildernesses, National Seashores & Lakeshores[0], US National Wildlife Refuges [1], Most US State parks.

Canadian National Parks[2] and most Provincial/Territorial Parks.

[0]: https://www.nps.gov/articles/recreational-collection-of-rock...

[1]: https://www.ecfr.gov/current/title-50/chapter-I/subchapter-C...

[2]: https://parks.canada.ca/voyage-travel/regles-rules#objects


So like less than a tenth of one percent of the US coastline. Literally so uncommon in the US I'd have to go well out of my way to find a section of beach where this is applicable.


And remove it from the beach, yes.


No, to walk away from the beach still holding that full bucket.


You would be surprised how many things its illegal to take from beaches or country (sand, corals, some shells, of course anything old enough etc)


Literally none of that is illegal at any of the beaches I've been to (east coast US). Not only does nobody care, there's frequently nobody around to even notice in the first place.


I don't mean to argue that it's just gimmick and any sane person would just use sand, but to be completely fair, sand is much less dense than steel, so if the coins pack well it does make a better weight.

I do also suspect that there must be some product that must be more cost effective than coins but denser than sand, but cannot think of it right away. I mean, scrap steel is a couple of cents per kg.


Olympic weight plates for barbells. They're widely used, so competition has brought the cost down, and they're easily available in useful increments. I currently see 4x 10lbs for <$50 on Amazon. That works out to 2,53 Euro per kg. So cheaper than euro cents. They may not have the exact shape you need.

The scrap steel probably didn't cost cents per kg when it was sold for its original purpose. You are paying for a useful shape.

A professional equivalent of weighted vests are ballistic plate carriers. Real ballistic plates can be fragile and expensive, so options for exercising in (or milsim games in airsoft etc.) include expired (and failed to re-certify) real ballistic plates, made for purpose training plates... or plate shaped sandbags!


> That works out to 2,53 Euro per kg. So cheaper than euro cents.

The cents are free though, cause they're legal tender — just deposit them instead of having to sell 2nd hand


Assuming you live in a sane country. One of the few complaints I have with Dutch society being so "streamlined". Cash is seen as a nusciance here.


The cheapest plates can be higher variance than you might expect. I’ve seen reports of 45s that are 10% light.


Especially if you hit eBay or similar, you can get it for cheap


Sometimes sand + water is used for ballast. Depends on your use case, if your heavy thing is moving around then the sloshing won't be ideal, but if it's just sitting somewhere static then it can work.

eg; weighing down the corners of a beach tent, pegs won't grip in the sand so instead tie plastic bags onto the guy ropes and fill them with sand and water.


It's a lot easier to contain coins vs sand, though.


You can keep both in a series of ziploc bags for convenience.


Round coins are also less coarse and rough


For me, it would be rather long trip and generally too expensive. I would had to steal it from kids playground. Which is rather low thing to do.


I have to ask, how do you not sound like ~6500 coins jingling together as you walk? I notice when I have like 10 coins in a backpack. Do you wrap bundles of coins in cellophane or something?


I remember back when I used physical coins, banks used to wrap them in paper rolls with known quantities in them. So you could get a $10 roll of ten $1 coins or whatever.


Ah that is almost certainly it, it's been so long since I've gotten a roll of quarters from a bank that I forgot that is an option. Thanks!


Could you explain more? I do not understand how you can buy coins for free by paying coins for “weights” (what are these weights? What are they made from?). Also, what is the use for this? To check of your coins are real? Calibrate your coin scale?


I guess OP means you don't need to buy above or sell below its value when "buying" or "selling" a metric shitton of small coins (like you would for gold for instance).

15 kilograms sounds excessive though, I bet the bank clerks hate that trick ;)


Banks usually stock pre-counted rolls of coins, and it's not much hassle to count out several of those. Though I guess 15 kg is probably going to be several dozen.


The coins are weights, the actual money is paper or electronic money.


Excuse the nerdy nitpick, I get the point but technically as far as "actual" money goes that's the coins. Electronic entries in bank ledgers are not legal tender.

One can of course go further and question if banknotes and coins should be called actually money. Today the nominal value is completely disconnected from what the metal is really worth, it's not like with gold coins back in the day. And once collective belief in the value is lost fiat money quickly becomes worthless. Zimbabwe and Venezuela are recent examples.


Have to correct your nitpick. What you're talking about is currency not money. Not being legal tender doesn't mean it's not money. The majority of money sits as electronic entries in each country's central bank. https://www.investopedia.com/terms/c/currency.asp#:~:text=Th....


True. I'm talking about private bank books, the kind of "electronic money" regular people use, which I assume is what the comment above referred to. Since only financial institutions have access to central bank accounts.


How do you pay 35 cent in paper is still a mystery. But OP just means you can exchange/buy coins (and use them as weights)?


You should be just as mystified about the 4€ component.


You give bills and get pennies.


The decathlon weight 500g pakets of sand)jacket is about €20. How easy is it to make your jacket 10kg? Are the coins easily removable? Do you have straps to keep the weight 'tight'?


It's very easy. I'm using the cheapest weighted vest that I could find and it came with blue bags that I've just filled with coins. You don't really need straps to make the weights tight because the money just kind of spreads inside of the bag and doesn't move at all once it's there.

It's on my todo list to 3d print some containers to replace the bags with actual "money rolls" so that I can remove them more easily.


Maybe you've already considered and decided paper wouldn't work, or maybe you want the fun of working with a 3D printer, but my initial thought:

Would it not be simple to create rolls of coins by simply wrapping a sheet of paper round a stack of them, once or twice around, a little bit of sellotape to hold the paper in place, including folding it over at both ends and taping there too? I'd imagine an A4 sheet would be more than enough for each stack of coins, cutting off what isn't needed, and since you wouldn't care about them being beautiful you wouldn't even need fresh paper and could just use paper that would otherwise go into recycling/trash (letters received, junk mail, etc.)

edit: I did a quick search which both confirmed people have made coin rolls using simple paper, and also that it's highly likely banks will offer pre-made paper holders for the various coin sizes that you can just ask for and get for free (with the bank assuming you'll be bringing them back full of coins - you could either ask for as many as you need, or just one per size and use it as a template for making more from plain paper like this guy does: https://m.youtube.com/watch?v=AvsOkp_WPxY )


That's a very good point. I wonder about the durability of a paper based solution, but 3d printed rolls might also be suboptimal in that regard. This needs some experimentation.


I'd imagine that if paper alone wasn't strong enough for long term use, using sellotape to cover the entire roll such that the whole thing has a layer of tape on top of the layer of paper would make them pretty durable and add very little time and cost to it. (But I've not done anything like this, so my guessing could be bullshit - happy experimenting!)


I'd honestly just use some ziplock bags and call it a day.


What's a weighted vest? Something for diving?


It's a vest that you can fill with stuff to increase the intensity of a workout.

There was a time in my life when my legs started hurting and shaking from muscle atrophy because I was programming too much and moving too little.

I was looking for a way to fix that issue and I didn't want to waste time going to a gym, so I started talking walks with a weighted vest. Walking is nice because you can think while walking and with a weighted vest you don't have to walk for hours for it to have a useful effect on your body.


FYI going to the gym is hardly a waste of time. You feel refreshed and your body will thank you after a while.


Working out without the commute saves time.


What is a waste of time is going in and out of the gym.


For information, the current research shows that the intensity of the exercise is much less important than the duration. So if you did so little exercise that you get muscle atrophy, a weighted vest isn't going to do much for you.


> For information, the current research shows that the intensity of the exercise is much less important than the duration

For what goal? Increasing strength? I have my doubts.


They're probably referring to some contrived fitness study on hypertrophy.


Anyone who has actually done both low-intensity exercise, e.g. walking, and high-intensity, e.g. heavy compound lifts, will tell you that statement needs a lot of additional caveats.


You’re gonna need to provide a source to that. For caloric burning? Sure, I’d agree. For cardiovascular health? Eh, the answer lies in the middle. For strength and muscle building? No, quite the opposite really. At some point the intensity of an exercise is so low it provides no meaningful muscle stimulus.


haha yeah nah. This needs a lot more additional context and caveats.

If I'm working on increasing my deadlift's 1rm, doesn't matter if I practice deadlifting for 16 hours a day, 7 days a week, but never go above 10% of my current 1rm


It's a way to increase the risk of injury to your knees and ankles and strain your back and shoulders while taking walks, and in general make walking more unpleasant.

Some people think it's an exercise 'life hack'.


If you're injuring yourself by walking around with a few extra kilos then you are so, so hilariously out of shape that any advice you can give is competely disregardable.


I avoided injury when backpacking through the Himalayas by tying helium balloons to by backpack for neutral buoyancy. Had to make slight adjustments as altitude changed, but it all worked out. I had my porter carry the helium tanks.


God must have created America, humans wouldn’t have been capable of trekking with such weight.


I do not know if that is satirical, specially the last sentence?


The OP said their legs were shaking just standing due to lack of exercise. So, they were literally that hilariously out of shape.


The risk of injury while walking in a weighted vest is not much higher than walking normally. A very high weight of vest is probably ill advised, but walking on a very flat/regular surface for long periods is far more damaging than walking with a little extra weight. Weighted bracelets/limb weights are dangerous though, and shouldn't be used unless you know what you're doing and take care not to move too quickly and put excess strain on joints.


How much weight on a weighted arm band is considered dangerous? I'm considering 500 gram bands for my arms, that's just about twice the weight of a cellular phone today.


It depends on what you're doing, but 500g shouldn't be dangerous as long as you wear the weights tightly bound so they don't bounce or slide. What you want to watch out for are anything that overextends or puts pressure on the joints - those movements can cause damage even unweighted and having weights just makes the danger worse.


I'd be worried about blisters/rashes/rubbing if the weights slide around. I use an exercise-bike like device and realised I was getting a blister on my hands from the constant motion of the grip.


Thank you.


Ehh, I've been doing fitness boxing and knockout home fitness (Nintendo switch) with 1.5 kg wrist/hand weights for ages now, no issues to speak off. I think he's taking about the 2-5kg weights, these are way more dangerous then you'd expect from wearing them. (I did that for a while, after getting slightly In shape - at least until I read up on it)

Strong recommendation for Nintendo switch for baseline fitness btw, these games are great for a 1-2 day 20 minutes workout/week for unfit office workers. Way better experience then the equivalent VR games.


What are the equivalent VR games? Just curious.

I don't play too much VR these days, but enjoyed Beat Saber for "stationary movement", Gorn for beating up stuff and the VR ports of the original Serious Sam games for "run and shoot like a maniac".


These can be pretty physically challenging too! my issue with arcade style games for fitness is that they stop whenever you fuck up. That's not really great when your goal is to get moving for ~20 minutes or so.

The one's I've currently got installed on my quest 3 are

Supernatural Fitness (I need a VPN to play because they're geolocking it to USA). I find the way they try to "get personal" with the trainer super awkward.

FitXR (only one with decent passthrough gameplay) I dislike how most exercises are centered around "gyms", whenever you enter a session, there are others around you doing the same exercise as you and you get a scoreboard. It really doesn't vibe with me whatsoever. I also don't believe that I almost always get first or second place - I'm pretty sure this is showing you numbers to make you feel good about yourself.

XR workout It's the most "indie" of these and with the highest difficulty ceiling. It's biggest downfall is that it doesn't really give you a generated "I wanna exercise for 20 minutes" button. At least I couldn't find it.

There are also others, but I don't have them installed. I.e. Les milles etc

But as I said before: purely from a workout perspective, the Nintendo games work way better in my experience.

It's just so awkward in VR compared to Knockout Home Fitness, worse signalling what you need to do next - you're wearing a headset while getting sweaty - no center stage youre watching, instead youre just trying to guess which movement you're supposed to do while things randomly float around.

https://m.youtube.com/watch?v=ctLdgFf5GCQ


Your body weight varies by more than that during the course of a normal day. Carrying 1kg should not increase any sort of risk of injury unless you exceptionally weak (as in, have trouble walking at all).

For the same reason, you probably won't see much benefit from such light weight over just walking a little faster or a little further.


The problem is that when you put weight on your limbs you are creating levers and inertia which get transferred to joints in ways those joints are not good at dealing with.


How to you carry groceries (or, basically, function at all) if you can't handle a 500g weight attached to your arm?


One usually doesn't do much with their arms while carrying groceries, they just hang at the side or move the bag around when putting it down or picking it up. When performing other movements, especially when they are fast or forceful, the extra weight can add momentum that is potentially hazardous, especially if it bounces or moves around (makes it very hard to compensate for reflexively). If present during repetitive tasks, extra weight can increase the risk of repetitive stress injuries occurring.


Some people have no, zero, none understanding of sensible limits. "If X is good then more X must be better" applied to one or more aspects of their life. Hence protein in their diet, vitamin supplements, weight in a vest, and of course, infamously, having a presence on social media.


Is it worse than carrying a backpack?


I went 0' 5' 10' 15, 20kg over 3 years after an embolism. N=1 (rather like yourself: or you spoke to/ read about people that don't quite understand 'pacing'. Do you/ them struggle with 1 bag of shopping? I make three or more light(er)trips.


In the same way that consuming food and drink is? Or carrying a backpack of things you need, not just dead weight?

Maybe I misundertand - how much weight are we talking about here?


Used in running to add extra resistance.

I've used them on and off in the past; useful in limited circumstances.


> you can also "buy" coins "for free"

Free till you count inflation and opportunity cost. (What you could gian as interest with some other investment)

But yeah, probably still cheaper than some product from a store.


> saved up from my childhood

Isn't Euro just from 2002? That surely is not that long time ago!


It's 22 years ago, roughly


I'm still wondering if there could exist an alternative world where efficient addition over decimal numbers that we developers use on a day to day basis is associative. Is that even possible or is there perhaps some fundamental limit that forces us to trade associativity for performance?

It seems to me that non associative floating point operations force us into a local maximum. The operation itself might be efficient on modern machines, but could it be preventing us from applying other important high level optimizations to our programs due to its lack of associativity? A richer algebraic structure should always be amenable to a richer set of potential optimizations.

---

I've asked a question that is very much related to that topic on the programming language subreddit:

"Could numerical operations be optimized by using algebraic properties that are not present in floating point operations but in numbers that have infinite precision?"

https://www.reddit.com/r/ProgrammingLanguages/comments/145kp...

The responses there might be interesting to some people here.


I’m not 100% clear on what you are asking, but integer addition is associative, right? (With quibbles about over/underflow of course). If you have some limited range of decimal numbers that you care about, you can always just use integers and account for the shifted decimal places as needed.

Floats are mostly for when you need that dynamic range.


It could also be that a lot of languages don't actually have integer types and just use a 64bit floating point number instead - ala JavaScript etc.


worth mentioning - js has had a built-in bigint type for quite a while now:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

the problem is it's marginally useful, since everyone expects number


Really? That seems nuts. How do they index an array?


They index them with doubles, they do the same with loop variables. As long as your integer is less (in absolute value) than about 2^53 (because they have 53 bit mantisas) you can represent it exactly with a double. 2^53 is 2^(10*5+3) so even if you're indexing individual bytes that many indexes works until you need to index into an array with 8 petabytes of data in it, at which point you're probably not using javascript anymore.

Like many things in javascript it's a bit cursed but it does work.


Plus 53-bit indices exceed the amount of memory that many 64-bit architectures can address (x86_64 is 48 bits, ARM is either 48 or 52 bits).



Thanks for the correction! TIL.


Tbf, it's not commonly run because it increases TLB miss latency for rarely any benefit (why are you mmap-ing so much? How can you afford to keep that much data around...).


In practice, JavaScript has 32-bit signed integers and 64-bit floating-point numbers as distinct types (look into any JS engine, and you'll see a distinction between the two being made), even if they both surface as a single "number" type. You can also see the distinction in the way that bitwise operators coerce numbers to integers, even though the arithmetic operators coerce to floats in theory.


The spec describes the behavior of converting to and from 32-bit signed for the purposes of the bitwise operators. https://tc39.es/ecma262/#sec-toint32


floor() enters the chat


It would be quite funny if that was how it worked, but it just checks to see if the exponent is 0 and then uses the mantisa as the index if so.


> I'm still wondering if there could exist an alternative world where efficient addition over decimal numbers that we developers use on a day to day basis is associative. Is that even possible or is there perhaps some fundamental limit that forces us to trade associativity for performance?

You're always welcome to use a weaker notion of associativity than bitwise equality (e.g., -ffast-math pretends many operations are associative to reorder them for speed, and that only gives approximately correct results on well-conditioned problems).

In general though, yes, such a limit does exist. Imagine, for the sake of argument, an xxx.yyy fixed-point system. What's the result of 100 * 0.01 * 0.01? You either get 0.01 or 0, depending on where you place the parentheses.

The general problem is in throwing away information. Trashing bits doesn't necessarily mean your operations won't be associative (imagine as a counter-example the infix operator x+y==1 for all x,y). It doesn't take many extra conditions to violate associativity though, and trashed bits for addition and multiplication are going to fit that description.

How do you gain associativity then? At a minimum, you can't throw information away. Your fast machine operations use an unbounded amount of RAM and don't fit in registers. Being floating-point vs fixed-point only affects that conclusion in extremely specialized cases (like only doing addition without overflow -- which sometimes applies to the financial industry, but even then you need to think twice about the machine representation of what you're doing).


> How do you gain associativity then? At a minimum, you can't throw information away.

That's an interesting perspective that I haven't considered before, thank you.

Now I'm wondering, could we throw away some information in just the right way and still maintain associativity? That is, it doesn't seem like throwing information away is fundamentally what's preventing us from having an associative operation, since we can throw information away and still maintain associativity by, for example, converting each summand to a 0 and adding them, and that operation would be associative. However, we would have thrown all information away, which is not useful, but we would have an associative operation.


Herbie, a fp optimizer, might be of interest to you

https://herbie.uwplse.org/


There's a link in there to future directions for Herbie which talks about the intriguing idea of out-sourcing the translation of a high level "I want to do this real number math" to the lower level "Here's some floating point arithmetic" via Herbie.

That is, the physicist writes the two line equation they want for electromagnetic force into their program, the same way they'd write a for-each style loop in the program if that's what they needed.

Obviously the CPU doesn't understand how to compute the appropriate approximation for this electromagnetic force equation, but nor does it understand how to iterate over each item in a container. Tools convert the for-each loop into machine code, why shouldn't other, smart, tools convert the physicist's equation into the FP instructions ?

Today the for-each loop thing just works, loads of programming languages do that, if a language can't do it (e.g. C) that's because it is old or only intended for experts or both.

But every popular language insists that physicist should laboriously convert the equation into the code to compute an approximation, which isn't really their skill set, so why not automate that problem?


> Could numerical operations be optimized by using algebraic properties that are not present in floating point operations but in numbers that have infinite precision?

... are you not aware of -ffast-math? There are several fast-math optimizations that are basically "assume FP operations have this algebraic property, even though they don't" (chiefly, -fassociative-math assumes associative and distributive laws hold).


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: