Skip to content

Instantly share code, notes, and snippets.

View Enichan's full-sized avatar

Emma Maassen Enichan

View GitHub Profile
@depp
depp / !Readme.md
Created November 13, 2022 07:45
Divide by 240

Fast Division

We want to calculate x/240, and to do that, we calculate (x*34953)>>23. This only works for sufficiently small values of x.

The value of 34953 looks like some kind of magic constant. It is really just ceil((1 << 23)/240)—the value 1/240, scaled up by 2^23. As you use larger scaling factors (above 1<<23), the value becomes more accurate, but you need more bits.

GCC can do this optimization for you under certain circumstances. GCC will convert x * 34953 to the same sequence of shifts and adds, if you are targeting an old processor like a 68000.

@nonarkitten
nonarkitten / amiga_gcc_tips.md
Last active April 25, 2023 06:38
Amiga GCC Tips

This is a work-in-progress note pad of all the things I've found about gcc to make the best code possible.

Do not use ixemul

Ever.

Generally, most other PC libraries are okay, including SDL and OpenGL, but ixemul will take awesome performing code and make it run like it's walking through a tar pit -- especially on any stdio file operations. When porting "small and dirty" POSIX applications where performance does not matter, then who cares, use ixemul. For everything else, don't. Don't even use libnix. Try as much as possible to use AmigaOS native functions like AllocVec over C standard functions like malloc.

Using register parameters