Home | History | Annotate | Line # | Download | only in riscv
      1 /* Integer multiplication routines for RISC-V.
      2 
      3    Copyright (C) 2016-2022 Free Software Foundation, Inc.
      4 
      5 This file is part of GCC.
      6 
      7 GCC is free software; you can redistribute it and/or modify it under
      8 the terms of the GNU General Public License as published by the Free
      9 Software Foundation; either version 3, or (at your option) any later
     10 version.
     11 
     12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
     13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
     14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     15 for more details.
     16 
     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.
     20 
     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/>.  */
     25 
     26 #include "riscv-asm.h"
     27 
     28   .text
     29   .align 2
     30 
     31 #if __riscv_xlen == 32
     32 /* Our RV64 64-bit routine is equivalent to our RV32 32-bit routine.  */
     33 # define __muldi3 __mulsi3
     34 #endif
     35 
     36 FUNC_BEGIN (__muldi3)
     37   mv     a2, a0
     38   li     a0, 0
     39 .L1:
     40   andi   a3, a1, 1
     41   beqz   a3, .L2
     42   add    a0, a0, a2
     43 .L2:
     44   srli   a1, a1, 1
     45   slli   a2, a2, 1
     46   bnez   a1, .L1
     47   ret
     48 FUNC_END (__muldi3)
     49