Handmade Network»Forums»Wheel Reinvention Jam
1 posts
Can someone translate line drawing function from ASM to C?

Hello, guys! My name is Dan. Heavily inspired by HMH series I am writing my own engine/software renderer, thus I am interested in fastest possible line drawing routine. After Bresenham's implementation, after EFLA, the fastest one I have found is Michael Abrash's Run Length Slice Algo: https://www.phatcode.net/res/224/files/html/ch36/36-03.html LISTING 36.1 L36-1.C. I modified it to work, and it is very good. However: Mr. Abrash present an even faster function but written in ASM: https://www.phatcode.net/res/224/files/html/ch37/37-01.html LISTING 37.1 L37-1.ASM So, if someone can translate this function to C, maybe even add intrinsics, that would be a new hero in cg world with += 999 karma. Thank you! P.S. 1. I live in Vietnam and banned from openai chatgpt. 2. perplexity and bingai cannot handle this function. 3. I use gcc on win32 via winlibs. 4. I use stretchdibits, u32 color, malloced memory buffer.

Mārtiņš Možeiko
2547 posts / 2 projects
Can someone translate line drawing function from ASM to C?
Edited by Mārtiņš Možeiko on

That asm function is doing same thing as C code in your previous link. Translating that asm code to C will give you same code as you already see.

People did write manual asm back in days, because compilers were not good at producing optimized code. There were many reasons for that - computers were slower, compilers were smaller, there were fewer registers to store temporaries (which means human could figure out better tricks), etc...

Nowadays any decent compiler will take that C code and produce reasonably good machine code.