English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 28 July 2013, 18:28   #1
Cowcat
Registered User
 
Join Date: Apr 2013
Location: Mallorca
Posts: 758
Mixed 68k / PPC code on VBCC.

Hello. This is my first post.

So far I've been testing some 68k C code that sends data (array with integers) to a PPC C code function and returns the result: Compiled each object file with their respective cpu directives and then linked both finally as 68k code. It works.

The problem I face is when my data is based arround float point: The PPC code needs the link library -lm to work correctly, but at linking time I can only use 68k link libraries.

Being a half begginer coder I don't know if it is possible such a thing, or if I need some kind of stub (fd,etc) with mixed math code from both cpu's.

Any idea?
"2013 and playing with my old Commodore A 1200-40/PPC "

Last edited by Cowcat; 28 July 2013 at 19:47.
Cowcat is offline  
Old 28 July 2013, 18:30   #2
Bamiga2002
BlizzardPPC'less
 
Bamiga2002's Avatar
 
Join Date: May 2004
Location: Finland
Age: 46
Posts: 3,210
Send a message via MSN to Bamiga2002
I don't know the answers to your coding questions, but I'm always after members to join our Blizzard PPC club

Welcome to EAB
Bamiga2002 is offline  
Old 28 July 2013, 19:46   #3
Cowcat
Registered User
 
Join Date: Apr 2013
Location: Mallorca
Posts: 758
Thanks!
Cowcat is offline  
Old 29 July 2013, 10:38   #4
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,500
Quote:
Originally Posted by Cowcat View Post
The problem I face is when my data is based arround float point: The PPC code needs the link library -lm to work correctly, but at linking time I can only use 68k link libraries.
Are you trying to build a WarpOS executable?

You have to resolve all PPC symbol references, before doing the final linking step with the 68k startup code, objects and libraries. So you may try the following with all the PPC objects (from memory, assuming WarpOS EHF object file format):

Code:
vlink -bamigaehf -r -o ppc.o ppcobj1.o ppcobj2.o ... -Lvlibwos: -lm
-r means that you don't want to create an executable, but an object file, suitable for another linker pass. This should resolve all PPC references to floating point functions from m.lib.

In the final linking step you just link with ppc.o.
phx is offline  
Old 29 July 2013, 12:40   #5
Cowcat
Registered User
 
Join Date: Apr 2013
Location: Mallorca
Posts: 758
Thanks a lot phx. It's a warpos object. I tried something like that but the result it's a warpos exception. I'll post code later.
Cowcat is offline  
Old 29 July 2013, 15:55   #6
Cowcat
Registered User
 
Join Date: Apr 2013
Location: Mallorca
Posts: 758
code1.c

#include <stdio.h>
#ifdef __VBCC__
#pragma amiga-align
#endif
#include <proto/exec.h>
#include <powerpc/powerpc.h>
#include <proto/powerpc.h>
#ifdef __VBCC__
#pragma default-align
#endif
#include "st.h"
extern void PPC_add();
int i;
vertex v[] = {
{-0.5,-0.5, 1.0},
{-0.5, 0.5, 1.0},
{ 0.5,-0.5, 1.0},
{ 0.5, 0.5, 1.0}
};

int main()
{

struct PPCArgs pa;
pa.PP_Code =(ULONG *)&PPC_add;
pa.PP_Offset = 0;
pa.PP_Flags = PPF_LINEAR;
pa.PP_Stack = 0;
pa.PP_StackSize=0;
pa.PP_Regs[0]=(ULONG) &v;

printf("Going PPC\n");
RunPPC(&pa);
for(i=0;i<4;i++){
printf("Result X %f\n",v[i].x);
printf("Result Y %f\n",v[i].y);
printf("Result Z %f\n",v[i].z);
printf("\n");
}
return(0);
}

##############################################
code2.c

#include <math.h>
#include "st.h"

void PPC_add (__reg("r3") vertex *p) {
int i;
for(i=0;i<4;i++){
p[i].x = p[i].x +0.5;
p[i].y = p[i].y +0.5;
p[i].z = p[i].z +0.5;
}
}

##########################
st.h

typedef struct{
float x,y,z;
}vertex;

Then....
vc +aos68k -c99 -c code1.c
vc +warpos -c99 -c code2.c
vlink -bamigaehf -r -o ppc.o code2.o -Lvlibwos: -lm
vc +aos68k -o crap code1.o ppc.o -lamiga -lmieee -lauto

Something is wrong in my code (crap) : Results are weird (sometimes same original values, others unexpected float values)....... Same happens without linking ppc object with -lm.
No problem if I modify array and code to work only with integers.

Last edited by Cowcat; 29 July 2013 at 16:03.
Cowcat is offline  
Old 31 July 2013, 11:02   #7
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,500
I guess your problem is that the TOC pointer in r2 is not initialized for the PPC code, so static data references will access random memory locations.

The TOC pointer in r2 is the same as the small data pointer in a4 for the M68k. You either have to pass it via PP_Regs (from LinkerDB symbol) or use the attribute __saveds for PPC_add(), so the function will restore the TOC register itself. I would recommend
Code:
__saveds void PPC_add (__reg("r3") vertex *p) {
for a first test.

When it still doesn't work then I need some time to reproduce it on a real WarpOS environment at home.

Quote:
Originally Posted by Cowcat View Post
#ifdef __VBCC__
#pragma amiga-align
#endif
BTW, those #ifdefs are not needed, because by definition a #pragma directive must be ignored by the compiler, when it is unknown.


Quote:
Results are weird (sometimes same original values, others unexpected float values).......
That's because of the random TOC register. The 0.5 float constant has to be loaded from the data section, which fails. It works with integers, because integers can be loaded directly into a register. No data access needed.

Quote:
Same happens without linking ppc object with -lm.
This was not even needed. I didn't see any reference to m.lib from your PPC code.

But now, when using __saveds, you have to link with the WarpOS -lvc here, to resolve a reference to the __setr2 function, which restores the TOC pointer.
phx is offline  
Old 31 July 2013, 12:48   #8
Cowcat
Registered User
 
Join Date: Apr 2013
Location: Mallorca
Posts: 758
Awesome. My initial thought about linking m.lib, was that compiling for only warpos a similiar code, and without linking that lib, the printf output is a "%f" string (??) More brain storming, thank you again.
Cowcat is offline  
Old 31 July 2013, 13:00   #9
Cowcat
Registered User
 
Join Date: Apr 2013
Location: Mallorca
Posts: 758
Perfect. It works (__saveds & linking -lvc ) !!! ,)
Cowcat is offline  
Old 31 July 2013, 17:09   #10
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,500
Quote:
Originally Posted by Cowcat View Post
My initial thought about linking m.lib, was that compiling for only warpos a similiar code, and without linking that lib, the printf output is a "%f" string (??)
True. When the PPC code would call printf() to output float, then you need the math-extended version of it, so you have to link with m.lib in this case. But in your PPC_add() was nothing like that.

Quote:
Perfect. It works (__saveds & linking -lvc ) !!! ,)
Great!
phx is offline  
Old 01 August 2013, 16:01   #11
Cowcat
Registered User
 
Join Date: Apr 2013
Location: Mallorca
Posts: 758
I owe you two beers.
Cowcat 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
68k & 060 friendly code... korruptor Coders. Tutorials 5 05 February 2011 15:46
68K/PPC context switching? RedskullDC support.Hardware 1 08 December 2008 11:44
VBCC 0.8j for Windows hitchhikr Coders. General 11 09 October 2008 00:58
Any interested in buying NEW PPC and 68K accelerators for A1200? keropi MarketPlace 8 23 February 2005 00:20
Aweb: New APL 3.5Beta AOS4 PPC code + Milestone: KHTML porting started Paul News 0 05 November 2004 11:21

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 13:17.

Top

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