Re: Altivec problems
Re: Altivec problems
- Subject: Re: Altivec problems
- From: Raphael Sebbe <email@hidden>
- Date: Fri, 21 Mar 2003 08:23:10 +0100
Hi,
I guess here shouldn't be any use of altivec extensions in a function
meant for a G3 (it would mess up non existing registers when entering,
and stuff like that). Use separate functions, or, even better, separate
libraries (with and without altivec) implementing the same interface,
and load the appropriate one at runtime.
HTH,
Raphael
On Friday, March 21, 2003, at 05:38 AM, Lance Pysher wrote:
I have some code that I have optimized for Altivec and works great on a
G4. I separated the G3 code from the G4 code in separate if...else...
statements. However it keeps crashing on a G3 if I comment out the G4
code, it runs the G3 code fine, and doesn't log that it went through
the code block. Do I need to some other sort of code separation.
- (void)convertDicomToHost{
int length = [[[self dicomDictionary] objectForKey:@"PixelData"]
length];
int i = 0;
int j = 0;
short rescaleIntercept;
float rescaleSlope;
signed short *pointer = ([[[self dicomDictionary]
objectForKey:@"PixelData"] mutableBytes]);
if ([dicomDictionary objectForKey:@"RescaleIntercept"] != nil)
rescaleIntercept = ([[dicomDictionary
objectForKey:@"RescaleIntercept"] intValue]);
else
rescaleIntercept = 0.0;
//rescale Slope
if ([dicomDictionary objectForKey:@"RescaleSlope"] != nil)
rescaleSlope = [[dicomDictionary
objectForKey:@"RescaleSlope"] floatValue];
else
rescaleSlope = 1.0;
if (![self isAltiVecAvailable]){
NSLog(@"G3");
for (i= 0; i<length/2; i++)
*pointer++ = rescaleIntercept +(rescaleSlope *
NSSwapLittleShortToHost(*pointer));
}
else{
NSLog(@"G4");
union vectorShort rescaleInterceptV ;
// float *rescaleSlopeV;
vector unsigned short eight = (vector unsigned short)(8);
vector short *vPointer = ([[[self dicomDictionary]
objectForKey:@"PixelData"] mutableBytes]);
//rescale Intercept
//Swap non G4 acceptable values. Then do rest with Altivec
for (i = 0; i< fmod(length,8); i++)
*pointer++ = NSSwapLittleShortToHost(*pointer);
for (i= fmod(length,8); i< length/16; i++)
*vPointer++ = vec_rl(*vPointer, eight);
if ((rescaleIntercept != 0) && (rescaleSlope == 1)) {
for (j = 0; j < 8; j++)
rescaleInterceptV.scalar[j] = rescaleIntercept;
short *pixelData = ([[[self dicomDictionary]
objectForKey:@"PixelData"] mutableBytes]);
vPointer = ([[[self dicomDictionary]
objectForKey:@"PixelData"] mutableBytes]);
for (i = 0; i< fmod(length,8); i++)
*pixelData++ = *pixelData + rescaleIntercept;
for (i= fmod(length,8); i<length/16; i++)
*vPointer++ = vec_add(*vPointer,
rescaleInterceptV.shortVec);
}
else if ((rescaleIntercept != 0) && (rescaleSlope != 1)) {
short *pixelData = ([[[self dicomDictionary]
objectForKey:@"PixelData"] mutableBytes]);
for (i= 0; i<length/2; i++)
*pixelData++ = *pixelData * rescaleSlope +
rescaleIntercept;
}
NSMutableData *tempData = [NSMutableData dataWithLength:
length
* 2 ];
short *pixelData = ([[[self dicomDictionary]
objectForKey:@"PixelData"] mutableBytes]);
short *temp = [tempData mutableBytes];
/*
NSLog(@"Start convert to int");
for (i= 0; i<length/2; i++)
temp[i*2] = *pixelData;
NSLog(@"End Convert");
*/
}
Lance Pysher, M.D.
email@hidden
http://irad.sourceforge.net/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.