Altivec problems
Altivec problems
- Subject: Altivec problems
- From: Lance Pysher <email@hidden>
- Date: Thu, 20 Mar 2003 21:38:06 -0700
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.