Debian Codegraph @

msvc/gmp/mpn/x86i/diveby3.asm

raw
1
2 ; Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
3 ;
4 ; This file is part of the GNU MP Library.
5 ;
6 ; The GNU MP Library is free software; you can redistribute it and/or
7 ; modify it under the terms of the GNU Lesser General Public License as
8 ; published by the Free Software Foundation; either version 2.1 of the
9 ; License, or (at your option) any later version.
10 ;
11 ; The GNU MP Library is distributed in the hope that it will be useful,
12 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ; Lesser General Public License for more details.
15 ;
16 ; You should have received a copy of the GNU Lesser General Public
17 ; License along with the GNU MP Library; see the file COPYING.LIB. If
18 ; not, write to the Free Software Foundation, Inc., 59 Temple Place -
19 ; Suite 330, Boston, MA 02111-1307, USA.
20 ;
21 ; Translation of AT&T syntax code by Brian Gladman
22
23 %include "x86i.inc"
24
25 %define PARAM_CARRY esp+frame+16
26 %define PARAM_SIZE esp+frame+12
27 %define PARAM_SRC esp+frame+8
28 %define PARAM_DST esp+frame+4
29 %assign frame 0
30
31 ; multiplicative inverse of 3,modulo 2^32
32 ; ceil(b/3) and ceil(b*2/3) where b=2^32
33
34 %define INVERSE_3 0xAAAAAAAB
35 %define ONE_THIRD_CEIL 0x55555556
36 %define TWO_THIRDS_CEIL 0xAAAAAAAB
37
38 section .text
39
40 global ___gmpn_divexact_by3c
41 %ifdef DLL
42 export ___gmpn_divexact_by3c
43 %endif
44
45 align 8
46 ___gmpn_divexact_by3c:
47 mov ecx,[PARAM_SRC]
48 FR_push ebp
49 mov ebp,[PARAM_SIZE]
50 FR_push edi
51 mov edi,[PARAM_DST]
52 FR_push esi
53 mov esi,INVERSE_3
54 FR_push ebx
55 lea ecx,[ecx+ebp*4]
56 mov ebx,[PARAM_CARRY]
57 lea edi,[edi+ebp*4]
58 neg ebp
59
60 ; eax scratch,low product
61 ; ebx carry limb (0 to 3)
62 ; ecx &src[size]
63 ; edx scratch,high product
64 ; esi multiplier
65 ; edi &dst[size]
66 ; ebp counter,limbs,negative
67
68 align 8
69 Ltop:
70 mov eax,[ecx+ebp*4]
71 sub eax,ebx
72 setc bl
73 imul esi
74 cmp eax,ONE_THIRD_CEIL
75 mov [edi+ebp*4],eax
76 sbb ebx,-1 ; +1 if eax>=ceil(b/3)
77 cmp eax,TWO_THIRDS_CEIL
78 sbb ebx,-1 ; +1 if eax>=ceil(b*2/3)
79 inc ebp
80 jnz Ltop
81 mov eax,ebx
82 pop ebx
83 pop esi
84 pop edi
85 pop ebp
86 ret
87
88 end