Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
cmucl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Carl Shapiro
cmucl
Commits
d1af0b85
Commit
d1af0b85
authored
12 years ago
by
Raymond Toy
Browse files
Options
Downloads
Patches
Plain Diff
Optimize TRUNCATE when the second arg is a compile-time constant.
parent
089f104a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/compiler/x86/arith.lisp
+78
-0
78 additions, 0 deletions
src/compiler/x86/arith.lisp
src/general-info/release-20e.txt
+3
-1
3 additions, 1 deletion
src/general-info/release-20e.txt
with
81 additions
and
1 deletion
src/compiler/x86/arith.lisp
+
78
−
0
View file @
d1af0b85
...
...
@@ -474,6 +474,7 @@
(
inst
lea
quo
(
make-ea
:dword
:index
eax
:scale
4
)))
(
move
rem
edx
)))
#+
nil
(
define-vop
(
fast-truncate-c/fixnum=>fixnum
fast-safe-arith-op
)
(
:translate
truncate
)
(
:args
(
x
:scs
(
any-reg
)
:target
eax
))
...
...
@@ -527,6 +528,7 @@
(
move
quo
eax
)
(
move
rem
edx
)))
#+
nil
(
define-vop
(
fast-truncate-c/unsigned=>unsigned
fast-safe-arith-op
)
(
:translate
truncate
)
(
:args
(
x
:scs
(
unsigned-reg
)
:target
eax
))
...
...
@@ -551,6 +553,44 @@
(
move
quo
eax
)
(
move
rem
edx
)))
(
define-vop
(
fast-truncate-c/unsigned=>unsigned
fast-unsigned-binop-c
)
(
:translate
truncate
)
(
:args
(
x
:scs
(
unsigned-reg
)))
(
:info
y
)
(
:arg-types
unsigned-num
(
:constant
(
integer
2
#.
(
1-
(
ash
1
vm:word-bits
)))))
(
:results
(
r
:scs
(
unsigned-reg
))
(
rem
:scs
(
unsigned-reg
)))
(
:result-types
unsigned-num
unsigned-num
)
(
:note
"inline (unsigned-byte 32) arithmetic"
)
(
:temporary
(
:sc
unsigned-reg
:offset
edx-offset
)
edx
)
(
:temporary
(
:sc
unsigned-reg
:offset
eax-offset
)
eax
)
(
:generator
6
(
multiple-value-bind
(
recip
shift
overflowp
)
(
c::find-unsigned-reciprocal
y
vm:word-bits
)
;; q = floor(M*x/2^32)
(
inst
mov
eax
recip
)
(
inst
mul
eax
x
)
; edx:eax = x*recip
(
cond
(
overflowp
;; The case where the sum overflows. X86 has a rotate
;; with carry instruction so use that to get the MSB of
;; the sum and then a regular shift to get the correct
;; number of shifts.
(
inst
add
edx
x
)
(
inst
rcr
edx
1
)
(
when
(
>
shift
1
)
(
inst
shr
edx
(
1-
shift
))))
(
t
;; The easy case
(
unless
(
zerop
shift
)
(
inst
shr
edx
shift
))))
;; Compute the remainder
(
move
rem
x
)
; Save x in case r is the same tn
(
move
r
edx
)
(
move
eax
edx
)
(
inst
mov
edx
y
)
(
inst
mul
eax
edx
)
(
inst
sub
rem
eax
))))
(
define-vop
(
fast-truncate/signed=>signed
fast-safe-arith-op
)
(
:translate
truncate
)
(
:args
(
x
:scs
(
signed-reg
)
:target
eax
)
...
...
@@ -578,6 +618,7 @@
(
move
quo
eax
)
(
move
rem
edx
)))
#+
nil
(
define-vop
(
fast-truncate-c/signed=>signed
fast-safe-arith-op
)
(
:translate
truncate
)
(
:args
(
x
:scs
(
signed-reg
)
:target
eax
))
...
...
@@ -602,6 +643,43 @@
(
move
quo
eax
)
(
move
rem
edx
)))
(
define-vop
(
fast-truncate-c/signed=>signed
fast-signed-binop-c
)
(
:translate
truncate
)
(
:args
(
x
:scs
(
signed-reg
)))
(
:info
y
)
(
:arg-types
signed-num
(
:constant
(
integer
2
#.
(
1-
(
ash
1
vm:word-bits
)))))
(
:results
(
r
:scs
(
signed-reg
))
(
rem
:scs
(
signed-reg
)))
(
:result-types
signed-num
signed-num
)
(
:note
"inline (signed-byte 32) arithmetic"
)
(
:temporary
(
:sc
signed-reg
:offset
edx-offset
)
edx
)
(
:temporary
(
:sc
signed-reg
:offset
eax-offset
)
eax
)
(
:generator
13
(
multiple-value-bind
(
recip
shift
)
(
c::find-signed-reciprocal
y
vm:word-bits
)
;; Compute q = floor(M*n/2^32). That is, the high half of the
;; product.
(
inst
mov
eax
recip
)
(
inst
imul
x
)
; edx:eax = x * recip
;; Adjust if the M is negative.
(
when
(
minusp
recip
)
(
inst
add
edx
x
))
;; Shift quotient as needed.
(
unless
(
zerop
shift
)
(
inst
sar
edx
shift
))
;; Add one to quotient if X is negative. This is done by right
;; shifting X to give either -1 or 0. Then subtract this from
;; the quotient. (NOTE: in the book, the sample code has this
;; wrong and ADDS instead of SUBTRACTS.)
(
move
eax
x
)
(
inst
sar
eax
31
)
(
inst
sub
edx
eax
)
;; Now compute the remainder.
(
move
rem
x
)
(
move
r
edx
)
; Save quotient for return
(
inst
imul
edx
y
)
; edx = q * y
(
inst
sub
rem
edx
))))
;;;; Shifting
...
...
This diff is collapsed.
Click to expand it.
src/general-info/release-20e.txt
+
3
−
1
View file @
d1af0b85
...
...
@@ -31,7 +31,9 @@ New in this release:
* The sparc port can be built using gcc once again.
* The old Cheney stop-and-copy GC supported on sparc once again.
However, there are no plans on supplying sparc binaries with
this GC.
this GC.
* For x86, optimize TRUNCATE when the second arg is a compile-time
constant. (Sparc and ppc already had this optimization)
* ANSI compliance fixes:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment