/[sb-simd]/sb-simd/test-matrix.lisp
ViewVC logotype

Contents of /sb-simd/test-matrix.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Tue Aug 9 09:45:36 2005 UTC (8 years, 8 months ago) by rlaakso
Branch: MAIN
CVS Tags: HEAD
..
1 #|
2 Copyright (c) 2005 Risto Laakso
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8 1. Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 3. The name of the author may not be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 |#
27 (in-package :cl-user)
28
29 (declaim (optimize (speed 3) (space 0) (safety 0) (debug 0)))
30
31
32 (defun test-matrix (&optional (test-count 10000000))
33 (let ((mat1 (make-array 9 :element-type 'single-float :initial-element 0f0))
34 (mat2 (make-array 9 :element-type 'single-float :initial-element 0f0))
35 (naive #())
36 (sse #())
37 )
38 (declare (type (simple-vector) naive sse) (type fixnum test-count))
39
40 (loop for i of-type fixnum from 0 below 9 do (setf (aref mat1 i) (float (random 1f6))
41 (aref mat2 i) (float (random 1f6))))
42
43 (format t "Data: ~S~%~S~%" mat1 mat2)
44
45 (setf naive (naive-mul33 mat1 mat2)
46 sse (sse-mul33 mat1 mat2))
47
48 (format t "naive mul: ~S~%" naive)
49 (format t "sse mul: ~S~%" sse)
50 (format t "EQUALP? ~A~%" (loop for equal = t
51 for n of-type single-float across naive
52 for s of-type single-float across sse
53 when (/= n s) do (setq equal nil)
54 finally (return equal)))
55 (format t "naive, ~D ops ~%" test-count)
56 (time-sample-form #'(lambda ()
57 (dotimes (i test-count)
58 (setf naive (naive-mul33 mat1 mat2)))))
59
60 (format t "sse, ~D ops ~%" test-count)
61 (time-sample-form #'(lambda ()
62 (dotimes (i test-count)
63 (setf sse (sse-mul33 mat1 mat2)))))
64
65 ))
66
67 (defun sse-mul33 (mat1 mat2)
68 (let ((res (make-array 9 :element-type 'single-float :initial-element 0f0)))
69 (declare (type (simple-array single-float (9)) mat1 mat2 res))
70 (sb-sys:%primitive sb-vm::%sse-matrix-mul-3x3/single-float res mat1 mat2)
71 res))
72
73 (defun naive-mul33 (mat1 mat2)
74 (let ((res (make-array 9 :element-type 'single-float :initial-element 0f0)))
75 (declare (type (simple-array single-float (9)) mat1 mat2 res))
76 (loop for row of-type fixnum from 0 to 2 do
77 (loop for col of-type fixnum from 0 to 2 do
78 (loop for elt of-type fixnum from 0 to 2 do
79 (incf (aref res (+ (* row 3) col))
80 (* (aref mat1 (+ (* row 3) elt)) (aref mat2 (+ (* elt 3) col)))))))
81 res))
82
83

  ViewVC Help
Powered by ViewVC 1.1.5