1 ###################################-
3 # Copyright 2009, 2010, 2011 Free Software Foundation, Inc.
5 # Contributed by Michael Eager <eager@eagercon.com>.
7 # This file is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the
9 # Free Software Foundation; either version 3, or (at your option) any
12 # GCC is distributed in the hope that it will be useful, but WITHOUT
13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 # License for more details.
17 # Under Section 7 of GPL version 3, you are granted additional
18 # permissions described in the GCC Runtime Library Exception, version
19 # 3.1, as published by the Free Software Foundation.
21 # You should have received a copy of the GNU General Public License and
22 # a copy of the GCC Runtime Library Exception along with this program;
23 # see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 # <http://www.gnu.org/licenses/>.
28 # Multiply operation for 64 bit integers, for devices with hard multiply
29 # Input : Operand1[H] in Reg r5
30 # Operand1[L] in Reg r6
31 # Operand2[H] in Reg r7
32 # Operand2[L] in Reg r8
33 # Output: Result[H] in Reg r3
38 # Both the input numbers are divided into 16 bit number as follows
42 # + (C * H + D * G) << 16
43 # + (B * H + C * G + D * F) << 32
44 # + (A * H + B * G + C * F + D * E) << 48
46 # Only 64 bits of the output are considered
48 #######################################
50 .globl muldi3_hardproc
55 # Save the input operands on the caller's stack
61 # Store all the callee saved registers
71 # Load all the 16 bit values for A through H
81 # D * H ==> LSB of the result on stack ==> Store1
83 swi r9,r1,36 # Pos2 and Pos3
85 # Hi (Store1) + C * H + D * G ==> Store2 ==> Pos1 and Pos2
86 # Store the carry generated in position 2 for Pos 3
88 mul r9,r22,r27 # C * H
89 mul r10,r23,r26 # D * G
93 addc r12,r12,r0 # Store the Carry
94 shi r9,r1,36 # Store Pos2
97 shi r11,r1,34 # Store Pos1
99 # Hi (Store2) + B * H + C * G + D * F ==> Store3 ==> Pos0 and Pos1
100 mul r9,r21,r27 # B * H
101 mul r10,r22,r26 # C * G
102 mul r7,r23,r25 # D * F
106 swi r9,r1,32 # Pos0 and Pos1
108 # Hi (Store3) + A * H + B * G + C * F + D * E ==> Store3 ==> Pos0
109 lhui r11,r1,32 # Pos0
110 mul r9,r20,r27 # A * H
111 mul r10,r21,r26 # B * G
112 mul r7,r22,r25 # C * F
113 mul r8,r23,r24 # D * E
118 sext16 r9,r9 # Sign extend the MSB
121 # Move results to r3 and r4
125 lwi r3,r1,32 # Hi Part
126 lwi r4,r1,36 # Lo Part
128 # Restore Callee saved registers
138 # Restore Frame and return