English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 08 January 2018, 22:44   #1
dalton
tulou
 
dalton's Avatar
 
Join Date: Jun 2006
Location: Gothenburg / Sweden
Posts: 88
vbcc 0.9e signed multiplication issue?

I'm struggling with the most basic of things now it seems.

This function (signed multiplication)

Code:
int foo(int a, int b)
{
	return a*b;
}
compiles to this (unsigned multiplication)

Code:
; stacksize=0
	near	code
	opt	0
	opt	NQLPSMRBT
	public	_foo
	cnop	0,4
_foo
	movem.l	l132,-(a7)
	move.l	(4+l134,a7),d0
	move.l	(8+l134,a7),d1
	move.l	d0,d2
	move.l	d1,d3
	swap	d2
	swap	d3
	mulu.w	d1,d2
	mulu.w	d0,d3
	mulu.w	d1,d0
	add.w	d3,d2
	swap	d2
	clr.w	d2
	add.l	d2,d0
l130
l132	reg	d2/d3
	movem.l	(a7)+,d2/d3
l134	equ	8
	rts
My command line looks like this:
Code:
devkit/tools/win32/vbccm68k.exe -I. -Idevkit/vbcc-targets/m68k-amigaos/include -Idevkit/include -c99 -quiet -D__VBCC__ -D__AMIGA__ -D__MINSTART__ -DOVERSCAN=1 -cpu=68000  -O=0 -maxoptpasses=65535 -dontwarn=72     -sc  -DNDEBUG  -o=main._s main.c
I must be doing something wrong?
dalton is offline  
Old 08 January 2018, 23:09   #2
Samurai_Crow
Total Chaos forever!
 
Samurai_Crow's Avatar
 
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,186
A 32 bit multiply on a 16 bit CPU?
Samurai_Crow is offline  
Old 09 January 2018, 00:46   #3
robinsonb5
Registered User
 
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 1,153
Quote:
Originally Posted by dalton View Post
I must be doing something wrong?
Are you getting incorrect results?
You're asking for a pair of 32-bit values to be multiplied, and for the lower 32-bits of the result (which would be 64-bit) to be returned, and that's what the code is doing. It doesn't matter that the code is using mulu for this - I think the difference in results between signed and unsigned multiplication will be in the upper 32-bits of the result, which you're discarding.
robinsonb5 is offline  
Old 09 January 2018, 08:47   #4
dalton
tulou
 
dalton's Avatar
 
Join Date: Jun 2006
Location: Gothenburg / Sweden
Posts: 88
Quote:
Originally Posted by robinsonb5 View Post
Are you getting incorrect results?
You're asking for a pair of 32-bit values to be multiplied, and for the lower 32-bits of the result (which would be 64-bit) to be returned, and that's what the code is doing. It doesn't matter that the code is using mulu for this - I think the difference in results between signed and unsigned multiplication will be in the upper 32-bits of the result, which you're discarding.
You're right, thanks! It's true that signed and unsigned multiplication are equivalent in this case. I believed I had it figured out last night but it turns out I did not put enough thought into it.

I'm having weird sign-related errors in my program, but it must be related to something other than multiplication.
dalton is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
vbcc bss clearing issue dalton Coders. C/C++ 3 02 December 2017 22:50
vbcc 0.9f (windows) local includes issue? dalton Coders. C/C++ 4 29 July 2017 21:33
vbcc 0.9d phx News 43 13 July 2015 19:41
Best Way to Convert 32-bit Signed Value to 16 Bit? AGS Coders. Asm / Hardware 31 29 December 2013 13:58
64 bit signed multiply cdoty Coders. General 2 16 December 2007 12:24

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 18:37.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.11801 seconds with 13 queries