1 ###################################-
3 # Copyright (C) 2009-2017 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 /* An executable stack is *not* required for these functions. */
52 .section .note.GNU-stack,"",%progbits
56 .globl muldi3_hardproc
61 # Save the input operands on the caller's stack
67 # Store all the callee saved registers
77 # Load all the 16 bit values for A through H
87 # D * H ==> LSB of the result on stack ==> Store1
89 swi r9,r1,36 # Pos2 and Pos3
91 # Hi (Store1) + C * H + D * G ==> Store2 ==> Pos1 and Pos2
92 # Store the carry generated in position 2 for Pos 3
94 mul r9,r22,r27 # C * H
95 mul r10,r23,r26 # D * G
99 addc r12,r12,r0 # Store the Carry
100 shi r9,r1,36 # Store Pos2
103 shi r11,r1,34 # Store Pos1
105 # Hi (Store2) + B * H + C * G + D * F ==> Store3 ==> Pos0 and Pos1
106 mul r9,r21,r27 # B * H
107 mul r10,r22,r26 # C * G
108 mul r7,r23,r25 # D * F
112 swi r9,r1,32 # Pos0 and Pos1
114 # Hi (Store3) + A * H + B * G + C * F + D * E ==> Store3 ==> Pos0
115 lhui r11,r1,32 # Pos0
116 mul r9,r20,r27 # A * H
117 mul r10,r21,r26 # B * G
118 mul r7,r22,r25 # C * F
119 mul r8,r23,r24 # D * E
124 sext16 r9,r9 # Sign extend the MSB
127 # Move results to r3 and r4
131 lwi r3,r1,32 # Hi Part
132 lwi r4,r1,36 # Lo Part
134 # Restore Callee saved registers
144 # Restore Frame and return