Skip to content

Commit

Permalink
Cryptography Plugins as per CryptographyPlugins-mt.25/eem.27
Browse files Browse the repository at this point in the history
Fix regressions in CryptographyPlugins-eem.23. Specifically alignment crashes in
	DESPlugin>>#primitiveDESCookKey,
	SHA2Plugin>>#primitiveSHA512ProcessBufferUpdatingHash,
	SHA2Plugin>>#primitiveSHA256ProcessBufferUpdatingHash
with Clang on SSE x86_64, which requires 128-bit stack alignment.

Fix type-casting issue on Windows 64-bit systems. We must use "long long" if
we mean "double word".

Polish:
Now there is an API call (isLong64s:) to determine if something is double words,
use it.

There is no need to use stackObjectValue: if its result is tested via isBytes:,
isWords: et al.  These methods check for immediates, so the check in
stackObjectValue: is redundant and expensive (it must set the failed flag which
should be tested later).

Don't bother assigning the result of firstIndexableField: to an intermediate
variable; its return type is void *, so it's perfect as an argument to memcpy:
et al.

Amalgamate tests using and: to have as few
	^interpreterProxy primitiveFailFor: PrimErrBadArgument
clauses as possible (greater instruction cache density).
Use methodReturnReceiver (ditto)
  • Loading branch information
eliotmiranda committed Dec 13, 2021
1 parent 97b4903 commit 27d2d9f
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 114 deletions.
68 changes: 40 additions & 28 deletions src/plugins/DESPlugin/DESPlugin.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* Automatically generated by
VMPluginCodeGenerator VMMaker.oscog-eem.3090 uuid: 3e2b8343-01bb-4169-ba4c-aecf82b4dcfc
VMPluginCodeGenerator VMMaker.oscog-eem.3119 uuid: c0b40a55-50ca-4dd9-8b6f-d355a6dd5e1f
from
DESPlugin * CryptographyPlugins-eem.23 uuid: bc8a8db4-2e4d-458f-bac9-f007458fdd4d
DESPlugin CryptographyPlugins-eem.27 uuid: 63bc0f04-a4d3-4347-84fc-20b64ea64093
*/
static char __buildInfo[] = "DESPlugin * CryptographyPlugins-eem.23 uuid: bc8a8db4-2e4d-458f-bac9-f007458fdd4d " __DATE__ ;
static char __buildInfo[] = "DESPlugin CryptographyPlugins-eem.27 uuid: 63bc0f04-a4d3-4347-84fc-20b64ea64093 " __DATE__ ;


#include "config.h"
Expand Down Expand Up @@ -58,30 +58,40 @@ static unsigned short byteBit[8] = {

#if !defined(SQUEAK_BUILTIN_PLUGIN)
static void * (*firstIndexableField)(sqInt oop);
#if !defined(integerValueOf)
static sqInt (*integerValueOf)(sqInt oop);
#endif
static sqInt (*isBytes)(sqInt oop);
#if !defined(isIntegerObject)
static sqInt (*isIntegerObject)(sqInt objectPointer);
#endif
static sqInt (*isWords)(sqInt oop);
static sqInt (*methodArgumentCount)(void);
static sqInt (*methodReturnBool)(sqInt boolean);
static sqInt (*pop)(sqInt nItems);
static sqInt (*methodReturnReceiver)(void);
static sqInt (*primitiveFailFor)(sqInt reasonCode);
static sqInt (*stSizeOf)(sqInt oop);
static sqInt (*stackIntegerValue)(sqInt offset);
static sqInt (*stackValue)(sqInt offset);
#else /* !defined(SQUEAK_BUILTIN_PLUGIN) */
extern void * firstIndexableField(sqInt oop);
#if !defined(integerValueOf)
extern sqInt integerValueOf(sqInt oop);
#endif
extern sqInt isBytes(sqInt oop);
#if !defined(isIntegerObject)
extern sqInt isIntegerObject(sqInt objectPointer);
#endif
extern sqInt isWords(sqInt oop);
extern sqInt methodArgumentCount(void);
extern sqInt methodReturnBool(sqInt boolean);
extern sqInt pop(sqInt nItems);
extern sqInt methodReturnReceiver(void);
extern sqInt primitiveFailFor(sqInt reasonCode);
extern sqInt stSizeOf(sqInt oop);
extern sqInt stackIntegerValue(sqInt offset);
extern sqInt stackValue(sqInt offset);
extern
#endif
struct VirtualMachine* interpreterProxy;
static const char *moduleName = "DESPlugin * CryptographyPlugins-eem.23 " INT_EXT;
static const char *moduleName = "DESPlugin CryptographyPlugins-eem.27 " INT_EXT;
static unsigned char pc1[56] = {
56, 48, 40, 32, 24, 16, 8, 0, 57, 49, 41, 33, 25, 17,
9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35,
Expand Down Expand Up @@ -376,18 +386,17 @@ primitiveDESCookKey(void)
return primitiveFailFor(PrimErrBadNumArgs);
}
rawOop = stackValue(2);
if (!((isBytes(rawOop))
&& ((stSizeOf(rawOop)) == 8))) {
return primitiveFailFor(PrimErrBadArgument);
}
encode = stackIntegerValue(1);
encode = stackValue(1);
cookedOop = stackValue(0);
if (!((isWords(cookedOop))
&& ((stSizeOf(cookedOop)) == 32))) {
if (!((isBytes(rawOop))
&& (((stSizeOf(rawOop)) == 8)
&& ((isIntegerObject(encode))
&& ((isWords(cookedOop))
&& ((stSizeOf(cookedOop)) == 32)))))) {
return primitiveFailFor(PrimErrBadArgument);
}
processKeymodeto(firstIndexableField(rawOop), encode != 0, firstIndexableField(cookedOop));
pop(3);
processKeymodeto(firstIndexableField(rawOop), (integerValueOf(encode)) != 0, firstIndexableField(cookedOop));
methodReturnReceiver();
return 0;
}

Expand Down Expand Up @@ -425,13 +434,11 @@ primitiveDESTransform(void)
return primitiveFailFor(PrimErrBadNumArgs);
}
dataOop = stackValue(1);
if (!((isBytes(dataOop))
&& ((stSizeOf(dataOop)) == 8))) {
return primitiveFailFor(PrimErrBadArgument);
}
cookedOop = stackValue(0);
if (!((isWords(cookedOop))
&& ((stSizeOf(cookedOop)) == 32))) {
if (!((isBytes(dataOop))
&& (((stSizeOf(dataOop)) == 8)
&& ((isWords(cookedOop))
&& ((stSizeOf(cookedOop)) == 32))))) {
return primitiveFailFor(PrimErrBadArgument);
}
data = firstIndexableField(dataOop);
Expand Down Expand Up @@ -517,7 +524,7 @@ primitiveDESTransform(void)
data[5] = ((((usqInt)((work[1]))) >> 16) & 0xFF);
data[6] = ((((usqInt)((work[1]))) >> 8) & 0xFF);
data[7] = ((work[1]) & 0xFF);
pop(2);
methodReturnReceiver();
return 0;
}

Expand Down Expand Up @@ -631,14 +638,19 @@ setInterpreter(struct VirtualMachine *anInterpreter)

#if !defined(SQUEAK_BUILTIN_PLUGIN)
firstIndexableField = interpreterProxy->firstIndexableField;
#if !defined(integerValueOf)
integerValueOf = interpreterProxy->integerValueOf;
#endif
isBytes = interpreterProxy->isBytes;
#if !defined(isIntegerObject)
isIntegerObject = interpreterProxy->isIntegerObject;
#endif
isWords = interpreterProxy->isWords;
methodArgumentCount = interpreterProxy->methodArgumentCount;
methodReturnBool = interpreterProxy->methodReturnBool;
pop = interpreterProxy->pop;
methodReturnReceiver = interpreterProxy->methodReturnReceiver;
primitiveFailFor = interpreterProxy->primitiveFailFor;
stSizeOf = interpreterProxy->stSizeOf;
stackIntegerValue = interpreterProxy->stackIntegerValue;
stackValue = interpreterProxy->stackValue;
#endif /* !defined(SQUEAK_BUILTIN_PLUGIN) */
}
Expand Down Expand Up @@ -666,7 +678,7 @@ unscrunchto(unsigned int *wordPtr, unsigned char *bytePtr)
static char _m[] = "DESPlugin";
void* DESPlugin_exports[][3] = {
{(void*)_m, "getModuleName", (void*)getModuleName},
{(void*)_m, "primitiveDESCookKey\000\001\001", (void*)primitiveDESCookKey},
{(void*)_m, "primitiveDESCookKey\000\001\003", (void*)primitiveDESCookKey},
{(void*)_m, "primitiveDESPluginAvailable\000\377\001", (void*)primitiveDESPluginAvailable},
{(void*)_m, "primitiveDESTransform\000\001\001", (void*)primitiveDESTransform},
{(void*)_m, "setInterpreter", (void*)setInterpreter},
Expand All @@ -676,7 +688,7 @@ void* DESPlugin_exports[][3] = {
#else // ifdef SQ_BUILTIN_PLUGIN

#if SPURVM
EXPORT(signed short) primitiveDESCookKeyMetadata = 0x101;
EXPORT(signed short) primitiveDESCookKeyMetadata = 259;
EXPORT(signed short) primitiveDESPluginAvailableMetadata = -255;
EXPORT(signed short) primitiveDESTransformMetadata = 0x101;
#endif // SPURVM
Expand Down
31 changes: 15 additions & 16 deletions src/plugins/DSAPrims/DSAPrims.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* Automatically generated by
VMPluginCodeGenerator VMMaker.oscog-eem.3090 uuid: 3e2b8343-01bb-4169-ba4c-aecf82b4dcfc
VMPluginCodeGenerator VMMaker.oscog-eem.3119 uuid: c0b40a55-50ca-4dd9-8b6f-d355a6dd5e1f
from
DSAPlugin * CryptographyPlugins-eem.23 uuid: bc8a8db4-2e4d-458f-bac9-f007458fdd4d
DSAPlugin CryptographyPlugins-eem.27 uuid: 63bc0f04-a4d3-4347-84fc-20b64ea64093
*/
static char __buildInfo[] = "DSAPlugin * CryptographyPlugins-eem.23 uuid: bc8a8db4-2e4d-458f-bac9-f007458fdd4d " __DATE__ ;
static char __buildInfo[] = "DSAPlugin CryptographyPlugins-eem.27 uuid: 63bc0f04-a4d3-4347-84fc-20b64ea64093 " __DATE__ ;


#include "config.h"
Expand Down Expand Up @@ -67,9 +67,9 @@ static sqInt (*isBytes)(sqInt oop);
static sqInt (*isWords)(sqInt oop);
static sqInt (*methodArgumentCount)(void);
static sqInt (*methodReturnBool)(sqInt boolean);
static sqInt (*pop)(sqInt nItems);
static sqInt (*methodReturnInteger)(sqInt integer);
static sqInt (*methodReturnReceiver)(void);
static sqInt (*primitiveFailFor)(sqInt reasonCode);
static sqInt (*pushInteger)(sqInt integerValue);
static sqInt (*stSizeOf)(sqInt oop);
static sqInt (*stackValue)(sqInt offset);
#else /* !defined(SQUEAK_BUILTIN_PLUGIN) */
Expand All @@ -80,15 +80,15 @@ extern sqInt isBytes(sqInt oop);
extern sqInt isWords(sqInt oop);
extern sqInt methodArgumentCount(void);
extern sqInt methodReturnBool(sqInt boolean);
extern sqInt pop(sqInt nItems);
extern sqInt methodReturnInteger(sqInt integer);
extern sqInt methodReturnReceiver(void);
extern sqInt primitiveFailFor(sqInt reasonCode);
extern sqInt pushInteger(sqInt integerValue);
extern sqInt stSizeOf(sqInt oop);
extern sqInt stackValue(sqInt offset);
extern
#endif
struct VirtualMachine* interpreterProxy;
static const char *moduleName = "DSAPrims * CryptographyPlugins-eem.23 " INT_EXT;
static const char *moduleName = "DSAPrims CryptographyPlugins-eem.27 " INT_EXT;
static sqInt remainderDigitCount;


Expand Down Expand Up @@ -398,7 +398,7 @@ primitiveBigDivide(void)
}
dsaQuotient[digitShift + 1] = q;
}
pop(3);
methodReturnReceiver();
return 0;
}

Expand Down Expand Up @@ -466,7 +466,7 @@ primitiveBigMultiply(void)
prodPtr[k] = carry;
}
}
pop(3);
methodReturnReceiver();
return 0;
}

Expand Down Expand Up @@ -514,7 +514,7 @@ primitiveExpandBlock(void)
v = ((unsigned int) ((((usqInt)((((unsigned int) v))) << 1)) | (((usqInt)((((unsigned int) v)))) >> (0x1F))));
wordPtr[i] = v;
}
pop(2);
methodReturnReceiver();
return 0;
}

Expand Down Expand Up @@ -598,7 +598,7 @@ primitiveHashBlock(void)
statePtr[2] = ((statePtr[2]) + c);
statePtr[3] = ((statePtr[3]) + d);
statePtr[4] = ((statePtr[4]) + e);
pop(2);
methodReturnReceiver();
return 0;
}

Expand Down Expand Up @@ -638,8 +638,7 @@ primitiveHighestNonZeroDigitIndex(void)
while ((i > 0)
&& ((bigIntPtr[(i -= 1)]) == 0)) {
}
pop(1);
pushInteger(i + 1);
methodReturnInteger(i + 1);
return 0;
}

Expand Down Expand Up @@ -668,9 +667,9 @@ setInterpreter(struct VirtualMachine *anInterpreter)
isWords = interpreterProxy->isWords;
methodArgumentCount = interpreterProxy->methodArgumentCount;
methodReturnBool = interpreterProxy->methodReturnBool;
pop = interpreterProxy->pop;
methodReturnInteger = interpreterProxy->methodReturnInteger;
methodReturnReceiver = interpreterProxy->methodReturnReceiver;
primitiveFailFor = interpreterProxy->primitiveFailFor;
pushInteger = interpreterProxy->pushInteger;
stSizeOf = interpreterProxy->stSizeOf;
stackValue = interpreterProxy->stackValue;
#endif /* !defined(SQUEAK_BUILTIN_PLUGIN) */
Expand Down
30 changes: 14 additions & 16 deletions src/plugins/MD5Plugin/MD5Plugin.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* Automatically generated by
VMPluginCodeGenerator VMMaker.oscog-eem.3090 uuid: 3e2b8343-01bb-4169-ba4c-aecf82b4dcfc
VMPluginCodeGenerator VMMaker.oscog-eem.3119 uuid: c0b40a55-50ca-4dd9-8b6f-d355a6dd5e1f
from
MD5Plugin * CryptographyPlugins-eem.23 uuid: bc8a8db4-2e4d-458f-bac9-f007458fdd4d
MD5Plugin CryptographyPlugins-eem.27 uuid: 63bc0f04-a4d3-4347-84fc-20b64ea64093
*/
static char __buildInfo[] = "MD5Plugin * CryptographyPlugins-eem.23 uuid: bc8a8db4-2e4d-458f-bac9-f007458fdd4d " __DATE__ ;
static char __buildInfo[] = "MD5Plugin CryptographyPlugins-eem.27 uuid: 63bc0f04-a4d3-4347-84fc-20b64ea64093 " __DATE__ ;


#include "config.h"
Expand Down Expand Up @@ -60,7 +60,7 @@ static sqInt (*methodReturnBool)(sqInt boolean);
static sqInt (*methodReturnReceiver)(void);
static sqInt (*primitiveFailFor)(sqInt reasonCode);
static sqInt (*stSizeOf)(sqInt oop);
static sqInt (*stackObjectValue)(sqInt offset);
static sqInt (*stackValue)(sqInt offset);
#else /* !defined(SQUEAK_BUILTIN_PLUGIN) */
extern void * firstIndexableField(sqInt oop);
extern sqInt isBytes(sqInt oop);
Expand All @@ -69,11 +69,11 @@ extern sqInt methodReturnBool(sqInt boolean);
extern sqInt methodReturnReceiver(void);
extern sqInt primitiveFailFor(sqInt reasonCode);
extern sqInt stSizeOf(sqInt oop);
extern sqInt stackObjectValue(sqInt offset);
extern sqInt stackValue(sqInt offset);
extern
#endif
struct VirtualMachine* interpreterProxy;
static const char *moduleName = "MD5Plugin * CryptographyPlugins-eem.23 " INT_EXT;
static const char *moduleName = "MD5Plugin CryptographyPlugins-eem.27 " INT_EXT;



Expand All @@ -100,7 +100,7 @@ primitiveDecodeState(void)
if (!((methodArgumentCount()) == 1)) {
return primitiveFailFor(PrimErrBadNumArgs);
}
bytesOop = stackObjectValue(0);
bytesOop = stackValue(0);
if (!((isBytes(bytesOop))
&& ((stSizeOf(bytesOop)) == 16))) {
return primitiveFailFor(PrimErrBadArgument);
Expand All @@ -126,7 +126,7 @@ primitiveInitializeState(void)
if (!((methodArgumentCount()) == 1)) {
return primitiveFailFor(PrimErrBadNumArgs);
}
bytesOop = stackObjectValue(0);
bytesOop = stackValue(0);
if (!((isBytes(bytesOop))
&& ((stSizeOf(bytesOop)) == 16))) {
return primitiveFailFor(PrimErrBadArgument);
Expand Down Expand Up @@ -166,14 +166,12 @@ primitiveProcessBufferWithState(void)
if (!((methodArgumentCount()) == 2)) {
return primitiveFailFor(PrimErrBadNumArgs);
}
bufferOop = stackObjectValue(1);
bufferOop = stackValue(1);
stateOop = stackValue(0);
if (!((isBytes(bufferOop))
&& ((stSizeOf(bufferOop)) == 64))) {
return primitiveFailFor(PrimErrBadArgument);
}
stateOop = stackObjectValue(0);
if (!((isBytes(stateOop))
&& ((stSizeOf(stateOop)) == 16))) {
&& (((stSizeOf(bufferOop)) == 64)
&& ((isBytes(stateOop))
&& ((stSizeOf(stateOop)) == 16))))) {
return primitiveFailFor(PrimErrBadArgument);
}
/* begin md5ProcessBuffer:withState: */
Expand Down Expand Up @@ -350,7 +348,7 @@ setInterpreter(struct VirtualMachine *anInterpreter)
methodReturnReceiver = interpreterProxy->methodReturnReceiver;
primitiveFailFor = interpreterProxy->primitiveFailFor;
stSizeOf = interpreterProxy->stSizeOf;
stackObjectValue = interpreterProxy->stackObjectValue;
stackValue = interpreterProxy->stackValue;
#endif /* !defined(SQUEAK_BUILTIN_PLUGIN) */
}
return ok;
Expand Down
Loading

0 comments on commit 27d2d9f

Please sign in to comment.