Right shift vs. divide

John Gilmore gnu at l5.uucp
Fri Dec 27 11:23:05 AEST 1985


You can compile divides to right-shifts without *too* much effort...
The Sun Unix "3.0 Pilot" compiler compiles this:

int i = -15;
int j;
main() {
	j = i / 4;
}

----into----

_main:
	link	a6,#0
	movl	_i,d0
	jge	L2000000
	addql	#3,d0
L2000000:
	asrl	#2,d0
	movl	d0,_j
	unlk	a6
	rts

---- Still a lot faster than a divide!



More information about the Comp.lang.c mailing list