Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: runtime/vm/intrinsifier_ia32.cc

Issue 582963003: Intrinsify Bigint 'multiply and accumulate" function on ia32. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 // 4 //
5 // The intrinsic code below is executed before a method has built its frame. 5 // The intrinsic code below is executed before a method has built its frame.
6 // The return address is on the stack and the arguments below it. 6 // The return address is on the stack and the arguments below it.
7 // Registers EDX (arguments descriptor) and ECX (function) must be preserved. 7 // Registers EDX (arguments descriptor) and ECX (function) must be preserved.
8 // Each intrinsification method returns true if the corresponding 8 // Each intrinsification method returns true if the corresponding
9 // Dart method was intrinsified. 9 // Dart method was intrinsified.
10 10
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 905
906 void Intrinsifier::Bigint_setDigits(Assembler* assembler) { 906 void Intrinsifier::Bigint_setDigits(Assembler* assembler) {
907 __ movl(EAX, Address(ESP, + 1 * kWordSize)); 907 __ movl(EAX, Address(ESP, + 1 * kWordSize));
908 __ movl(ECX, Address(ESP, + 2 * kWordSize)); 908 __ movl(ECX, Address(ESP, + 2 * kWordSize));
909 __ StoreIntoObject(ECX, 909 __ StoreIntoObject(ECX,
910 FieldAddress(ECX, Bigint::digits_offset()), EAX, false); 910 FieldAddress(ECX, Bigint::digits_offset()), EAX, false);
911 __ ret(); 911 __ ret();
912 } 912 }
913 913
914 914
915 void Intrinsifier::Bigint_mulAdd(Assembler* assembler) {
srdjan 2014/09/19 00:26:08 Please test with --no-intrinsify, otherwise the da
regis 2014/09/19 02:01:34 Added // TODO(regis): Once this intrinsic is imple
916 // Pseudo code:
917 // static void _mulAdd(Uint32List args,
918 // Uint32List m_digits, int i,
919 // Uint32List a_digits, int j, int n) {
920 // uint32_t x = args[MA_MULTIPLIER];
921 // if (x == 0) {
922 // args[MA_CARRY_OUT] = 0;
923 // return;
924 // }
925 // uint32_t* mip = &m_digits[i >> 1]; // i is Smi.
926 // uint32_t* ajp = &a_digits[j >> 1]; // j is Smi.
927 // uint32_t c = 0;
928 // while ((n -= 2) >= 0) { // n is Smi.
929 // uint32_t mi = *mip++;
930 // uint32_t aj = *ajp;
931 // uint64_t t = x*mi + aj + c; // 32-bit * 32-bit -> 64-bit.
932 // *ajp++ = low32(t);
933 // c = high32(t);
934 // }
935 // args[MA_CARRY_OUT] = c;
936 // }
937
938 // EBX = x
939 Label x_not_zero;
940 __ movl(ECX, Address(ESP, 6 * kWordSize)); // args
941 __ movl(EBX, FieldAddress(ECX, TypedData::data_offset())); // x
942 __ cmpl(EBX, Immediate(0));
943 __ j(NOT_EQUAL, &x_not_zero, Assembler::kNearJump);
944 // Set args[MA_CARRY_OUT] to 0 and return.
945 __ movl(FieldAddress(ECX, TypedData::data_offset() + kWordSize), EBX);
946 __ ret();
947 __ Bind(&x_not_zero);
948
949 // Preserve CTX to free ESI.
950 __ pushl(CTX);
951 ASSERT(CTX == ESI);
952
953 // EDI = mip = &m_digits[i >> 1]
954 __ movl(EDI, Address(ESP, 6 * kWordSize)); // m_digits
955 __ movl(EAX, Address(ESP, 5 * kWordSize)); // i is Smi
956 __ leal(EDI, FieldAddress(EDI, EAX, TIMES_2, TypedData::data_offset()));
957
958 // ESI = ajp = &a_digits[j >> 1]
959 __ movl(ESI, Address(ESP, 4 * kWordSize)); // a_digits
960 __ movl(EAX, Address(ESP, 3 * kWordSize)); // j is Smi
961 __ leal(ESI, FieldAddress(ESI, EAX, TIMES_2, TypedData::data_offset()));
962
963 // ECX = c = 0
964 __ xorl(ECX, ECX);
965
966 Label loop, done;
967 __ Bind(&loop);
968 // x: EBX
969 // mip: EDI
970 // ajp: ESI
971 // c: ECX
972 // t: EDX:EAX (not live at loop entry)
973
974 // while ((n -= 2) >= 0), n is on stack, above ret addr and saved CTX.
975 __ movl(EAX, Immediate(2)); // 'sub mem32, imm32' not implemented.
976 __ subl(Address(ESP, 2 * kWordSize), EAX); // --n, n is Smi.
977 __ j(NEGATIVE, &done);
978
979 // uint32_t mi = *mip++
980 __ movl(EAX, Address(EDI, 0));
981 __ addl(EDI, Immediate(kWordSize));
982
983 // uint64_t t = x*mi
984 __ mull(EBX); // t = EDX:EAX = EAX * EBX
985 __ addl(EAX, ECX); // t += c
986 __ adcl(EDX, Immediate(0));
987
988 // uint32_t aj = *ajp; t += aj
989 __ addl(EAX, Address(ESI, 0));
990 __ adcl(EDX, Immediate(0));
991
992 // *ajp++ = low32(t)
993 __ movl(Address(ESI, 0), EAX);
994 __ addl(ESI, Immediate(kWordSize));
995
996 // c = high32(t)
997 __ movl(ECX, EDX);
998 __ jmp(&loop, Assembler::kNearJump);
999
1000 __ Bind(&done);
1001 // Restore CTX, set args[MA_CARRY_OUT] to c and return.
1002 __ popl(CTX);
1003 __ movl(EAX, Address(ESP, 6 * kWordSize)); // args
1004 __ movl(FieldAddress(EAX, TypedData::data_offset() + kWordSize), ECX);
srdjan 2014/09/19 00:26:08 Load EAX with null(), just in case (as suggested b
regis 2014/09/19 02:01:34 I have instead added a TODO to confirm that this i
1005 __ ret();
1006 }
1007
1008
915 // Check if the last argument is a double, jump to label 'is_smi' if smi 1009 // Check if the last argument is a double, jump to label 'is_smi' if smi
916 // (easy to convert to double), otherwise jump to label 'not_double_smi', 1010 // (easy to convert to double), otherwise jump to label 'not_double_smi',
917 // Returns the last argument in EAX. 1011 // Returns the last argument in EAX.
918 static void TestLastArgumentIsDouble(Assembler* assembler, 1012 static void TestLastArgumentIsDouble(Assembler* assembler,
919 Label* is_smi, 1013 Label* is_smi,
920 Label* not_double_smi) { 1014 Label* not_double_smi) {
921 __ movl(EAX, Address(ESP, + 1 * kWordSize)); 1015 __ movl(EAX, Address(ESP, + 1 * kWordSize));
922 __ testl(EAX, Immediate(kSmiTagMask)); 1016 __ testl(EAX, Immediate(kSmiTagMask));
923 __ j(ZERO, is_smi, Assembler::kNearJump); // Jump if Smi. 1017 __ j(ZERO, is_smi, Assembler::kNearJump); // Jump if Smi.
924 __ CompareClassId(EAX, kDoubleCid, EBX); 1018 __ CompareClassId(EAX, kDoubleCid, EBX);
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
1642 Isolate::current_tag_offset()); 1736 Isolate::current_tag_offset());
1643 // Set return value to Isolate::current_tag_. 1737 // Set return value to Isolate::current_tag_.
1644 __ movl(EAX, current_tag_addr); 1738 __ movl(EAX, current_tag_addr);
1645 __ ret(); 1739 __ ret();
1646 } 1740 }
1647 1741
1648 #undef __ 1742 #undef __
1649 } // namespace dart 1743 } // namespace dart
1650 1744
1651 #endif // defined TARGET_ARCH_IA32 1745 #endif // defined TARGET_ARCH_IA32
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698