HVM icon indicating copy to clipboard operation
HVM copied to clipboard

Add multiply-high operation

Open CatsAreFluffy opened this issue 1 year ago • 3 comments

Is your feature request related to a problem? Please describe. Currently, multiplying numbers with more than 24 bits is awkward, since you can only access the lower 24 bits of the full 48-bit result.

Describe the solution you'd like A new primitive operation that multiplies two numbers and returns the high half of the product.

Describe alternatives you've considered Waiting for native support for bigger numbers (and then asking for multiply-high for those since people will always need bigger numbers)

Additional context

CatsAreFluffy avatar May 31 '24 06:05 CatsAreFluffy

We probably won't add this, and will instead just suggest using the extended numerics (https://github.com/HigherOrderCO/HVM/issues/319) once support for that is added.

enricozb avatar May 31 '24 09:05 enricozb

Wait why not? Looks like a great idea actually. Now that I think about it, a set of opcodes to allow for u48 implementations using (u24,u24) tuples look like an amazing intermediate between fast unboxed numbers and slow boxed ones. Perhaps we could actually implement native u48's as (CON u24 u24)?

VictorTaelin avatar Jun 02 '24 17:06 VictorTaelin

We could add it, but we'd be supporting quite a few numeric representations though.

enricozb avatar Jun 02 '24 19:06 enricozb