| 1 |
;;;; -*- Mode: Lisp; Syntax: Common-Lisp; indent-tabs-mode: nil; Package: C -*- |
| 2 |
;;;; vim: set filetype=lisp tabstop=8 shiftwidth=2 expandtab: |
| 3 |
|
| 4 |
;;;; |
| 5 |
;;;; Copyright (c) 2003, Juan Jose Garcia Ripoll. |
| 6 |
;;;; |
| 7 |
;;;; See the file 'LICENSE' for the copyright details. |
| 8 |
;;;; |
| 9 |
|
| 10 |
;;;; Optimizer for several constant values |
| 11 |
|
| 12 |
(in-package "COMPILER") |
| 13 |
|
| 14 |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 15 |
;;; |
| 16 |
;;; KNOWN OPTIMIZABLE CONSTANTS |
| 17 |
;;; |
| 18 |
|
| 19 |
(defun make-single-constant-optimizer (name c-value) |
| 20 |
(cond ((symbolp name) |
| 21 |
(let* ((value (symbol-value name)) |
| 22 |
(host-type (lisp-type->host-type (type-of value))) |
| 23 |
(location (make-vv :location c-value :value value :host-type host-type))) |
| 24 |
(cons value location))) |
| 25 |
((floatp name) |
| 26 |
(let* ((value name) |
| 27 |
(location (make-vv :location c-value :value value :host-type :object))) |
| 28 |
(cons value location))) |
| 29 |
(t |
| 30 |
(cons name (make-vv :location c-value :value name))))) |
| 31 |
|
| 32 |
(defun make-optimizable-constants (machine) |
| 33 |
(loop for (value name) in (optimizable-constants-list machine) |
| 34 |
collect (make-single-constant-optimizer value name))) |
| 35 |
|
| 36 |
;;; FIXME this is messy - numbers are lisp objects and symbols are native |
| 37 |
;;; types. We should provide both alternatives for different expected types. |
| 38 |
;;; See WT-TO-OBJECT-CONVERSION |
| 39 |
(defun optimizable-constants-list (machine) |
| 40 |
(append |
| 41 |
;; Constants that appear everywhere |
| 42 |
'( |
| 43 |
;; Order is important: on platforms where 0.0 and -0.0 are the same |
| 44 |
;; the last one is prioritized. |
| 45 |
(#.(coerce 0 'cl:single-float) "cl_core.singlefloat_zero") |
| 46 |
(#.(coerce 0 'cl:double-float) "cl_core.doublefloat_zero") |
| 47 |
(#.(coerce -0.0 'cl:single-float) "cl_core.singlefloat_minus_zero") |
| 48 |
(#.(coerce -0.0 'cl:double-float) "cl_core.doublefloat_minus_zero") |
| 49 |
(#.(coerce 0 'cl:long-float) "cl_core.longfloat_zero") |
| 50 |
(#.(coerce -0.0 'cl:long-float) "cl_core.longfloat_minus_zero") |
| 51 |
|
| 52 |
;; We temporarily remove this constant, because the bytecodes compiler |
| 53 |
;; does not know how to externalize it. |
| 54 |
;;(#.(si::standard-readtable) "cl_core.standard_readtable") |
| 55 |
|
| 56 |
(#.(find-package :cl) "cl_core.lisp_package") |
| 57 |
(#.(find-package :cl-user) "cl_core.user_package") |
| 58 |
(#.(find-package :keyword) "cl_core.keyword_package") |
| 59 |
(#.(find-package :clos) "cl_core.clos_package") |
| 60 |
#+threads |
| 61 |
(#.(find-package :mp) "cl_core.mp_package") |
| 62 |
) |
| 63 |
(when (eq machine *default-machine*) |
| 64 |
;; Constants which are not portable |
| 65 |
`((cl:most-positive-short-float "FLT_MAX") |
| 66 |
(cl:most-positive-single-float "FLT_MAX") |
| 67 |
|
| 68 |
(cl:most-negative-short-float "-FLT_MAX") |
| 69 |
(cl:most-negative-single-float "-FLT_MAX") |
| 70 |
|
| 71 |
(cl:least-positive-short-float "FLT_TRUE_MIN") |
| 72 |
(cl:least-positive-single-float "FLT_TRUE_MIN") |
| 73 |
(cl:least-positive-normalized-short-float "FLT_MIN") |
| 74 |
(cl:least-positive-normalized-single-float" FLT_MIN") |
| 75 |
|
| 76 |
(cl:least-negative-short-float "-FLT_TRUE_MIN") |
| 77 |
(cl:least-negative-single-float "-FLT_TRUE_MIN") |
| 78 |
(cl:least-negative-normalized-short-float "-FLT_MIN") |
| 79 |
(cl:least-negative-normalized-single-float "-FLT_MIN") |
| 80 |
|
| 81 |
(cl:most-positive-double-float "DBL_MAX") |
| 82 |
(cl:most-negative-double-float "-DBL_MAX") |
| 83 |
(cl:least-positive-double-float "DBL_TRUE_MIN") |
| 84 |
(cl:least-positive-normalized-double-float "DBL_MIN") |
| 85 |
(cl:least-negative-double-float "-DBL_TRUE_MIN") |
| 86 |
(cl:least-negative-normalized-double-float "-DBL_MIN") |
| 87 |
|
| 88 |
#+ieee-floating-point |
| 89 |
,@'((ext:short-float-positive-infinity "INFINITY") |
| 90 |
(ext:single-float-positive-infinity "INFINITY") |
| 91 |
(ext:double-float-positive-infinity "INFINITY") |
| 92 |
|
| 93 |
(ext:short-float-negative-infinity "-INFINITY") |
| 94 |
(ext:single-float-negative-infinity "-INFINITY") |
| 95 |
(ext:double-float-negative-infinity "-INFINITY")) |
| 96 |
|
| 97 |
,@'((cl:most-positive-long-float "LDBL_MAX") |
| 98 |
(cl:most-negative-long-float "-LDBL_MAX") |
| 99 |
(cl:least-positive-long-float "LDBL_TRUE_MIN") |
| 100 |
(cl:least-positive-normalized-long-float" LDBL_MIN") |
| 101 |
(cl:least-negative-long-float "-LDBL_TRUE_MIN") |
| 102 |
(cl:least-negative-normalized-long-float "-LDBL_MIN") |
| 103 |
#+ieee-floating-point |
| 104 |
(ext:long-float-positive-infinity "INFINITY") |
| 105 |
#+ieee-floating-point |
| 106 |
(ext:long-float-negative-infinity "-INFINITY")))))) |