PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/simd-pack.impure.lisp

http://github.com/sbcl/sbcl
Lisp | 154 lines | 130 code | 10 blank | 14 comment | 6 complexity | 06ac51f1c75eb8b9792ea0b66c83e213 MD5 | raw file
Possible License(s): CC0-1.0
  1. ;;;; Potentially side-effectful tests of the simd-pack infrastructure.
  2. ;;;; This software is part of the SBCL system. See the README file for
  3. ;;;; more information.
  4. ;;;;
  5. ;;;; While most of SBCL is derived from the CMU CL system, the test
  6. ;;;; files (like this one) were written from scratch after the fork
  7. ;;;; from CMU CL.
  8. ;;;;
  9. ;;;; This software is in the public domain and is provided with
  10. ;;;; absolutely no warranty. See the COPYING and CREDITS files for
  11. ;;;; more information.
  12. #-sb-simd-pack (exit :code 104)
  13. (defun make-constant-packs ()
  14. (values (sb-kernel:%make-simd-pack-ub64 1 2)
  15. (sb-kernel:%make-simd-pack-ub32 0 0 0 0)
  16. (sb-kernel:%make-simd-pack-ub64 (ldb (byte 64 0) -1)
  17. (ldb (byte 64 0) -1))
  18. (sb-kernel:%make-simd-pack-single 1f0 2f0 3f0 4f0)
  19. (sb-kernel:%make-simd-pack-single 0f0 0f0 0f0 0f0)
  20. (sb-kernel:%make-simd-pack-single (sb-kernel:make-single-float -1)
  21. (sb-kernel:make-single-float -1)
  22. (sb-kernel:make-single-float -1)
  23. (sb-kernel:make-single-float -1))
  24. (sb-kernel:%make-simd-pack-double 1d0 2d0)
  25. (sb-kernel:%make-simd-pack-double 0d0 0d0)
  26. (sb-kernel:%make-simd-pack-double (sb-kernel:make-double-float
  27. -1 (ldb (byte 32 0) -1))
  28. (sb-kernel:make-double-float
  29. -1 (ldb (byte 32 0) -1)))))
  30. (with-test (:name :compile-simd-pack)
  31. (multiple-value-bind (i i0 i-1
  32. f f0 f-1
  33. d d0 d-1)
  34. (make-constant-packs)
  35. (loop for (lo hi) in (list '(1 2) '(0 0)
  36. (list (ldb (byte 64 0) -1)
  37. (ldb (byte 64 0) -1)))
  38. for pack in (list i i0 i-1)
  39. do (assert (eql lo (sb-kernel:%simd-pack-low pack)))
  40. (assert (eql hi (sb-kernel:%simd-pack-high pack))))
  41. (loop for expected in (list '(1f0 2f0 3f0 4f0)
  42. '(0f0 0f0 0f0 0f0)
  43. (make-list
  44. 4 :initial-element (sb-kernel:make-single-float -1)))
  45. for pack in (list f f0 f-1)
  46. do (assert (every #'eql expected
  47. (multiple-value-list (sb-kernel:%simd-pack-singles pack)))))
  48. (loop for expected in (list '(1d0 2d0)
  49. '(0d0 0d0)
  50. (make-list
  51. 2 :initial-element (sb-kernel:make-double-float
  52. -1 (ldb (byte 32 0) -1))))
  53. for pack in (list d d0 d-1)
  54. do (assert (every #'eql expected
  55. (multiple-value-list (sb-kernel:%simd-pack-doubles pack)))))))
  56. (with-test (:name (simd-pack print :smoke))
  57. (let ((packs (multiple-value-list (make-constant-packs))))
  58. (flet ((print-them (expect)
  59. (dolist (pack packs)
  60. (flet ((do-it ()
  61. (with-output-to-string (stream)
  62. (write pack :stream stream :pretty t :escape nil))))
  63. (case expect
  64. (print-not-readable
  65. (assert-error (do-it) print-not-readable))
  66. (t
  67. (typecase pack
  68. ((simd-pack single-float)
  69. (if (and *print-readably*
  70. (some #'float-nan-p (multiple-value-list
  71. (%simd-pack-singles pack))))
  72. (assert-error (do-it) print-not-readable)
  73. (do-it)))
  74. ((simd-pack double-float)
  75. (if (and *print-readably*
  76. (some #'float-nan-p (multiple-value-list
  77. (%simd-pack-doubles pack))))
  78. (assert-error (do-it) print-not-readable)
  79. (do-it)))
  80. (t
  81. (do-it)))))))))
  82. ;; Default
  83. (print-them t)
  84. ;; Readably
  85. (let ((*print-readably* t)
  86. (*read-eval* t))
  87. (print-them t))
  88. ;; Want readably but can't without *READ-EVAL*.
  89. (let ((*print-readably* t)
  90. (*read-eval* nil))
  91. (print-them 'print-not-readable)))))
  92. (defvar *tmp-filename* (scratch-file-name))
  93. (defvar *pack*)
  94. (with-test (:name :load-simd-pack-int)
  95. (with-open-file (s *tmp-filename*
  96. :direction :output
  97. :if-exists :supersede
  98. :if-does-not-exist :create)
  99. (print '(setq *pack* (sb-kernel:%make-simd-pack-ub64 2 4)) s))
  100. (let (tmp-fasl)
  101. (unwind-protect
  102. (progn
  103. (setq tmp-fasl (compile-file *tmp-filename*))
  104. (let ((*pack* nil))
  105. (load tmp-fasl)
  106. (assert (typep *pack* '(sb-kernel:simd-pack integer)))
  107. (assert (= 2 (sb-kernel:%simd-pack-low *pack*)))
  108. (assert (= 4 (sb-kernel:%simd-pack-high *pack*)))))
  109. (when tmp-fasl (delete-file tmp-fasl))
  110. (delete-file *tmp-filename*))))
  111. (with-test (:name :load-simd-pack-single)
  112. (with-open-file (s *tmp-filename*
  113. :direction :output
  114. :if-exists :supersede
  115. :if-does-not-exist :create)
  116. (print '(setq *pack* (sb-kernel:%make-simd-pack-single 1f0 2f0 3f0 4f0)) s))
  117. (let (tmp-fasl)
  118. (unwind-protect
  119. (progn
  120. (setq tmp-fasl (compile-file *tmp-filename*))
  121. (let ((*pack* nil))
  122. (load tmp-fasl)
  123. (assert (typep *pack* '(sb-kernel:simd-pack single-float)))
  124. (assert (equal (multiple-value-list (sb-kernel:%simd-pack-singles *pack*))
  125. '(1f0 2f0 3f0 4f0)))))
  126. (when tmp-fasl (delete-file tmp-fasl))
  127. (delete-file *tmp-filename*))))
  128. (with-test (:name :load-simd-pack-double)
  129. (with-open-file (s *tmp-filename*
  130. :direction :output
  131. :if-exists :supersede
  132. :if-does-not-exist :create)
  133. (print '(setq *pack* (sb-kernel:%make-simd-pack-double 1d0 2d0)) s))
  134. (let (tmp-fasl)
  135. (unwind-protect
  136. (progn
  137. (setq tmp-fasl (compile-file *tmp-filename*))
  138. (let ((*pack* nil))
  139. (load tmp-fasl)
  140. (assert (typep *pack* '(sb-kernel:simd-pack double-float)))
  141. (assert (equal (multiple-value-list (sb-kernel:%simd-pack-doubles *pack*))
  142. '(1d0 2d0)))))
  143. (when tmp-fasl (delete-file tmp-fasl))
  144. (delete-file *tmp-filename*))))