Skip to content

Commit 27d2d9f

Browse files
committed
Cryptography Plugins as per CryptographyPlugins-mt.25/eem.27
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)
1 parent 97b4903 commit 27d2d9f

File tree

4 files changed

+116
-114
lines changed

4 files changed

+116
-114
lines changed

src/plugins/DESPlugin/DESPlugin.c

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* Automatically generated by
2-
VMPluginCodeGenerator VMMaker.oscog-eem.3090 uuid: 3e2b8343-01bb-4169-ba4c-aecf82b4dcfc
2+
VMPluginCodeGenerator VMMaker.oscog-eem.3119 uuid: c0b40a55-50ca-4dd9-8b6f-d355a6dd5e1f
33
from
4-
DESPlugin * CryptographyPlugins-eem.23 uuid: bc8a8db4-2e4d-458f-bac9-f007458fdd4d
4+
DESPlugin CryptographyPlugins-eem.27 uuid: 63bc0f04-a4d3-4347-84fc-20b64ea64093
55
*/
6-
static char __buildInfo[] = "DESPlugin * CryptographyPlugins-eem.23 uuid: bc8a8db4-2e4d-458f-bac9-f007458fdd4d " __DATE__ ;
6+
static char __buildInfo[] = "DESPlugin CryptographyPlugins-eem.27 uuid: 63bc0f04-a4d3-4347-84fc-20b64ea64093 " __DATE__ ;
77

88

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

5959
#if !defined(SQUEAK_BUILTIN_PLUGIN)
6060
static void * (*firstIndexableField)(sqInt oop);
61+
#if !defined(integerValueOf)
62+
static sqInt (*integerValueOf)(sqInt oop);
63+
#endif
6164
static sqInt (*isBytes)(sqInt oop);
65+
#if !defined(isIntegerObject)
66+
static sqInt (*isIntegerObject)(sqInt objectPointer);
67+
#endif
6268
static sqInt (*isWords)(sqInt oop);
6369
static sqInt (*methodArgumentCount)(void);
6470
static sqInt (*methodReturnBool)(sqInt boolean);
65-
static sqInt (*pop)(sqInt nItems);
71+
static sqInt (*methodReturnReceiver)(void);
6672
static sqInt (*primitiveFailFor)(sqInt reasonCode);
6773
static sqInt (*stSizeOf)(sqInt oop);
68-
static sqInt (*stackIntegerValue)(sqInt offset);
6974
static sqInt (*stackValue)(sqInt offset);
7075
#else /* !defined(SQUEAK_BUILTIN_PLUGIN) */
7176
extern void * firstIndexableField(sqInt oop);
77+
#if !defined(integerValueOf)
78+
extern sqInt integerValueOf(sqInt oop);
79+
#endif
7280
extern sqInt isBytes(sqInt oop);
81+
#if !defined(isIntegerObject)
82+
extern sqInt isIntegerObject(sqInt objectPointer);
83+
#endif
7384
extern sqInt isWords(sqInt oop);
7485
extern sqInt methodArgumentCount(void);
7586
extern sqInt methodReturnBool(sqInt boolean);
76-
extern sqInt pop(sqInt nItems);
87+
extern sqInt methodReturnReceiver(void);
7788
extern sqInt primitiveFailFor(sqInt reasonCode);
7889
extern sqInt stSizeOf(sqInt oop);
79-
extern sqInt stackIntegerValue(sqInt offset);
8090
extern sqInt stackValue(sqInt offset);
8191
extern
8292
#endif
8393
struct VirtualMachine* interpreterProxy;
84-
static const char *moduleName = "DESPlugin * CryptographyPlugins-eem.23 " INT_EXT;
94+
static const char *moduleName = "DESPlugin CryptographyPlugins-eem.27 " INT_EXT;
8595
static unsigned char pc1[56] = {
8696
56, 48, 40, 32, 24, 16, 8, 0, 57, 49, 41, 33, 25, 17,
8797
9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35,
@@ -376,18 +386,17 @@ primitiveDESCookKey(void)
376386
return primitiveFailFor(PrimErrBadNumArgs);
377387
}
378388
rawOop = stackValue(2);
379-
if (!((isBytes(rawOop))
380-
&& ((stSizeOf(rawOop)) == 8))) {
381-
return primitiveFailFor(PrimErrBadArgument);
382-
}
383-
encode = stackIntegerValue(1);
389+
encode = stackValue(1);
384390
cookedOop = stackValue(0);
385-
if (!((isWords(cookedOop))
386-
&& ((stSizeOf(cookedOop)) == 32))) {
391+
if (!((isBytes(rawOop))
392+
&& (((stSizeOf(rawOop)) == 8)
393+
&& ((isIntegerObject(encode))
394+
&& ((isWords(cookedOop))
395+
&& ((stSizeOf(cookedOop)) == 32)))))) {
387396
return primitiveFailFor(PrimErrBadArgument);
388397
}
389-
processKeymodeto(firstIndexableField(rawOop), encode != 0, firstIndexableField(cookedOop));
390-
pop(3);
398+
processKeymodeto(firstIndexableField(rawOop), (integerValueOf(encode)) != 0, firstIndexableField(cookedOop));
399+
methodReturnReceiver();
391400
return 0;
392401
}
393402

@@ -425,13 +434,11 @@ primitiveDESTransform(void)
425434
return primitiveFailFor(PrimErrBadNumArgs);
426435
}
427436
dataOop = stackValue(1);
428-
if (!((isBytes(dataOop))
429-
&& ((stSizeOf(dataOop)) == 8))) {
430-
return primitiveFailFor(PrimErrBadArgument);
431-
}
432437
cookedOop = stackValue(0);
433-
if (!((isWords(cookedOop))
434-
&& ((stSizeOf(cookedOop)) == 32))) {
438+
if (!((isBytes(dataOop))
439+
&& (((stSizeOf(dataOop)) == 8)
440+
&& ((isWords(cookedOop))
441+
&& ((stSizeOf(cookedOop)) == 32))))) {
435442
return primitiveFailFor(PrimErrBadArgument);
436443
}
437444
data = firstIndexableField(dataOop);
@@ -517,7 +524,7 @@ primitiveDESTransform(void)
517524
data[5] = ((((usqInt)((work[1]))) >> 16) & 0xFF);
518525
data[6] = ((((usqInt)((work[1]))) >> 8) & 0xFF);
519526
data[7] = ((work[1]) & 0xFF);
520-
pop(2);
527+
methodReturnReceiver();
521528
return 0;
522529
}
523530

@@ -631,14 +638,19 @@ setInterpreter(struct VirtualMachine *anInterpreter)
631638

632639
#if !defined(SQUEAK_BUILTIN_PLUGIN)
633640
firstIndexableField = interpreterProxy->firstIndexableField;
641+
#if !defined(integerValueOf)
642+
integerValueOf = interpreterProxy->integerValueOf;
643+
#endif
634644
isBytes = interpreterProxy->isBytes;
645+
#if !defined(isIntegerObject)
646+
isIntegerObject = interpreterProxy->isIntegerObject;
647+
#endif
635648
isWords = interpreterProxy->isWords;
636649
methodArgumentCount = interpreterProxy->methodArgumentCount;
637650
methodReturnBool = interpreterProxy->methodReturnBool;
638-
pop = interpreterProxy->pop;
651+
methodReturnReceiver = interpreterProxy->methodReturnReceiver;
639652
primitiveFailFor = interpreterProxy->primitiveFailFor;
640653
stSizeOf = interpreterProxy->stSizeOf;
641-
stackIntegerValue = interpreterProxy->stackIntegerValue;
642654
stackValue = interpreterProxy->stackValue;
643655
#endif /* !defined(SQUEAK_BUILTIN_PLUGIN) */
644656
}
@@ -666,7 +678,7 @@ unscrunchto(unsigned int *wordPtr, unsigned char *bytePtr)
666678
static char _m[] = "DESPlugin";
667679
void* DESPlugin_exports[][3] = {
668680
{(void*)_m, "getModuleName", (void*)getModuleName},
669-
{(void*)_m, "primitiveDESCookKey\000\001\001", (void*)primitiveDESCookKey},
681+
{(void*)_m, "primitiveDESCookKey\000\001\003", (void*)primitiveDESCookKey},
670682
{(void*)_m, "primitiveDESPluginAvailable\000\377\001", (void*)primitiveDESPluginAvailable},
671683
{(void*)_m, "primitiveDESTransform\000\001\001", (void*)primitiveDESTransform},
672684
{(void*)_m, "setInterpreter", (void*)setInterpreter},
@@ -676,7 +688,7 @@ void* DESPlugin_exports[][3] = {
676688
#else // ifdef SQ_BUILTIN_PLUGIN
677689

678690
#if SPURVM
679-
EXPORT(signed short) primitiveDESCookKeyMetadata = 0x101;
691+
EXPORT(signed short) primitiveDESCookKeyMetadata = 259;
680692
EXPORT(signed short) primitiveDESPluginAvailableMetadata = -255;
681693
EXPORT(signed short) primitiveDESTransformMetadata = 0x101;
682694
#endif // SPURVM

src/plugins/DSAPrims/DSAPrims.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* Automatically generated by
2-
VMPluginCodeGenerator VMMaker.oscog-eem.3090 uuid: 3e2b8343-01bb-4169-ba4c-aecf82b4dcfc
2+
VMPluginCodeGenerator VMMaker.oscog-eem.3119 uuid: c0b40a55-50ca-4dd9-8b6f-d355a6dd5e1f
33
from
4-
DSAPlugin * CryptographyPlugins-eem.23 uuid: bc8a8db4-2e4d-458f-bac9-f007458fdd4d
4+
DSAPlugin CryptographyPlugins-eem.27 uuid: 63bc0f04-a4d3-4347-84fc-20b64ea64093
55
*/
6-
static char __buildInfo[] = "DSAPlugin * CryptographyPlugins-eem.23 uuid: bc8a8db4-2e4d-458f-bac9-f007458fdd4d " __DATE__ ;
6+
static char __buildInfo[] = "DSAPlugin CryptographyPlugins-eem.27 uuid: 63bc0f04-a4d3-4347-84fc-20b64ea64093 " __DATE__ ;
77

88

99
#include "config.h"
@@ -67,9 +67,9 @@ static sqInt (*isBytes)(sqInt oop);
6767
static sqInt (*isWords)(sqInt oop);
6868
static sqInt (*methodArgumentCount)(void);
6969
static sqInt (*methodReturnBool)(sqInt boolean);
70-
static sqInt (*pop)(sqInt nItems);
70+
static sqInt (*methodReturnInteger)(sqInt integer);
71+
static sqInt (*methodReturnReceiver)(void);
7172
static sqInt (*primitiveFailFor)(sqInt reasonCode);
72-
static sqInt (*pushInteger)(sqInt integerValue);
7373
static sqInt (*stSizeOf)(sqInt oop);
7474
static sqInt (*stackValue)(sqInt offset);
7575
#else /* !defined(SQUEAK_BUILTIN_PLUGIN) */
@@ -80,15 +80,15 @@ extern sqInt isBytes(sqInt oop);
8080
extern sqInt isWords(sqInt oop);
8181
extern sqInt methodArgumentCount(void);
8282
extern sqInt methodReturnBool(sqInt boolean);
83-
extern sqInt pop(sqInt nItems);
83+
extern sqInt methodReturnInteger(sqInt integer);
84+
extern sqInt methodReturnReceiver(void);
8485
extern sqInt primitiveFailFor(sqInt reasonCode);
85-
extern sqInt pushInteger(sqInt integerValue);
8686
extern sqInt stSizeOf(sqInt oop);
8787
extern sqInt stackValue(sqInt offset);
8888
extern
8989
#endif
9090
struct VirtualMachine* interpreterProxy;
91-
static const char *moduleName = "DSAPrims * CryptographyPlugins-eem.23 " INT_EXT;
91+
static const char *moduleName = "DSAPrims CryptographyPlugins-eem.27 " INT_EXT;
9292
static sqInt remainderDigitCount;
9393

9494

@@ -398,7 +398,7 @@ primitiveBigDivide(void)
398398
}
399399
dsaQuotient[digitShift + 1] = q;
400400
}
401-
pop(3);
401+
methodReturnReceiver();
402402
return 0;
403403
}
404404

@@ -466,7 +466,7 @@ primitiveBigMultiply(void)
466466
prodPtr[k] = carry;
467467
}
468468
}
469-
pop(3);
469+
methodReturnReceiver();
470470
return 0;
471471
}
472472

@@ -514,7 +514,7 @@ primitiveExpandBlock(void)
514514
v = ((unsigned int) ((((usqInt)((((unsigned int) v))) << 1)) | (((usqInt)((((unsigned int) v)))) >> (0x1F))));
515515
wordPtr[i] = v;
516516
}
517-
pop(2);
517+
methodReturnReceiver();
518518
return 0;
519519
}
520520

@@ -598,7 +598,7 @@ primitiveHashBlock(void)
598598
statePtr[2] = ((statePtr[2]) + c);
599599
statePtr[3] = ((statePtr[3]) + d);
600600
statePtr[4] = ((statePtr[4]) + e);
601-
pop(2);
601+
methodReturnReceiver();
602602
return 0;
603603
}
604604

@@ -638,8 +638,7 @@ primitiveHighestNonZeroDigitIndex(void)
638638
while ((i > 0)
639639
&& ((bigIntPtr[(i -= 1)]) == 0)) {
640640
}
641-
pop(1);
642-
pushInteger(i + 1);
641+
methodReturnInteger(i + 1);
643642
return 0;
644643
}
645644

@@ -668,9 +667,9 @@ setInterpreter(struct VirtualMachine *anInterpreter)
668667
isWords = interpreterProxy->isWords;
669668
methodArgumentCount = interpreterProxy->methodArgumentCount;
670669
methodReturnBool = interpreterProxy->methodReturnBool;
671-
pop = interpreterProxy->pop;
670+
methodReturnInteger = interpreterProxy->methodReturnInteger;
671+
methodReturnReceiver = interpreterProxy->methodReturnReceiver;
672672
primitiveFailFor = interpreterProxy->primitiveFailFor;
673-
pushInteger = interpreterProxy->pushInteger;
674673
stSizeOf = interpreterProxy->stSizeOf;
675674
stackValue = interpreterProxy->stackValue;
676675
#endif /* !defined(SQUEAK_BUILTIN_PLUGIN) */

src/plugins/MD5Plugin/MD5Plugin.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* Automatically generated by
2-
VMPluginCodeGenerator VMMaker.oscog-eem.3090 uuid: 3e2b8343-01bb-4169-ba4c-aecf82b4dcfc
2+
VMPluginCodeGenerator VMMaker.oscog-eem.3119 uuid: c0b40a55-50ca-4dd9-8b6f-d355a6dd5e1f
33
from
4-
MD5Plugin * CryptographyPlugins-eem.23 uuid: bc8a8db4-2e4d-458f-bac9-f007458fdd4d
4+
MD5Plugin CryptographyPlugins-eem.27 uuid: 63bc0f04-a4d3-4347-84fc-20b64ea64093
55
*/
6-
static char __buildInfo[] = "MD5Plugin * CryptographyPlugins-eem.23 uuid: bc8a8db4-2e4d-458f-bac9-f007458fdd4d " __DATE__ ;
6+
static char __buildInfo[] = "MD5Plugin CryptographyPlugins-eem.27 uuid: 63bc0f04-a4d3-4347-84fc-20b64ea64093 " __DATE__ ;
77

88

99
#include "config.h"
@@ -60,7 +60,7 @@ static sqInt (*methodReturnBool)(sqInt boolean);
6060
static sqInt (*methodReturnReceiver)(void);
6161
static sqInt (*primitiveFailFor)(sqInt reasonCode);
6262
static sqInt (*stSizeOf)(sqInt oop);
63-
static sqInt (*stackObjectValue)(sqInt offset);
63+
static sqInt (*stackValue)(sqInt offset);
6464
#else /* !defined(SQUEAK_BUILTIN_PLUGIN) */
6565
extern void * firstIndexableField(sqInt oop);
6666
extern sqInt isBytes(sqInt oop);
@@ -69,11 +69,11 @@ extern sqInt methodReturnBool(sqInt boolean);
6969
extern sqInt methodReturnReceiver(void);
7070
extern sqInt primitiveFailFor(sqInt reasonCode);
7171
extern sqInt stSizeOf(sqInt oop);
72-
extern sqInt stackObjectValue(sqInt offset);
72+
extern sqInt stackValue(sqInt offset);
7373
extern
7474
#endif
7575
struct VirtualMachine* interpreterProxy;
76-
static const char *moduleName = "MD5Plugin * CryptographyPlugins-eem.23 " INT_EXT;
76+
static const char *moduleName = "MD5Plugin CryptographyPlugins-eem.27 " INT_EXT;
7777

7878

7979

@@ -100,7 +100,7 @@ primitiveDecodeState(void)
100100
if (!((methodArgumentCount()) == 1)) {
101101
return primitiveFailFor(PrimErrBadNumArgs);
102102
}
103-
bytesOop = stackObjectValue(0);
103+
bytesOop = stackValue(0);
104104
if (!((isBytes(bytesOop))
105105
&& ((stSizeOf(bytesOop)) == 16))) {
106106
return primitiveFailFor(PrimErrBadArgument);
@@ -126,7 +126,7 @@ primitiveInitializeState(void)
126126
if (!((methodArgumentCount()) == 1)) {
127127
return primitiveFailFor(PrimErrBadNumArgs);
128128
}
129-
bytesOop = stackObjectValue(0);
129+
bytesOop = stackValue(0);
130130
if (!((isBytes(bytesOop))
131131
&& ((stSizeOf(bytesOop)) == 16))) {
132132
return primitiveFailFor(PrimErrBadArgument);
@@ -166,14 +166,12 @@ primitiveProcessBufferWithState(void)
166166
if (!((methodArgumentCount()) == 2)) {
167167
return primitiveFailFor(PrimErrBadNumArgs);
168168
}
169-
bufferOop = stackObjectValue(1);
169+
bufferOop = stackValue(1);
170+
stateOop = stackValue(0);
170171
if (!((isBytes(bufferOop))
171-
&& ((stSizeOf(bufferOop)) == 64))) {
172-
return primitiveFailFor(PrimErrBadArgument);
173-
}
174-
stateOop = stackObjectValue(0);
175-
if (!((isBytes(stateOop))
176-
&& ((stSizeOf(stateOop)) == 16))) {
172+
&& (((stSizeOf(bufferOop)) == 64)
173+
&& ((isBytes(stateOop))
174+
&& ((stSizeOf(stateOop)) == 16))))) {
177175
return primitiveFailFor(PrimErrBadArgument);
178176
}
179177
/* begin md5ProcessBuffer:withState: */
@@ -350,7 +348,7 @@ setInterpreter(struct VirtualMachine *anInterpreter)
350348
methodReturnReceiver = interpreterProxy->methodReturnReceiver;
351349
primitiveFailFor = interpreterProxy->primitiveFailFor;
352350
stSizeOf = interpreterProxy->stSizeOf;
353-
stackObjectValue = interpreterProxy->stackObjectValue;
351+
stackValue = interpreterProxy->stackValue;
354352
#endif /* !defined(SQUEAK_BUILTIN_PLUGIN) */
355353
}
356354
return ok;

0 commit comments

Comments
 (0)