Skip to content

Commit ef60956

Browse files
committed
CogVM source as per VMMaker.oscog-eem.3722
Fix the underlying cause of the failure of partitionedMul:with:nBits:wordBits: on 32-bits (a shift requires an explicit cast to avoid truncation). Revert hacks.
1 parent ee12b3d commit ef60956

File tree

2 files changed

+7
-71
lines changed

2 files changed

+7
-71
lines changed

building/win32x86/common/Makefile.msvc.flags

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ undefine MSVC
4242
export TOOLPREFIX
4343
$(info CC=$(CC))
4444
AS:=as --32
45-
XCFLAGS+=-DRGBMul32BitFallBack=1
4645

4746
$(info CC=$(CC))
4847

src/plugins/BitBltPlugin/BitBltPlugin.c

Lines changed: 7 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/* Automatically generated by
2-
SmartSyntaxPluginCodeGenerator VMMaker.oscog-eem.3721 uuid: f3895c70-5b57-4684-92f6-72aee920c70e
2+
SmartSyntaxPluginCodeGenerator VMMaker.oscog-eem.3722 uuid: 5cb8d220-2e6d-4207-9f4f-2f3a99b4c5e1
33
(Compiler-eem.527)
44
from
5-
BitBltSimulation VMMaker.oscog-eem.3721 uuid: f3895c70-5b57-4684-92f6-72aee920c70e
5+
BitBltSimulation VMMaker.oscog-eem.3722 uuid: 5cb8d220-2e6d-4207-9f4f-2f3a99b4c5e1
66
*/
7-
static char __buildInfo[] = "BitBltSimulation VMMaker.oscog-eem.3721 uuid: f3895c70-5b57-4684-92f6-72aee920c70e " __DATE__ ;
7+
static char __buildInfo[] = "BitBltSimulation VMMaker.oscog-eem.3722 uuid: 5cb8d220-2e6d-4207-9f4f-2f3a99b4c5e1 " __DATE__ ;
88

99

1010
#include "config.h"
@@ -132,9 +132,6 @@ static unsigned int partitionedAddtonBitscomponentMaskcarryOverflowMask(unsigned
132132
static unsigned int partitionedANDtonBitsnPartitions(unsigned int word1, unsigned int word2, sqInt nBits, sqInt nParts);
133133
static unsigned int partitionedMaxwithnBitsnPartitions(unsigned int word1, unsigned int word2, sqInt nBits, sqInt nParts);
134134
static unsigned int partitionedMinwithnBitsnPartitions(unsigned int word1, unsigned int word2, sqInt nBits, sqInt nParts);
135-
#if RGBMul32BitFallBack
136-
static unsigned int partitionedMulwithnBitsnPartitions(unsigned int word1, unsigned int word2, sqInt nBits, sqInt nParts);
137-
#endif /* RGBMul32BitFallBack */
138135
static unsigned int partitionedMulwithnBitswordBits(unsigned int word1, unsigned int word2, sqInt nBits, sqInt wordBits);
139136
static unsigned int partitionedSubfromnBitsnPartitions(unsigned int word1, unsigned int word2, sqInt nBits, sqInt nParts);
140137
static unsigned int pixClearwith(unsigned int sourceWord, unsigned int destinationWord);
@@ -349,7 +346,7 @@ static int maskTable[33] = {
349346
0, 1, 3, 0, 15, 31, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 65535,
350347
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1
351348
};
352-
static const char *moduleName = "BitBltPlugin VMMaker.oscog-eem.3721 " INT_EXT;
349+
static const char *moduleName = "BitBltPlugin VMMaker.oscog-eem.3722 " INT_EXT;
353350
static sqInt noHalftone;
354351
static sqInt noSource;
355352
static sqInt numGCsOnInvocation;
@@ -4068,52 +4065,6 @@ partitionedMinwithnBitsnPartitions(unsigned int word1, unsigned int word2, sqInt
40684065
}
40694066

40704067

4071-
/* Multiply word1 with word2 as nParts partitions of nBits each.
4072-
This is useful for packed pixels, or packed colors.
4073-
Bug in loop version when non-white background */
4074-
/* In C, integer multiplication might answer a wrong value if the unsigned
4075-
values are declared as signed.
4076-
This problem does not affect this method, because the most significant bit
4077-
(i.e. the sign bit) will
4078-
always be zero (jmv)
4079-
*/
4080-
4081-
/* BitBltSimulation>>#partitionedMul:with:nBits:nPartitions: */
4082-
#if RGBMul32BitFallBack
4083-
static unsigned int
4084-
partitionedMulwithnBitsnPartitions(unsigned int word1, unsigned int word2, sqInt nBits, sqInt nParts)
4085-
{
4086-
unsigned int dMask;
4087-
unsigned int product;
4088-
unsigned int result;
4089-
unsigned int sMask;
4090-
4091-
/* partition mask starts at the right */
4092-
sMask = maskTable[nBits];
4093-
dMask = (((usqInt)(sMask) << nBits));
4094-
4095-
/* optimized first step */
4096-
result = ((usqInt)((((((word1 & sMask) + 1) * ((word2 & sMask) + 1)) - 1) & dMask))) >> nBits;
4097-
if (nParts == 1) {
4098-
return result;
4099-
}
4100-
product = (((((((usqInt)(word1)) >> nBits) & sMask) + 1) * (((((usqInt)(word2)) >> nBits) & sMask) + 1)) - 1) & dMask;
4101-
result = result | product;
4102-
if (nParts == 2) {
4103-
return result;
4104-
}
4105-
product = (((((((usqInt)(word1)) >> (2 * nBits)) & sMask) + 1) * (((((usqInt)(word2)) >> (2 * nBits)) & sMask) + 1)) - 1) & dMask;
4106-
result = result | ((((usqInt)(product) << nBits)));
4107-
if (nParts == 3) {
4108-
return result;
4109-
}
4110-
product = (((((((usqInt)(word1)) >> (3 * nBits)) & sMask) + 1) * (((((usqInt)(word2)) >> (3 * nBits)) & sMask) + 1)) - 1) & dMask;
4111-
result = result | ((((usqInt)(product) << (2 * nBits))));
4112-
return result;
4113-
}
4114-
#endif /* RGBMul32BitFallBack */
4115-
4116-
41174068
/* Multiply each channel of nBits in word1 and word2.
41184069
We assume that for each channel of nBits, we multiply ratios in interval
41194070
[0..1], scaled by (1 << nBits - 1).
@@ -4177,8 +4128,10 @@ partitionedMulwithnBitswordBits(unsigned int word1, unsigned int word2, sqInt nB
41774128
shift = 0;
41784129
doubleWordMul = 0;
41794130
for (i = 1; i <= (wordBits / nBits); i += 1) {
4131+
/* N.B. we must explicitly cast the expression to be shifted to 8 bytes, otherwise Slang will generate a 32-bit shift, truncating the result and hence breaking the code. */
4132+
41804133
/* multiply each channel of the two operands */
4181-
doubleWordMul += (((usqInt)((((((doubleWord1) >> shift) & channelMask) * (((doubleWord2) >> shift) & channelMask)) + half)) << shift));
4134+
doubleWordMul = ((((unsigned long long) (doubleWordMul + (((((doubleWord1) >> shift) & channelMask) * (((doubleWord2) >> shift) & channelMask)) + half)))) << shift);
41824135
shift += n2;
41834136
}
41844137

@@ -5926,21 +5879,6 @@ rgbMinwith(unsigned int sourceWord, unsigned int destinationWord)
59265879
static unsigned int
59275880
rgbMulwith(unsigned int sourceWord, unsigned int destinationWord)
59285881
{
5929-
5930-
# if RGBMul32BitFallBack
5931-
if (destDepth < 16) {
5932-
/* Mul each pixel separately */
5933-
return partitionedMulwithnBitsnPartitions(sourceWord, destinationWord, destDepth, destPPW);
5934-
}
5935-
if (destDepth == 16) {
5936-
/* Mul RGB components of each pixel separately */
5937-
return (partitionedMulwithnBitsnPartitions(sourceWord, destinationWord, 5, 3)) + ((((usqInt)((partitionedMulwithnBitsnPartitions(((usqInt)(sourceWord)) >> 16, ((usqInt)(destinationWord)) >> 16, 5, 3))) << 16)));
5938-
}
5939-
else {
5940-
/* Mul RGBA components of the pixel separately */
5941-
return partitionedMulwithnBitsnPartitions(sourceWord, destinationWord, 8, 4);
5942-
}
5943-
# else // RGBMul32BitFallBack
59445882
if (destDepth < 16) {
59455883
/* Mul each pixel separately */
59465884
if (destDepth == 1) {
@@ -5956,7 +5894,6 @@ rgbMulwith(unsigned int sourceWord, unsigned int destinationWord)
59565894
/* Mul RGBA components of the pixel separately */
59575895
return partitionedMulwithnBitswordBits(sourceWord, destinationWord, 8, 32);
59585896
}
5959-
# endif // RGBMul32BitFallBack
59605897
}
59615898

59625899
/* BitBltSimulation>>#rgbSub:with: */

0 commit comments

Comments
 (0)