-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathccl.lisp
63 lines (52 loc) · 1.74 KB
/
ccl.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
;;; -*- Mode: Lisp; indent-tabs-mode: nil -*-
(in-package :ccl)
#+(or x8632-target x8664-target)
(defx8632lapfunction swap-bytes::%swap-bytes-16 ((fixnum arg_z))
(unbox-fixnum fixnum imm0)
(xchg (% ah) (% al))
(box-fixnum imm0 fixnum)
(single-value-return))
#+x8632-target
(defx8632lapfunction swap-bytes::%swap-bytes-32 ((number arg_z))
; Extract the u32 from the number, swap the bytes, make and return
; a bignum.
(save-simple-frame)
(call-subprim .SPgetu32)
(bswapl (% imm0))
(restore-simple-frame)
(jmp-subprim .SPmakeu32))
#+x8664-target
(defx86lapfunction swap-bytes::%swap-bytes-32 ((fixnum arg_z))
(unbox-fixnum fixnum imm0)
(bswapl (% eax))
(box-fixnum imm0 fixnum)
(single-value-return))
#+x8632-target
(defun swap-bytes::%swap-bytes-64 (integer)
(declare (type (unsigned-byte 64) integer)
(optimize (speed 3) (safety 0) (debug 0)))
(logior
(swap-bytes:swap-bytes-32 (ldb (byte 32 32) integer))
(ash (swap-bytes:swap-bytes-32 (ldb (byte 32 0) integer)) 32)))
#+x8664-target
(defx86lapfunction swap-bytes::%swap-bytes-64 ((number arg_z))
; Extract the u64 from the number (either a fixnum or bignum), swap the
; bytes, make and return a bignum.
(save-simple-frame)
(call-subprim .SPgetu64)
(bswapq (% imm0))
(restore-simple-frame)
(jmp-subprim .SPmakeu64))
(in-package :swap-bytes)
(declaim (inline swap-bytes-16))
(defun swap-bytes-16 (integer)
(declare (type (unsigned-byte 16) integer))
(%swap-bytes-16 integer))
(declaim (inline swap-bytes-32))
(defun swap-bytes-32 (integer)
(declare (type (unsigned-byte 32) integer))
(%swap-bytes-32 integer))
(declaim (inline swap-bytes-64))
(defun swap-bytes-64 (integer)
(declare (type (unsigned-byte 64) integer))
(%swap-bytes-64 integer))