Newer
Older
;;; -*- Mode: LISP; Syntax: Common-Lisp; Base: 10; Package: x86 -*-
;;;
;;; **********************************************************************
;;; This code was written as part of the CMU Common Lisp project at
;;; Carnegie Mellon University, and has been placed in the public domain.
;;; If you want to use this code or any part of CMU Common Lisp, please contact
;;; Scott Fahlman or slisp-group@cs.cmu.edu.
;;;
(ext:file-comment
"$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/compiler/x86/array.lisp,v 1.17 1999/03/08 00:57:32 dtc Exp $")
;;;
;;; **********************************************************************
;;;
;;; This file contains the x86 definitions for array operations.
;;;
;;; Written by William Lott
;;;
;;; Debugged by Paul F. Werkowski Spring/Summer 1995.
;;; Enhancements/debugging by Douglas T. Crosher 1996,1997,1998,1999.
;;;
(in-package :x86)
;;;; Allocator for the array header.
(define-vop (make-array-header)
(:translate make-array-header)
(:policy :fast-safe)
(:args (type :scs (any-reg))
(rank :scs (any-reg)))
(:arg-types positive-fixnum positive-fixnum)
(:temporary (:sc any-reg :to :eval) bytes)
(:temporary (:sc any-reg :to :result) header)
(:results (result :scs (descriptor-reg) :from :eval))
(:generator 13
(inst lea bytes
(make-ea :dword :base rank
:disp (+ (* (1+ array-dimensions-offset) word-bytes)
lowtag-mask)))
(inst and bytes (lognot lowtag-mask))
(inst lea header (make-ea :dword :base rank
:disp (fixnum (1- array-dimensions-offset))))
(inst shl header type-bits)
(inst or header type)
(inst shr header 2)
(pseudo-atomic
(allocation result bytes node)
(inst lea result (make-ea :dword :base result :disp other-pointer-type))
(storew header result 0 other-pointer-type))))
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
;;;; Additional accessors and setters for the array header.
(defknown lisp::%array-dimension (t index) index
(flushable))
(defknown lisp::%set-array-dimension (t index index) index
())
(define-full-reffer %array-dimension *
array-dimensions-offset other-pointer-type
(any-reg) positive-fixnum lisp::%array-dimension)
(define-full-setter %set-array-dimension *
array-dimensions-offset other-pointer-type
(any-reg) positive-fixnum lisp::%set-array-dimension)
(defknown lisp::%array-rank (t) index (flushable))
(define-vop (array-rank-vop)
(:translate lisp::%array-rank)
(:policy :fast-safe)
(:args (x :scs (descriptor-reg)))
(:results (res :scs (unsigned-reg)))
(:result-types positive-fixnum)
(:generator 6
(loadw res x 0 other-pointer-type)
(inst shr res type-bits)
(inst sub res (1- array-dimensions-offset))))
;;;; Bounds checking routine.
;;; Note that the immediate SC for the index argument is disabled
;;; because it is not possible to generate a valid error code SC for
;;; an immediate value.
(define-vop (check-bound)
(:translate %check-bound)
(:policy :fast-safe)
(:args (array :scs (descriptor-reg))
(bound :scs (any-reg descriptor-reg))
(index :scs (any-reg descriptor-reg #+nil immediate) :target result))
(:results (result :scs (any-reg descriptor-reg)))
(:result-types positive-fixnum)
(:vop-var vop)
(:save-p :compute-only)
(:generator 5
(let ((error (generate-error-code vop invalid-array-index-error
array bound index))
(index (if (sc-is index immediate) (fixnum (tn-value index)) index)))
(inst cmp bound index)
;; We use below-or-equal even though it's an unsigned test, because
;; negative indexes appear as real large unsigned numbers. Therefore,
;; we get the < 0 and >= bound test all rolled into one.
(inst jmp :be error)
(unless (and (tn-p index) (location= result index))
(inst mov result index)))))
;;;; Accessors/Setters
;;; Variants built on top of word-index-ref, etc. I.e. those vectors whos
;;; elements are represented in integer registers and are built out of
;;; 8, 16, or 32 bit elements.
(eval-when (compile eval)
(defmacro def-full-data-vector-frobs (type element-type &rest scs)
`(progn
(define-full-reffer ,(symbolicate "DATA-VECTOR-REF/" type) ,type
vector-data-offset other-pointer-type ,scs ,element-type
data-vector-ref)
(define-full-setter ,(symbolicate "DATA-VECTOR-SET/" type) ,type
vector-data-offset other-pointer-type ,scs ,element-type
data-vector-set)))
); eval-when (compile eval)
(def-full-data-vector-frobs simple-vector * descriptor-reg any-reg)
(def-full-data-vector-frobs simple-array-unsigned-byte-32 unsigned-num
unsigned-reg)
(def-full-data-vector-frobs simple-array-signed-byte-30 tagged-num any-reg)
(def-full-data-vector-frobs simple-array-signed-byte-32 signed-num signed-reg)
;;; Integer vectors whos elements are smaller than a byte. I.e. bit, 2-bit,
;;; and 4-bit vectors.
;;;
(eval-when (compile eval)
(defmacro def-small-data-vector-frobs (type bits)
(let* ((elements-per-word (floor vm:word-bits bits))
(bit-shift (1- (integer-length elements-per-word))))
`(progn
(define-vop (,(symbolicate 'data-vector-ref/ type))
(:note "inline array access")
(:translate data-vector-ref)
(:policy :fast-safe)
(:args (object :scs (descriptor-reg))
(index :scs (unsigned-reg)))
(:arg-types ,type positive-fixnum)
(:results (result :scs (unsigned-reg) :from (:argument 0)))
(:result-types positive-fixnum)
(:temporary (:sc unsigned-reg :offset ecx-offset) ecx)
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
(:generator 20
(move ecx index)
(inst shr ecx ,bit-shift)
(inst mov result
(make-ea :dword :base object :index ecx :scale 4
:disp (- (* vector-data-offset word-bytes)
other-pointer-type)))
(move ecx index)
(inst and ecx ,(1- elements-per-word))
,@(unless (= bits 1)
`((inst shl ecx ,(1- (integer-length bits)))))
(inst shr result :cl)
(inst and result ,(1- (ash 1 bits)))))
(define-vop (,(symbolicate 'data-vector-ref-c/ type))
(:translate data-vector-ref)
(:policy :fast-safe)
(:args (object :scs (descriptor-reg)))
(:arg-types ,type (:constant index))
(:info index)
(:results (result :scs (unsigned-reg)))
(:result-types positive-fixnum)
(:generator 15
(multiple-value-bind (word extra) (floor index ,elements-per-word)
(loadw result object (+ word vector-data-offset)
other-pointer-type)
(unless (zerop extra)
(inst shr result (* extra ,bits)))
(unless (= extra ,(1- elements-per-word))
(inst and result ,(1- (ash 1 bits)))))))
(define-vop (,(symbolicate 'data-vector-set/ type))
(:note "inline array store")
(:translate data-vector-set)
(:policy :fast-safe)
(:args (object :scs (descriptor-reg) :target ptr)
(index :scs (unsigned-reg) :target ecx)
(value :scs (unsigned-reg immediate) :target result))
(:arg-types ,type positive-fixnum positive-fixnum)
(:results (result :scs (unsigned-reg)))
(:result-types positive-fixnum)
(:temporary (:sc unsigned-reg) word-index)
(:temporary (:sc unsigned-reg :from (:argument 0)) ptr old)
(:temporary (:sc unsigned-reg :offset ecx-offset :from (:argument 1))
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
ecx)
(:generator 25
(move word-index index)
(inst shr word-index ,bit-shift)
(inst lea ptr
(make-ea :dword :base object :index word-index :scale 4
:disp (- (* vector-data-offset word-bytes)
other-pointer-type)))
(loadw old ptr)
(move ecx index)
(inst and ecx ,(1- elements-per-word))
,@(unless (= bits 1)
`((inst shl ecx ,(1- (integer-length bits)))))
(inst ror old :cl)
(unless (and (sc-is value immediate)
(= (tn-value value) ,(1- (ash 1 bits))))
(inst and old ,(lognot (1- (ash 1 bits)))))
(sc-case value
(immediate
(unless (zerop (tn-value value))
(inst or old (logand (tn-value value) ,(1- (ash 1 bits))))))
(unsigned-reg
(inst or old value)))
(inst rol old :cl)
(storew old ptr)
(sc-case value
(immediate
(inst mov result (tn-value value)))
(unsigned-reg
(move result value)))))
(define-vop (,(symbolicate 'data-vector-set-c/ type))
(:translate data-vector-set)
(:policy :fast-safe)
(:args (object :scs (descriptor-reg))
(value :scs (unsigned-reg immediate) :target result))
(:arg-types ,type (:constant index) positive-fixnum)
(:info index)
(:results (result :scs (unsigned-reg)))
(:result-types positive-fixnum)
(:temporary (:sc unsigned-reg :to (:result 0)) old)
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
(:generator 20
(multiple-value-bind (word extra) (floor index ,elements-per-word)
(inst mov old
(make-ea :dword :base object
:disp (- (* (+ word vector-data-offset) word-bytes)
other-pointer-type)))
(sc-case value
(immediate
(let* ((value (tn-value value))
(mask ,(1- (ash 1 bits)))
(shift (* extra ,bits)))
(unless (= value mask)
(inst and old (lognot (ash mask shift))))
(unless (zerop value)
(inst or old (ash value shift)))))
(unsigned-reg
(let ((shift (* extra ,bits)))
(unless (zerop shift)
(inst ror old shift)
(inst and old (lognot ,(1- (ash 1 bits))))
(inst or old value)
(inst rol old shift)))))
(inst mov (make-ea :dword :base object
:disp (- (* (+ word vector-data-offset) word-bytes)
other-pointer-type))
old)
(sc-case value
(immediate
(inst mov result (tn-value value)))
(unsigned-reg
(move result value)))))))))
); eval-when (compile eval)
(def-small-data-vector-frobs simple-bit-vector 1)
(def-small-data-vector-frobs simple-array-unsigned-byte-2 2)
(def-small-data-vector-frobs simple-array-unsigned-byte-4 4)
;;; And the float variants.
;;;
(define-vop (data-vector-ref/simple-array-single-float)
(:note "inline array access")
(:translate data-vector-ref)
(:policy :fast-safe)
(:args (object :scs (descriptor-reg))
(index :scs (any-reg)))
(:arg-types simple-array-single-float positive-fixnum)
(:results (value :scs (single-reg)))
(:result-types single-float)
(:generator 5
(with-empty-tn@fp-top(value)
(inst fld (make-ea :dword :base object :index index :scale 1
:disp (- (* vm:vector-data-offset vm:word-bytes)
vm:other-pointer-type))))))
(define-vop (data-vector-ref-c/simple-array-single-float)
(:note "inline array access")
(:translate data-vector-ref)
(:policy :fast-safe)
(:args (object :scs (descriptor-reg)))
(:info index)
(:arg-types simple-array-single-float (:constant (signed-byte 30)))
(:results (value :scs (single-reg)))
(:result-types single-float)
(:generator 4
(with-empty-tn@fp-top(value)
(inst fld (make-ea :dword :base object
:disp (- (+ (* vm:vector-data-offset vm:word-bytes)
(* 4 index))
vm:other-pointer-type))))))
(define-vop (data-vector-set/simple-array-single-float)
(:note "inline array store")
(:translate data-vector-set)
(:policy :fast-safe)
(:args (object :scs (descriptor-reg))
(index :scs (any-reg))
(value :scs (single-reg) :target result))
(:arg-types simple-array-single-float positive-fixnum single-float)
(:results (result :scs (single-reg)))
(:result-types single-float)
(:generator 5
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
(cond ((zerop (tn-offset value))
;; Value is in ST0
(inst fst (make-ea :dword :base object :index index :scale 1
:disp (- (* vm:vector-data-offset vm:word-bytes)
vm:other-pointer-type)))
(unless (zerop (tn-offset result))
;; Value is in ST0 but not result.
(inst fst result)))
(t
;; Value is not in ST0.
(inst fxch value)
(inst fst (make-ea :dword :base object :index index :scale 1
:disp (- (* vm:vector-data-offset vm:word-bytes)
vm:other-pointer-type)))
(cond ((zerop (tn-offset result))
;; The result is in ST0.
(inst fst value))
(t
;; Neither value or result are in ST0
(unless (location= value result)
(inst fst result))
(inst fxch value)))))))
(define-vop (data-vector-set-c/simple-array-single-float)
(:note "inline array store")
(:translate data-vector-set)
(:policy :fast-safe)
(:args (object :scs (descriptor-reg))
(value :scs (single-reg) :target result))
(:info index)
(:arg-types simple-array-single-float (:constant (signed-byte 30))
single-float)
(:results (result :scs (single-reg)))
(:result-types single-float)
(:generator 4
(cond ((zerop (tn-offset value))
;; Value is in ST0
(inst fst (make-ea :dword :base object
:disp (- (+ (* vm:vector-data-offset
vm:word-bytes)
(* 4 index))
vm:other-pointer-type)))
(unless (zerop (tn-offset result))
;; Value is in ST0 but not result.
(inst fst result)))
(t
;; Value is not in ST0.
(inst fxch value)
(inst fst (make-ea :dword :base object
:disp (- (+ (* vm:vector-data-offset
vm:word-bytes)
(* 4 index))
vm:other-pointer-type)))
(cond ((zerop (tn-offset result))
;; The result is in ST0.
(inst fst value))
(t
;; Neither value or result are in ST0
(unless (location= value result)
(inst fst result))
(inst fxch value)))))))
(define-vop (data-vector-ref/simple-array-double-float)
(:note "inline array access")
(:translate data-vector-ref)
(:policy :fast-safe)
(:args (object :scs (descriptor-reg))
(index :scs (any-reg)))
(:arg-types simple-array-double-float positive-fixnum)
(:results (value :scs (double-reg)))
(:result-types double-float)
(:generator 7
(with-empty-tn@fp-top(value)
(inst fldd (make-ea :dword :base object :index index :scale 2
:disp (- (* vm:vector-data-offset vm:word-bytes)
vm:other-pointer-type))))))
(define-vop (data-vector-ref-c/simple-array-double-float)
(:note "inline array access")
(:translate data-vector-ref)
(:policy :fast-safe)
(:args (object :scs (descriptor-reg)))
(:info index)
(:arg-types simple-array-double-float (:constant (signed-byte 30)))
(:results (value :scs (double-reg)))
(:result-types double-float)
(:generator 6
(with-empty-tn@fp-top(value)
(inst fldd (make-ea :dword :base object
:disp (- (+ (* vm:vector-data-offset vm:word-bytes)
(* 8 index))
vm:other-pointer-type))))))
(define-vop (data-vector-set/simple-array-double-float)
(:note "inline array store")
(:translate data-vector-set)
(:policy :fast-safe)
(:args (object :scs (descriptor-reg))
(index :scs (any-reg))
(value :scs (double-reg) :target result))
(:arg-types simple-array-double-float positive-fixnum double-float)
(:results (result :scs (double-reg)))
(:result-types double-float)
(:generator 20
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
(cond ((zerop (tn-offset value))
;; Value is in ST0
(inst fstd (make-ea :dword :base object :index index :scale 2
:disp (- (* vm:vector-data-offset vm:word-bytes)
vm:other-pointer-type)))
(unless (zerop (tn-offset result))
;; Value is in ST0 but not result.
(inst fstd result)))
(t
;; Value is not in ST0.
(inst fxch value)
(inst fstd (make-ea :dword :base object :index index :scale 2
:disp (- (* vm:vector-data-offset vm:word-bytes)
vm:other-pointer-type)))
(cond ((zerop (tn-offset result))
;; The result is in ST0.
(inst fstd value))
(t
;; Neither value or result are in ST0
(unless (location= value result)
(inst fstd result))
(inst fxch value)))))))
(define-vop (data-vector-set-c/simple-array-double-float)
(:note "inline array store")
(:translate data-vector-set)
(:policy :fast-safe)
(:args (object :scs (descriptor-reg))
(value :scs (double-reg) :target result))
(:info index)
(:arg-types simple-array-double-float (:constant (signed-byte 30))
double-float)
(:results (result :scs (double-reg)))
(:result-types double-float)
(:generator 19
(cond ((zerop (tn-offset value))
;; Value is in ST0
(inst fstd (make-ea :dword :base object
:disp (- (+ (* vm:vector-data-offset
vm:word-bytes)
(* 8 index))
vm:other-pointer-type)))
(unless (zerop (tn-offset result))
;; Value is in ST0 but not result.
(inst fstd result)))
(t
;; Value is not in ST0.
(inst fxch value)
(inst fstd (make-ea :dword :base object
:disp (- (+ (* vm:vector-data-offset
vm:word-bytes)
(* 8 index))
vm:other-pointer-type)))
(cond ((zerop (tn-offset result))
;; The result is in ST0.
(inst fstd value))
(t
;; Neither value or result are in ST0
(unless (location= value result)
(inst fstd result))
(inst fxch value)))))))
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
#+long-float
(define-vop (data-vector-ref/simple-array-long-float)
(:note "inline array access")
(:translate data-vector-ref)
(:policy :fast-safe)
(:args (object :scs (descriptor-reg) :to :result)
(index :scs (any-reg)))
(:arg-types simple-array-long-float positive-fixnum)
(:temporary (:sc any-reg :from :eval :to :result) temp)
(:results (value :scs (long-reg)))
(:result-types long-float)
(:generator 7
;; temp = 3 * index
(inst lea temp (make-ea :dword :base index :index index :scale 2))
(with-empty-tn@fp-top(value)
(inst fldl (make-ea :dword :base object :index temp :scale 1
:disp (- (* vm:vector-data-offset vm:word-bytes)
vm:other-pointer-type))))))
#+long-float
(define-vop (data-vector-ref-c/simple-array-long-float)
(:note "inline array access")
(:translate data-vector-ref)
(:policy :fast-safe)
(:args (object :scs (descriptor-reg)))
(:info index)
(:arg-types simple-array-long-float (:constant (signed-byte 30)))
(:results (value :scs (long-reg)))
(:result-types long-float)
(:generator 6
(with-empty-tn@fp-top(value)
(inst fldl (make-ea :dword :base object
:disp (- (+ (* vm:vector-data-offset vm:word-bytes)
(* 12 index))
vm:other-pointer-type))))))
#+long-float
(define-vop (data-vector-set/simple-array-long-float)
(:note "inline array store")
(:translate data-vector-set)
(:policy :fast-safe)
(:args (object :scs (descriptor-reg) :to :result)
(index :scs (any-reg))
(value :scs (long-reg) :target result))
(:arg-types simple-array-long-float positive-fixnum long-float)
(:temporary (:sc any-reg :from (:argument 1) :to :result) temp)
(:results (result :scs (long-reg)))
(:result-types long-float)
(:generator 20
;; temp = 3 * index
(inst lea temp (make-ea :dword :base index :index index :scale 2))
(cond ((zerop (tn-offset value))
;; Value is in ST0
(store-long-float
(make-ea :dword :base object :index temp :scale 1
:disp (- (* vm:vector-data-offset vm:word-bytes)
vm:other-pointer-type)))
(unless (zerop (tn-offset result))
;; Value is in ST0 but not result.
(inst fstd result)))
(t
;; Value is not in ST0.
(inst fxch value)
(store-long-float
(make-ea :dword :base object :index temp :scale 1
:disp (- (* vm:vector-data-offset vm:word-bytes)
vm:other-pointer-type)))
(cond ((zerop (tn-offset result))
;; The result is in ST0.
(inst fstd value))
(t
;; Neither value or result are in ST0
(unless (location= value result)
(inst fstd result))
(inst fxch value)))))))
#+long-float
(define-vop (data-vector-set-c/simple-array-long-float)
(:note "inline array store")
(:translate data-vector-set)
(:policy :fast-safe)
(:args (object :scs (descriptor-reg))
(value :scs (long-reg) :target result))
(:info index)
(:arg-types simple-array-long-float (:constant (signed-byte 30)) long-float)
(:results (result :scs (long-reg)))
(:result-types long-float)
(:generator 19
(cond ((zerop (tn-offset value))
;; Value is in ST0
(store-long-float (make-ea :dword :base object
:disp (- (+ (* vm:vector-data-offset
vm:word-bytes)
(* 12 index))
vm:other-pointer-type)))
(unless (zerop (tn-offset result))
;; Value is in ST0 but not result.
(inst fstd result)))
(t
;; Value is not in ST0.
(inst fxch value)
(store-long-float (make-ea :dword :base object
:disp (- (+ (* vm:vector-data-offset
vm:word-bytes)
(* 12 index))
vm:other-pointer-type)))
(cond ((zerop (tn-offset result))
;; The result is in ST0.
(inst fstd value))
(t
;; Neither value or result are in ST0
(unless (location= value result)
(inst fstd result))
(inst fxch value)))))))
;;; Complex float variants.
(define-vop (data-vector-ref/simple-array-complex-single-float)
(:note "inline array access")
(:translate data-vector-ref)
(:policy :fast-safe)
(:args (object :scs (descriptor-reg))
(index :scs (any-reg)))
(:arg-types simple-array-complex-single-float positive-fixnum)
(:results (value :scs (complex-single-reg)))
(:result-types complex-single-float)
(:generator 5
(let ((real-tn (complex-single-reg-real-tn value)))
(with-empty-tn@fp-top (real-tn)
(inst fld (make-ea :dword :base object :index index :scale 2
:disp (- (* vm:vector-data-offset vm:word-bytes)
vm:other-pointer-type)))))
(let ((imag-tn (complex-single-reg-imag-tn value)))
(with-empty-tn@fp-top (imag-tn)
(inst fld (make-ea :dword :base object :index index :scale 2
:disp (- (* (1+ vm:vector-data-offset)
vm:word-bytes)
vm:other-pointer-type)))))))
(define-vop (data-vector-ref-c/simple-array-complex-single-float)
(:note "inline array access")
(:translate data-vector-ref)
(:policy :fast-safe)
(:args (object :scs (descriptor-reg)))
(:info index)
(:arg-types simple-array-complex-single-float (:constant (signed-byte 30)))
(:results (value :scs (complex-single-reg)))
(:result-types complex-single-float)
(:generator 4
(let ((real-tn (complex-single-reg-real-tn value)))
(with-empty-tn@fp-top (real-tn)
(inst fld (make-ea :dword :base object
:disp (- (+ (* vm:vector-data-offset vm:word-bytes)
(* 8 index))
vm:other-pointer-type)))))
(let ((imag-tn (complex-single-reg-imag-tn value)))
(with-empty-tn@fp-top (imag-tn)
(inst fld (make-ea :dword :base object
:disp (- (+ (* vm:vector-data-offset vm:word-bytes)
(* 8 index) 4)
vm:other-pointer-type)))))))
(define-vop (data-vector-set/simple-array-complex-single-float)
(:note "inline array store")
(:translate data-vector-set)
(:policy :fast-safe)
(:args (object :scs (descriptor-reg))
(index :scs (any-reg))
(value :scs (complex-single-reg) :target result))
(:arg-types simple-array-complex-single-float positive-fixnum
complex-single-float)
(:results (result :scs (complex-single-reg)))
(:result-types complex-single-float)
(:generator 5
(let ((value-real (complex-single-reg-real-tn value))
(result-real (complex-single-reg-real-tn result)))
(cond ((zerop (tn-offset value-real))
;; Value is in ST0
(inst fst (make-ea :dword :base object :index index :scale 2
:disp (- (* vm:vector-data-offset
vm:word-bytes)
vm:other-pointer-type)))
(unless (zerop (tn-offset result-real))
;; Value is in ST0 but not result.
(inst fst result-real)))
(t
;; Value is not in ST0.
(inst fxch value-real)
(inst fst (make-ea :dword :base object :index index :scale 2
:disp (- (* vm:vector-data-offset
vm:word-bytes)
vm:other-pointer-type)))
(cond ((zerop (tn-offset result-real))
;; The result is in ST0.
(inst fst value-real))
(t
;; Neither value or result are in ST0
(unless (location= value-real result-real)
(inst fst result-real))
(inst fxch value-real))))))
(let ((value-imag (complex-single-reg-imag-tn value))
(result-imag (complex-single-reg-imag-tn result)))
(inst fxch value-imag)
(inst fst (make-ea :dword :base object :index index :scale 2
:disp (- (+ (* vm:vector-data-offset vm:word-bytes)
4)
vm:other-pointer-type)))
(unless (location= value-imag result-imag)
(inst fst result-imag))
(inst fxch value-imag))))
(define-vop (data-vector-set-c/simple-array-complex-single-float)
(:note "inline array store")
(:translate data-vector-set)
(:policy :fast-safe)
(:args (object :scs (descriptor-reg))
(value :scs (complex-single-reg) :target result))
(:info index)
(:arg-types simple-array-complex-single-float (:constant (signed-byte 30))
complex-single-float)
(:results (result :scs (complex-single-reg)))
(:result-types complex-single-float)
(:generator 4
(let ((value-real (complex-single-reg-real-tn value))
(result-real (complex-single-reg-real-tn result)))
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
(cond ((zerop (tn-offset value-real))
;; Value is in ST0
(inst fst (make-ea :dword :base object
:disp (- (+ (* vm:vector-data-offset
vm:word-bytes)
(* 8 index))
vm:other-pointer-type)))
(unless (zerop (tn-offset result-real))
;; Value is in ST0 but not result.
(inst fst result-real)))
(t
;; Value is not in ST0.
(inst fxch value-real)
(inst fst (make-ea :dword :base object
:disp (- (+ (* vm:vector-data-offset
vm:word-bytes)
(* 8 index))
vm:other-pointer-type)))
(cond ((zerop (tn-offset result-real))
;; The result is in ST0.
(inst fst value-real))
(t
;; Neither value or result are in ST0
(unless (location= value-real result-real)
(inst fst result-real))
(inst fxch value-real))))))
(let ((value-imag (complex-single-reg-imag-tn value))
(result-imag (complex-single-reg-imag-tn result)))
(inst fxch value-imag)
(inst fst (make-ea :dword :base object
:disp (- (+ (* vm:vector-data-offset vm:word-bytes)
(* 8 index) 4)
vm:other-pointer-type)))
(unless (location= value-imag result-imag)
(inst fst result-imag))
(inst fxch value-imag))))
(define-vop (data-vector-ref/simple-array-complex-double-float)
(:note "inline array access")
(:translate data-vector-ref)
(:policy :fast-safe)
(:args (object :scs (descriptor-reg))
(index :scs (any-reg)))
(:arg-types simple-array-complex-double-float positive-fixnum)
(:results (value :scs (complex-double-reg)))
(:result-types complex-double-float)
(:generator 7
(let ((real-tn (complex-double-reg-real-tn value)))
(with-empty-tn@fp-top (real-tn)
(inst fldd (make-ea :dword :base object :index index :scale 4
:disp (- (* vm:vector-data-offset vm:word-bytes)
vm:other-pointer-type)))))
(let ((imag-tn (complex-double-reg-imag-tn value)))
(with-empty-tn@fp-top (imag-tn)
(inst fldd (make-ea :dword :base object :index index :scale 4
:disp (- (+ (* vm:vector-data-offset vm:word-bytes)
8)
vm:other-pointer-type)))))))
(define-vop (data-vector-ref-c/simple-array-complex-double-float)
(:note "inline array access")
(:translate data-vector-ref)
(:policy :fast-safe)
(:args (object :scs (descriptor-reg)))
(:info index)
(:arg-types simple-array-complex-double-float (:constant (signed-byte 30)))
(:results (value :scs (complex-double-reg)))
(:result-types complex-double-float)
(:generator 6
(let ((real-tn (complex-double-reg-real-tn value)))
(with-empty-tn@fp-top (real-tn)
(inst fldd (make-ea :dword :base object
:disp (- (+ (* vm:vector-data-offset vm:word-bytes)
(* 16 index))
vm:other-pointer-type)))))
(let ((imag-tn (complex-double-reg-imag-tn value)))
(with-empty-tn@fp-top (imag-tn)
(inst fldd (make-ea :dword :base object
:disp (- (+ (* vm:vector-data-offset vm:word-bytes)
(* 16 index) 8)
vm:other-pointer-type)))))))
(define-vop (data-vector-set/simple-array-complex-double-float)
(:note "inline array store")
(:translate data-vector-set)
(:policy :fast-safe)
(:args (object :scs (descriptor-reg))
(index :scs (any-reg))
(value :scs (complex-double-reg) :target result))
(:arg-types simple-array-complex-double-float positive-fixnum
complex-double-float)
(:results (result :scs (complex-double-reg)))
(:result-types complex-double-float)
(:generator 20
(let ((value-real (complex-double-reg-real-tn value))
(result-real (complex-double-reg-real-tn result)))
(cond ((zerop (tn-offset value-real))
;; Value is in ST0
(inst fstd (make-ea :dword :base object :index index :scale 4
:disp (- (* vm:vector-data-offset
vm:word-bytes)
vm:other-pointer-type)))
(unless (zerop (tn-offset result-real))
;; Value is in ST0 but not result.
(inst fstd result-real)))
(t
;; Value is not in ST0.
(inst fxch value-real)
(inst fstd (make-ea :dword :base object :index index :scale 4
:disp (- (* vm:vector-data-offset
vm:word-bytes)
vm:other-pointer-type)))
(cond ((zerop (tn-offset result-real))
;; The result is in ST0.
(inst fstd value-real))
(t
;; Neither value or result are in ST0
(unless (location= value-real result-real)
(inst fstd result-real))
(inst fxch value-real))))))
(let ((value-imag (complex-double-reg-imag-tn value))
(result-imag (complex-double-reg-imag-tn result)))
(inst fxch value-imag)
(inst fstd (make-ea :dword :base object :index index :scale 4
:disp (- (+ (* vm:vector-data-offset vm:word-bytes)
8)
vm:other-pointer-type)))
(unless (location= value-imag result-imag)
(inst fstd result-imag))
(inst fxch value-imag))))
(define-vop (data-vector-set-c/simple-array-complex-double-float)
(:note "inline array store")
(:translate data-vector-set)
(:policy :fast-safe)
(:args (object :scs (descriptor-reg))
(value :scs (complex-double-reg) :target result))
(:info index)
(:arg-types simple-array-complex-double-float (:constant (signed-byte 30))
complex-double-float)
(:results (result :scs (complex-double-reg)))
(:result-types complex-double-float)
(:generator 19
(let ((value-real (complex-double-reg-real-tn value))
(result-real (complex-double-reg-real-tn result)))
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
(cond ((zerop (tn-offset value-real))
;; Value is in ST0
(inst fstd (make-ea :dword :base object
:disp (- (+ (* vm:vector-data-offset
vm:word-bytes)
(* 16 index))
vm:other-pointer-type)))
(unless (zerop (tn-offset result-real))
;; Value is in ST0 but not result.
(inst fstd result-real)))
(t
;; Value is not in ST0.
(inst fxch value-real)
(inst fstd (make-ea :dword :base object
:disp (- (+ (* vm:vector-data-offset
vm:word-bytes)
(* 16 index))
vm:other-pointer-type)))
(cond ((zerop (tn-offset result-real))
;; The result is in ST0.
(inst fstd value-real))
(t
;; Neither value or result are in ST0
(unless (location= value-real result-real)
(inst fstd result-real))
(inst fxch value-real))))))
(let ((value-imag (complex-double-reg-imag-tn value))
(result-imag (complex-double-reg-imag-tn result)))
(inst fxch value-imag)
(inst fstd (make-ea :dword :base object
:disp (- (+ (* vm:vector-data-offset vm:word-bytes)
(* 16 index) 8)
vm:other-pointer-type)))
(unless (location= value-imag result-imag)
(inst fstd result-imag))
(inst fxch value-imag))))
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#+long-float
(define-vop (data-vector-ref/simple-array-complex-long-float)
(:note "inline array access")
(:translate data-vector-ref)
(:policy :fast-safe)
(:args (object :scs (descriptor-reg) :to :result)
(index :scs (any-reg)))
(:arg-types simple-array-complex-long-float positive-fixnum)
(:temporary (:sc any-reg :from :eval :to :result) temp)
(:results (value :scs (complex-long-reg)))
(:result-types complex-long-float)
(:generator 7
;; temp = 3 * index
(inst lea temp (make-ea :dword :base index :index index :scale 2))
(let ((real-tn (complex-long-reg-real-tn value)))
(with-empty-tn@fp-top (real-tn)
(inst fldl (make-ea :dword :base object :index temp :scale 2
:disp (- (* vm:vector-data-offset vm:word-bytes)
vm:other-pointer-type)))))
(let ((imag-tn (complex-long-reg-imag-tn value)))
(with-empty-tn@fp-top (imag-tn)
(inst fldl (make-ea :dword :base object :index temp :scale 2
:disp (- (+ (* vm:vector-data-offset vm:word-bytes)
12)
vm:other-pointer-type)))))))
#+long-float
(define-vop (data-vector-ref-c/simple-array-complex-long-float)
(:note "inline array access")
(:translate data-vector-ref)
(:policy :fast-safe)
(:args (object :scs (descriptor-reg)))
(:info index)
(:arg-types simple-array-complex-long-float (:constant (signed-byte 30)))
(:results (value :scs (complex-long-reg)))
(:result-types complex-long-float)
(:generator 6
(let ((real-tn (complex-long-reg-real-tn value)))
(with-empty-tn@fp-top (real-tn)
(inst fldl (make-ea :dword :base object
:disp (- (+ (* vm:vector-data-offset vm:word-bytes)
(* 24 index))
vm:other-pointer-type)))))
(let ((imag-tn (complex-long-reg-imag-tn value)))
(with-empty-tn@fp-top (imag-tn)
(inst fldl (make-ea :dword :base object
:disp (- (+ (* vm:vector-data-offset vm:word-bytes)
(* 24 index) 12)
vm:other-pointer-type)))))))
#+long-float
(define-vop (data-vector-set/simple-array-complex-long-float)
(:note "inline array store")
(:translate data-vector-set)
(:policy :fast-safe)
(:args (object :scs (descriptor-reg) :to :result)
(index :scs (any-reg))
(value :scs (complex-long-reg) :target result))
(:arg-types simple-array-complex-long-float positive-fixnum
complex-long-float)
(:temporary (:sc any-reg :from (:argument 1) :to :result) temp)
(:results (result :scs (complex-long-reg)))
(:result-types complex-long-float)
(:generator 20
;; temp = 3 * index
(inst lea temp (make-ea :dword :base index :index index :scale 2))
(let ((value-real (complex-long-reg-real-tn value))
(result-real (complex-long-reg-real-tn result)))
(cond ((zerop (tn-offset value-real))
;; Value is in ST0
(store-long-float
(make-ea :dword :base object :index temp :scale 2
:disp (- (* vm:vector-data-offset vm:word-bytes)
vm:other-pointer-type)))
(unless (zerop (tn-offset result-real))
;; Value is in ST0 but not result.
(inst fstd result-real)))
(t
;; Value is not in ST0.
(inst fxch value-real)
(store-long-float
(make-ea :dword :base object :index temp :scale 2
:disp (- (* vm:vector-data-offset vm:word-bytes)
vm:other-pointer-type)))
(cond ((zerop (tn-offset result-real))
;; The result is in ST0.
(inst fstd value-real))
(t
;; Neither value or result are in ST0
(unless (location= value-real result-real)
(inst fstd result-real))
(inst fxch value-real))))))
(let ((value-imag (complex-long-reg-imag-tn value))
(result-imag (complex-long-reg-imag-tn result)))
(inst fxch value-imag)
(store-long-float
(make-ea :dword :base object :index temp :scale 2
:disp (- (+ (* vm:vector-data-offset vm:word-bytes) 12)
vm:other-pointer-type)))
(unless (location= value-imag result-imag)