|
From: Conrad W. <we...@on...> - 2003-01-05 15:07:08
|
>A quick fix is to not make the byte swap function inline, but that is
>obviously less efficient and not what I think is wanted. A Bit more
>assembly magic is required.
Here is an option that seems to produce a lot more efficient code.
However, I am an old 68k programmer, my ppc knowlegde is not very good so
mr Andy Green should probably verify this!
1. New macro for MD5STEP1 when BigEndian
#if ZCONFIG(Endian, Big)
# define MD5STEP1(f, w, x, y, z, i, c, s) \
inValueAddress = iData + i; \
asm { lwbrx swapResult, r0, inValueAddress }; \
localData[i] = swapResult; \
w += f(x, y, z) + c + localData[i]; \
w = w<<s | w>>(32-s); \
w += x
Notice the byte swap is now in the macro and expecting 2 predifined
registers global to the "calling" function: inValueAddress and swapResult.
2. Add two new locals to sMD5_Transform
static void sMD5_Transform(uint32 ioState[4], const uint32 iData[16])
{
uint32 a = ioState[0];
uint32 b = ioState[1];
uint32 c = ioState[2];
uint32 d = ioState[3];
register const void* inValueAddress;
register int32 swapResult;
..........
Here is a dump of the code produced by the new macro:
MD5STEP1(F1, a, b, c, d, 0, 0xd76aa478, 7);
0000001C: 7F1EC378 mr r30,r24
00000020: 7FE0F42C lwbrx r31,r0,r30
00000024: 93E1FFA0 stw r31,-96(SP)
00000028: 8081FFA0 lwz r4,-96(SP)
0000002C: 7F80EA78 xor r0,r28,r29
00000030: 7F600038 and r0,r27,r0
00000034: 7FA30278 xor r3,r29,r0
00000038: 3C03D76B subis r0,r3,10389
0000003C: 7C002214 add r0,r0,r4
00000040: 7F40D214 add r26,r0,r26
00000044: 3B5AA478 subi r26,r26,23432
00000048: 57433830 slwi r3,r26,7
0000004C: 57403E7E srwi r0,r26,25
00000050: 7C7A0378 or r26,r3,r0
00000054: 7F5ADA14 add r26,r26,r27
MD5STEP1(F1, d, a, b, c, 1, 0xe8c7b756, 12);
00000058: 3BD80004 addi r30,r24,4
0000005C: 7FE0F42C lwbrx r31,r0,r30
00000060: 93E1FFA4 stw r31,-92(SP)
00000064: 8081FFA4 lwz r4,-92(SP)
And here is a dump of the code produced by the old macro:
MD5STEP1(F1, a, b, c, d, 0, 0xd76aa478, 7);
0000003C: 8201001C lwz r16,28(SP)
00000040: 7E20842C lwbrx r17,r0,r16
00000044: 9221FF60 stw r17,-160(SP)
00000048: 80C1FF50 lwz r6,-176(SP)
0000004C: 80A1FF5C lwz r5,-164(SP)
00000050: 8081FF54 lwz r4,-172(SP)
00000054: 8061FF58 lwz r3,-168(SP)
00000058: 8001FF5C lwz r0,-164(SP)
0000005C: 7C600278 xor r0,r3,r0
00000060: 7C800038 and r0,r4,r0
00000064: 7CA30278 xor r3,r5,r0
00000068: 3C63D76B subis r3,r3,10389
0000006C: 8001FF60 lwz r0,-160(SP)
00000070: 9001FF80 stw r0,-128(SP)
00000074: 7C030214 add r0,r3,r0
00000078: 7C603214 add r3,r0,r6
0000007C: 3803A478 subi r0,r3,23432
00000080: 9001FF50 stw r0,-176(SP)
00000084: 8001FF50 lwz r0,-176(SP)
00000088: 54033830 slwi r3,r0,7
0000008C: 8001FF50 lwz r0,-176(SP)
00000090: 54003E7E srwi r0,r0,25
00000094: 7C600378 or r0,r3,r0
00000098: 9001FF50 stw r0,-176(SP)
0000009C: 8061FF50 lwz r3,-176(SP)
000000A0: 8001FF54 lwz r0,-172(SP)
000000A4: 7C030214 add r0,r3,r0
000000A8: 9001FF50 stw r0,-176(SP)
MD5STEP1(F1, d, a, b, c, 1, 0xe8c7b756, 12);
000000AC: 8061001C lwz r3,28(SP)
000000B0: 3A430004 addi r18,r3,4
000000B4: 7E60942C lwbrx r19,r0,r18
000000B8: 9261FF64 stw r19,-156(SP)
000000BC: 80C1FF5C lwz r6,-164(SP)
000000C0: 80A1FF58 lwz r5,-168(SP)
000000C4: 8081FF50 lwz r4,-176(SP)
000000C8: 8061FF54 lwz r3,-172(SP)
000000CC: 8001FF58 lwz r0,-168(SP)
/Conrad
>
>Cheers,
>Conrad Weyns.
>
>
>
>>
>>When I try to compile it while running on OS 9.2, CodeWarrior complains
>>that it
>>doesn't have enough registers to compile. If I try to compile it while
>>running
>>OS X, CodeWarrior unexpectedly quits.
>>
>>I need a hash for something that I'm doing, but happily there is also
>>ZStream_SHA1.cpp, which should work fine for me.
>>
>>Mike
>>--
>>Michael D. Crawford
>>GoingWare Inc. - Expert Software Development and Consulting
>>http://www.goingware.com/
>>cra...@go...
>>
>> Tilting at Windmills for a Better Tomorrow.
>>
>>
>>
>>-------------------------------------------------------
>>This sf.net email is sponsored by:ThinkGeek
>>Welcome to geek heaven.
>>http://thinkgeek.com/sf
>>_______________________________________________
>>ZooLib-dev mailing list
>>Zoo...@li...
>>https://lists.sourceforge.net/lists/listinfo/zoolib-dev
>>
>>
>
>
>
>
>-------------------------------------------------------
>This sf.net email is sponsored by:ThinkGeek
>Welcome to geek heaven.
>http://thinkgeek.com/sf
>_______________________________________________
>ZooLib-dev mailing list
>Zoo...@li...
>https://lists.sourceforge.net/lists/listinfo/zoolib-dev
>
>
|