Xref: utzoo comp.sys.atari.st:12655 comp.os.minix:4181
Path: utzoo!utgpu!watmath!egisin
From: egisin@watmath.waterloo.edu (Eric Gisin)
Newsgroups: comp.sys.atari.st,comp.os.minix
Subject: improved long multiply for GCC -m68000
Message-ID: <22486@watmath.waterloo.edu>
Date: 30 Nov 88 14:24:48 GMT
Distribution: comp
Organization: U of Waterloo, Ontario
Lines: 38

Here's an improved long multiply for the 68000.
The original came from some program in comp.sources.amiga.
It uses a single hardware multiply when the arguments are
the range 0 to 2^^16 - 1. The signed version is the
same as the unsigned, since a non-widening twos complement
multiply is the same for signed and unsigned operands
(except for overflow detection, which we ignore).

| optimized long multiply - author unknown

.globl	__mulsi3, __umulsi3

	.text; .even
__mulsi3:
__umulsi3:
	movel	SP@(4), D0
	movel	SP@(8), D1
	movel	D2, A1
	movel	D0, D2
	mulu	D1, D2
	movel	D2, A0
	movel	D0, D2
	orl	D1, D2
	swap	D2
	tstw	D2		| if (D0.hi | D1.hi) == 0
	beq	L1		| return A0
	movel	D0, D2
	swap	D2
	mulu	D1, D2
	swap	D1
	mulu	D1, D0
	addl	D2, D0
	swap	D0
	clrw	D0
	addl	D0, A0
L1:	movel	A0, D0
	movel	A1, D2
	rts