root/ext/uvector/uvector.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. uvector_index
  2. Scm_UVectorElementSize
  3. Scm_MakeUVectorFull
  4. Scm_MakeUVector
  5. Scm_UVectorAlias
  6. size_mismatch
  7. ARGTYPE_UVECTOR
  8. ARGTYPE_VECTOR
  9. ARGTYPE_LIST
  10. ARGTYPE_CONST
  11. ArgType
  12. arg2_check
  13. int64eqv
  14. uint64eqv
  15. int64print
  16. uint64print
  17. s8g_add
  18. s8g_sub
  19. s8g_mul
  20. u8g_add
  21. u8g_sub
  22. u8g_mul
  23. s16g_add
  24. s16g_sub
  25. s16g_mul
  26. u16g_add
  27. u16g_sub
  28. u16g_mul
  29. s32_add_safe
  30. s32_sub_safe
  31. s32_mul_safe
  32. u32_add_safe
  33. u32_sub_safe
  34. u32_mul_safe
  35. s64g_add
  36. s64g_sub
  37. s64g_mul
  38. u64g_add
  39. u64g_sub
  40. u64g_mul
  41. s8num
  42. u8num
  43. s64num
  44. u64num
  45. bitext
  46. bitext64
  47. s8muladd
  48. s32muladd
  49. s64muladd
  50. u8muladd
  51. u32muladd
  52. u64muladd
  53. swapb16
  54. swapb32
  55. swapb64
  56. print_s8vector
  57. compare_s8vector
  58. make_s8vector
  59. Scm_MakeS8Vector
  60. Scm_MakeS8VectorFromArray
  61. Scm_MakeS8VectorFromArrayShared
  62. Scm_ListToS8Vector
  63. Scm_VectorToS8Vector
  64. Scm_S8VectorFill
  65. Scm_S8VectorRef
  66. Scm_S8VectorSet
  67. Scm_S8VectorToList
  68. Scm_S8VectorToVector
  69. Scm_S8VectorCopy
  70. Scm_S8VectorCopyX
  71. print_u8vector
  72. compare_u8vector
  73. make_u8vector
  74. Scm_MakeU8Vector
  75. Scm_MakeU8VectorFromArray
  76. Scm_MakeU8VectorFromArrayShared
  77. Scm_ListToU8Vector
  78. Scm_VectorToU8Vector
  79. Scm_U8VectorFill
  80. Scm_U8VectorRef
  81. Scm_U8VectorSet
  82. Scm_U8VectorToList
  83. Scm_U8VectorToVector
  84. Scm_U8VectorCopy
  85. Scm_U8VectorCopyX
  86. print_s16vector
  87. compare_s16vector
  88. make_s16vector
  89. Scm_MakeS16Vector
  90. Scm_MakeS16VectorFromArray
  91. Scm_MakeS16VectorFromArrayShared
  92. Scm_ListToS16Vector
  93. Scm_VectorToS16Vector
  94. Scm_S16VectorFill
  95. Scm_S16VectorRef
  96. Scm_S16VectorSet
  97. Scm_S16VectorToList
  98. Scm_S16VectorToVector
  99. Scm_S16VectorCopy
  100. Scm_S16VectorCopyX
  101. print_u16vector
  102. compare_u16vector
  103. make_u16vector
  104. Scm_MakeU16Vector
  105. Scm_MakeU16VectorFromArray
  106. Scm_MakeU16VectorFromArrayShared
  107. Scm_ListToU16Vector
  108. Scm_VectorToU16Vector
  109. Scm_U16VectorFill
  110. Scm_U16VectorRef
  111. Scm_U16VectorSet
  112. Scm_U16VectorToList
  113. Scm_U16VectorToVector
  114. Scm_U16VectorCopy
  115. Scm_U16VectorCopyX
  116. print_s32vector
  117. compare_s32vector
  118. make_s32vector
  119. Scm_MakeS32Vector
  120. Scm_MakeS32VectorFromArray
  121. Scm_MakeS32VectorFromArrayShared
  122. Scm_ListToS32Vector
  123. Scm_VectorToS32Vector
  124. Scm_S32VectorFill
  125. Scm_S32VectorRef
  126. Scm_S32VectorSet
  127. Scm_S32VectorToList
  128. Scm_S32VectorToVector
  129. Scm_S32VectorCopy
  130. Scm_S32VectorCopyX
  131. print_u32vector
  132. compare_u32vector
  133. make_u32vector
  134. Scm_MakeU32Vector
  135. Scm_MakeU32VectorFromArray
  136. Scm_MakeU32VectorFromArrayShared
  137. Scm_ListToU32Vector
  138. Scm_VectorToU32Vector
  139. Scm_U32VectorFill
  140. Scm_U32VectorRef
  141. Scm_U32VectorSet
  142. Scm_U32VectorToList
  143. Scm_U32VectorToVector
  144. Scm_U32VectorCopy
  145. Scm_U32VectorCopyX
  146. print_s64vector
  147. compare_s64vector
  148. make_s64vector
  149. Scm_MakeS64Vector
  150. Scm_MakeS64VectorFromArray
  151. Scm_MakeS64VectorFromArrayShared
  152. Scm_ListToS64Vector
  153. Scm_VectorToS64Vector
  154. Scm_S64VectorFill
  155. Scm_S64VectorRef
  156. Scm_S64VectorSet
  157. Scm_S64VectorToList
  158. Scm_S64VectorToVector
  159. Scm_S64VectorCopy
  160. Scm_S64VectorCopyX
  161. print_u64vector
  162. compare_u64vector
  163. make_u64vector
  164. Scm_MakeU64Vector
  165. Scm_MakeU64VectorFromArray
  166. Scm_MakeU64VectorFromArrayShared
  167. Scm_ListToU64Vector
  168. Scm_VectorToU64Vector
  169. Scm_U64VectorFill
  170. Scm_U64VectorRef
  171. Scm_U64VectorSet
  172. Scm_U64VectorToList
  173. Scm_U64VectorToVector
  174. Scm_U64VectorCopy
  175. Scm_U64VectorCopyX
  176. print_f32vector
  177. compare_f32vector
  178. make_f32vector
  179. Scm_MakeF32Vector
  180. Scm_MakeF32VectorFromArray
  181. Scm_MakeF32VectorFromArrayShared
  182. Scm_ListToF32Vector
  183. Scm_VectorToF32Vector
  184. Scm_F32VectorFill
  185. Scm_F32VectorRef
  186. Scm_F32VectorSet
  187. Scm_F32VectorToList
  188. Scm_F32VectorToVector
  189. Scm_F32VectorCopy
  190. Scm_F32VectorCopyX
  191. print_f64vector
  192. compare_f64vector
  193. make_f64vector
  194. Scm_MakeF64Vector
  195. Scm_MakeF64VectorFromArray
  196. Scm_MakeF64VectorFromArrayShared
  197. Scm_ListToF64Vector
  198. Scm_VectorToF64Vector
  199. Scm_F64VectorFill
  200. Scm_F64VectorRef
  201. Scm_F64VectorSet
  202. Scm_F64VectorToList
  203. Scm_F64VectorToVector
  204. Scm_F64VectorCopy
  205. Scm_F64VectorCopyX
  206. s8vector_add
  207. Scm_S8VectorAdd
  208. Scm_S8VectorAddX
  209. u8vector_add
  210. Scm_U8VectorAdd
  211. Scm_U8VectorAddX
  212. s16vector_add
  213. Scm_S16VectorAdd
  214. Scm_S16VectorAddX
  215. u16vector_add
  216. Scm_U16VectorAdd
  217. Scm_U16VectorAddX
  218. s32vector_add
  219. Scm_S32VectorAdd
  220. Scm_S32VectorAddX
  221. u32vector_add
  222. Scm_U32VectorAdd
  223. Scm_U32VectorAddX
  224. s64vector_add
  225. Scm_S64VectorAdd
  226. Scm_S64VectorAddX
  227. u64vector_add
  228. Scm_U64VectorAdd
  229. Scm_U64VectorAddX
  230. f32vector_add
  231. Scm_F32VectorAdd
  232. Scm_F32VectorAddX
  233. f64vector_add
  234. Scm_F64VectorAdd
  235. Scm_F64VectorAddX
  236. s8vector_sub
  237. Scm_S8VectorSub
  238. Scm_S8VectorSubX
  239. u8vector_sub
  240. Scm_U8VectorSub
  241. Scm_U8VectorSubX
  242. s16vector_sub
  243. Scm_S16VectorSub
  244. Scm_S16VectorSubX
  245. u16vector_sub
  246. Scm_U16VectorSub
  247. Scm_U16VectorSubX
  248. s32vector_sub
  249. Scm_S32VectorSub
  250. Scm_S32VectorSubX
  251. u32vector_sub
  252. Scm_U32VectorSub
  253. Scm_U32VectorSubX
  254. s64vector_sub
  255. Scm_S64VectorSub
  256. Scm_S64VectorSubX
  257. u64vector_sub
  258. Scm_U64VectorSub
  259. Scm_U64VectorSubX
  260. f32vector_sub
  261. Scm_F32VectorSub
  262. Scm_F32VectorSubX
  263. f64vector_sub
  264. Scm_F64VectorSub
  265. Scm_F64VectorSubX
  266. s8vector_mul
  267. Scm_S8VectorMul
  268. Scm_S8VectorMulX
  269. u8vector_mul
  270. Scm_U8VectorMul
  271. Scm_U8VectorMulX
  272. s16vector_mul
  273. Scm_S16VectorMul
  274. Scm_S16VectorMulX
  275. u16vector_mul
  276. Scm_U16VectorMul
  277. Scm_U16VectorMulX
  278. s32vector_mul
  279. Scm_S32VectorMul
  280. Scm_S32VectorMulX
  281. u32vector_mul
  282. Scm_U32VectorMul
  283. Scm_U32VectorMulX
  284. s64vector_mul
  285. Scm_S64VectorMul
  286. Scm_S64VectorMulX
  287. u64vector_mul
  288. Scm_U64VectorMul
  289. Scm_U64VectorMulX
  290. f32vector_mul
  291. Scm_F32VectorMul
  292. Scm_F32VectorMulX
  293. f64vector_mul
  294. Scm_F64VectorMul
  295. Scm_F64VectorMulX
  296. f32vector_div
  297. Scm_F32VectorDiv
  298. Scm_F32VectorDivX
  299. f64vector_div
  300. Scm_F64VectorDiv
  301. Scm_F64VectorDivX
  302. s8vector_and
  303. Scm_S8VectorAnd
  304. Scm_S8VectorAndX
  305. s8vector_ior
  306. Scm_S8VectorIor
  307. Scm_S8VectorIorX
  308. s8vector_xor
  309. Scm_S8VectorXor
  310. Scm_S8VectorXorX
  311. u8vector_and
  312. Scm_U8VectorAnd
  313. Scm_U8VectorAndX
  314. u8vector_ior
  315. Scm_U8VectorIor
  316. Scm_U8VectorIorX
  317. u8vector_xor
  318. Scm_U8VectorXor
  319. Scm_U8VectorXorX
  320. s16vector_and
  321. Scm_S16VectorAnd
  322. Scm_S16VectorAndX
  323. s16vector_ior
  324. Scm_S16VectorIor
  325. Scm_S16VectorIorX
  326. s16vector_xor
  327. Scm_S16VectorXor
  328. Scm_S16VectorXorX
  329. u16vector_and
  330. Scm_U16VectorAnd
  331. Scm_U16VectorAndX
  332. u16vector_ior
  333. Scm_U16VectorIor
  334. Scm_U16VectorIorX
  335. u16vector_xor
  336. Scm_U16VectorXor
  337. Scm_U16VectorXorX
  338. s32vector_and
  339. Scm_S32VectorAnd
  340. Scm_S32VectorAndX
  341. s32vector_ior
  342. Scm_S32VectorIor
  343. Scm_S32VectorIorX
  344. s32vector_xor
  345. Scm_S32VectorXor
  346. Scm_S32VectorXorX
  347. u32vector_and
  348. Scm_U32VectorAnd
  349. Scm_U32VectorAndX
  350. u32vector_ior
  351. Scm_U32VectorIor
  352. Scm_U32VectorIorX
  353. u32vector_xor
  354. Scm_U32VectorXor
  355. Scm_U32VectorXorX
  356. s64vector_and
  357. Scm_S64VectorAnd
  358. Scm_S64VectorAndX
  359. s64vector_ior
  360. Scm_S64VectorIor
  361. Scm_S64VectorIorX
  362. s64vector_xor
  363. Scm_S64VectorXor
  364. Scm_S64VectorXorX
  365. u64vector_and
  366. Scm_U64VectorAnd
  367. Scm_U64VectorAndX
  368. u64vector_ior
  369. Scm_U64VectorIor
  370. Scm_U64VectorIorX
  371. u64vector_xor
  372. Scm_U64VectorXor
  373. Scm_U64VectorXorX
  374. Scm_S8VectorDotProd
  375. Scm_U8VectorDotProd
  376. Scm_S16VectorDotProd
  377. Scm_U16VectorDotProd
  378. Scm_S32VectorDotProd
  379. Scm_U32VectorDotProd
  380. Scm_S64VectorDotProd
  381. Scm_U64VectorDotProd
  382. Scm_F32VectorDotProd
  383. Scm_F64VectorDotProd
  384. Scm_S8VectorRangeCheck
  385. Scm_S8VectorClamp
  386. Scm_S8VectorClampX
  387. Scm_U8VectorRangeCheck
  388. Scm_U8VectorClamp
  389. Scm_U8VectorClampX
  390. Scm_S16VectorRangeCheck
  391. Scm_S16VectorClamp
  392. Scm_S16VectorClampX
  393. Scm_U16VectorRangeCheck
  394. Scm_U16VectorClamp
  395. Scm_U16VectorClampX
  396. Scm_S32VectorRangeCheck
  397. Scm_S32VectorClamp
  398. Scm_S32VectorClampX
  399. Scm_U32VectorRangeCheck
  400. Scm_U32VectorClamp
  401. Scm_U32VectorClampX
  402. Scm_S64VectorRangeCheck
  403. Scm_S64VectorClamp
  404. Scm_S64VectorClampX
  405. Scm_U64VectorRangeCheck
  406. Scm_U64VectorClamp
  407. Scm_U64VectorClampX
  408. Scm_F32VectorRangeCheck
  409. Scm_F32VectorClamp
  410. Scm_F32VectorClampX
  411. Scm_F64VectorRangeCheck
  412. Scm_F64VectorClamp
  413. Scm_F64VectorClampX
  414. s16vector_swapb
  415. Scm_S16VectorSwapBytes
  416. Scm_S16VectorSwapBytesX
  417. u16vector_swapb
  418. Scm_U16VectorSwapBytes
  419. Scm_U16VectorSwapBytesX
  420. s32vector_swapb
  421. Scm_S32VectorSwapBytes
  422. Scm_S32VectorSwapBytesX
  423. u32vector_swapb
  424. Scm_U32VectorSwapBytes
  425. Scm_U32VectorSwapBytesX
  426. s64vector_swapb
  427. Scm_S64VectorSwapBytes
  428. Scm_S64VectorSwapBytesX
  429. u64vector_swapb
  430. Scm_U64VectorSwapBytes
  431. Scm_U64VectorSwapBytesX
  432. f32vector_swapb
  433. Scm_F32VectorSwapBytes
  434. Scm_F32VectorSwapBytesX
  435. f64vector_swapb
  436. Scm_F64VectorSwapBytes
  437. Scm_F64VectorSwapBytesX
  438. Scm_UVectorCopy
  439. Scm_UVectorSwapBytes
  440. Scm_UVectorSwapBytesX
  441. endian_check
  442. Scm_ReadBlockX
  443. Scm_WriteBlock

   1 /*
   2  * uvector.c.tmpl - uniform vector support code template
   3  *
   4  *   Copyright (c) 1999-2004 Shiro Kawai, All rights reserved.
   5  * 
   6  *   Redistribution and use in source and binary forms, with or without
   7  *   modification, are permitted provided that the following conditions
   8  *   are met:
   9  * 
  10  *   1. Redistributions of source code must retain the above copyright
  11  *      notice, this list of conditions and the following disclaimer.
  12  *
  13  *   2. Redistributions in binary form must reproduce the above copyright
  14  *      notice, this list of conditions and the following disclaimer in the
  15  *      documentation and/or other materials provided with the distribution.
  16  *
  17  *   3. Neither the name of the authors nor the names of its contributors
  18  *      may be used to endorse or promote products derived from this
  19  *      software without specific prior written permission.
  20  *
  21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  27  *   TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28  *   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29  *   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30  *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  31  *   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32  *
  33  *  $Id: uvector.c.tmpl,v 1.6 2005/06/23 04:18:21 shirok Exp $
  34  */
  35 
  36 #include <stdlib.h>
  37 #include <math.h>
  38 #include <limits.h>
  39 #include <string.h>  /* for memcpy() */
  40 #include <gauche.h>
  41 #include <gauche/extend.h>
  42 #include <gauche/builtin-syms.h>
  43 #include "gauche/uvector.h"
  44 #include "gauche/arith.h"
  45 #include "gauche/scmconst.h"
  46 
  47 #include "uvectorP.h"
  48 
  49 static ScmClass *uvector_cpl[] = {
  50     SCM_CLASS_STATIC_PTR(Scm_UVectorClass),
  51     SCM_CLASS_STATIC_PTR(Scm_SequenceClass),
  52     SCM_CLASS_STATIC_PTR(Scm_CollectionClass),
  53     SCM_CLASS_STATIC_PTR(Scm_TopClass),
  54     NULL
  55 };
  56 
  57 SCM_DEFINE_BUILTIN_CLASS(Scm_UVectorClass, NULL, NULL, NULL, NULL,
  58                          uvector_cpl+1);
  59 
  60 static int uvector_index(ScmClass *klass)
  61 {
  62     if (SCM_EQ(klass, SCM_CLASS_S8VECTOR))  return 0;
  63     if (SCM_EQ(klass, SCM_CLASS_U8VECTOR))  return 1;
  64     if (SCM_EQ(klass, SCM_CLASS_S16VECTOR)) return 2;
  65     if (SCM_EQ(klass, SCM_CLASS_U16VECTOR)) return 3;
  66     if (SCM_EQ(klass, SCM_CLASS_S32VECTOR)) return 4;
  67     if (SCM_EQ(klass, SCM_CLASS_U32VECTOR)) return 5;
  68     if (SCM_EQ(klass, SCM_CLASS_S64VECTOR)) return 6;
  69     if (SCM_EQ(klass, SCM_CLASS_U64VECTOR)) return 7;
  70     if (SCM_EQ(klass, SCM_CLASS_F32VECTOR)) return 8;
  71     if (SCM_EQ(klass, SCM_CLASS_F64VECTOR)) return 9;
  72     else return -1;
  73 }
  74 
  75 /* Returns the size of element of the uvector of given class */
  76 int Scm_UVectorElementSize(ScmClass *klass)
  77 {
  78     static int sizes[] = { 1, 1, 2, 2, 4, 4, 8, 8,
  79                            sizeof(float), sizeof(double) };
  80     int ind = uvector_index(klass);
  81     if (ind >= 0) return sizes[ind];
  82     return -1;
  83 }
  84 
  85 /* Generic constructor */
  86 ScmObj Scm_MakeUVectorFull(ScmClass *klass, int size, void *init, int immutable, void *owner)
  87 {
  88     ScmUVector *vec;
  89     int eltsize = Scm_UVectorElementSize(klass);
  90     SCM_ASSERT(eltsize >= 1);
  91     vec = SCM_NEW(ScmUVector);
  92     SCM_SET_CLASS(vec, klass);
  93     if (init) {
  94         vec->elements = init;   /* trust the caller */
  95     } else {
  96         vec->elements = SCM_NEW_ATOMIC2(void*, size*eltsize);
  97     }
  98     vec->size = size;
  99     vec->immutable = immutable;
 100     vec->owner = owner;
 101     return SCM_OBJ(vec);
 102 }
 103 
 104 ScmObj Scm_MakeUVector(ScmClass *klass, int size, void *init)
 105 {
 106     return Scm_MakeUVectorFull(klass, size, init, FALSE, NULL);
 107 }
 108 
 109 /*
 110  * Generic aliasing
 111  */
 112 ScmObj Scm_UVectorAlias(ScmClass *klass, ScmUVector *v, int start, int end)
 113 {
 114     int len = SCM_UVECTOR_SIZE(v), reqalign, srcalign, dstsize;
 115 
 116     SCM_CHECK_START_END(start, end, len);
 117     reqalign = Scm_UVectorElementSize(klass);
 118     srcalign = Scm_UVectorElementSize(Scm_ClassOf(SCM_OBJ(v)));
 119     if (reqalign < 0) {
 120         Scm_Error("uvector-alias requires uniform vector class, but got %S",
 121                   klass);
 122     }
 123     if ((start*srcalign)%reqalign != 0 || (end*srcalign)%reqalign != 0) {
 124         Scm_Error("aliasing %S of range (%d, %d) to %S doesn't satisfy alignemnt requirement.",
 125                   Scm_ClassOf(SCM_OBJ(v)), start, end, klass);
 126     }
 127     if (reqalign >= srcalign) dstsize = (end-start) / (reqalign/srcalign);
 128     else dstsize = (end-start) * (srcalign/reqalign);
 129     SCM_RETURN(Scm_MakeUVectorFull(klass,
 130                                    dstsize,
 131                                    (char*)v->elements + start*srcalign,
 132                                    SCM_UVECTOR_IMMUTABLE_P(v),
 133                                    SCM_UVECTOR_OWNER(v)));
 134 }
 135 
 136 /*===========================================================
 137  * Helper functions
 138  */
 139 
 140 static void size_mismatch(const char *name, ScmObj x, ScmObj y)
 141 {
 142     Scm_Error("%s: argument object sizes do not match: %S vs %S", name, x, y);
 143 }
 144 
 145 /* many numeric op procedures takes either uvector, vector, list or
 146    a constant number as the second arg.  this factors out the common
 147    code. */
 148 typedef enum {
 149     ARGTYPE_UVECTOR,
 150     ARGTYPE_VECTOR,
 151     ARGTYPE_LIST,
 152     ARGTYPE_CONST
 153 } ArgType;
 154 
 155 static ArgType arg2_check(const char *name, ScmObj x, ScmObj y, int const_ok)
 156 {
 157     int size = SCM_UVECTOR_SIZE(x);
 158     if (SCM_UVECTORP(y)) {
 159         if (SCM_UVECTOR_SIZE(y) != size) size_mismatch(name, SCM_OBJ(x), y);
 160         return ARGTYPE_UVECTOR;
 161     } else if (SCM_VECTORP(y)) {
 162         if (SCM_VECTOR_SIZE(y) != size) size_mismatch(name, SCM_OBJ(x), y);
 163         return ARGTYPE_VECTOR;
 164     } else if (SCM_LISTP(y)) {
 165         if (Scm_Length(y) != size) size_mismatch(name, SCM_OBJ(x), y);
 166         return ARGTYPE_LIST;
 167     } else if (!const_ok) {
 168         Scm_Error("%s: second operand must be either a matching uvector, a vector, or a list, but got %S", y);
 169     } else if (!SCM_REALP(y)) {
 170         Scm_Error("%s: second operand must be either a matching uvector, a vector, a list or a number, but got %S", y);
 171     }
 172     return ARGTYPE_CONST;
 173 }
 174 
 175 /*--------------------------------------------------------
 176  * Comparison and print
 177  */
 178 static inline int int64eqv(ScmInt64 x, ScmInt64 y)
 179 {
 180 #if SCM_EMULATE_INT64
 181     return (x.hi == y.hi && x.lo == y.lo);
 182 #else
 183     return x == y;
 184 #endif
 185 }
 186 
 187 static inline int uint64eqv(ScmUInt64 x, ScmUInt64 y)
 188 {
 189 #if SCM_EMULATE_INT64
 190     return (x.hi == y.hi && x.lo == y.lo);
 191 #else
 192     return x == y;
 193 #endif
 194 }
 195 
 196 static inline void int64print(ScmPort *out, ScmInt64 v)
 197 {
 198 #if SCM_EMULATE_INT64
 199     Scm_Printf(out, "%S", Scm_MakeInteger64(v));
 200 #elif SIZEOF_LONG == 4
 201     char buf[50];
 202     snprintf(buf, 50, "%lld", v);
 203     Scm_Printf(out, "%s", buf);
 204 #else
 205     Scm_Printf(out, "%ld", v);
 206 #endif
 207 }
 208 
 209 static inline void uint64print(ScmPort *out, ScmUInt64 v)
 210 {
 211 #if SCM_EMULATE_INT64
 212     Scm_Printf(out, "%S", Scm_MakeIntegerU64(v));
 213 #elif SIZEOF_LONG == 4
 214     char buf[50];
 215     snprintf(buf, 50, "%llu", v);
 216     Scm_Printf(out, "%s", buf);
 217 #else
 218     Scm_Printf(out, "%lu", v);
 219 #endif
 220 }
 221 
 222 /****** Add, sub, mul and div (f32 and f64 only) *****/
 223 #define s8s8_add(x, y, clamp)   clamp_s8(x+y, clamp)
 224 #define s8s8_sub(x, y, clamp)   clamp_s8(x-y, clamp)
 225 #define s8s8_mul(x, y, clamp)   clamp_s8(x*y, clamp)
 226 
 227 static inline long s8g_add(long x, long y, int clamp)
 228 {
 229     if (y > 255)  return range_s8hi(0, clamp);
 230     if (y < -256) return range_s8lo(0, clamp);
 231     return clamp_s8(x+y, clamp);
 232 }
 233 
 234 static inline long s8g_sub(long x, long y, int clamp)
 235 {
 236     if (y < -255) return range_s8hi(0, clamp);
 237     if (y > 256)  return range_s8lo(0, clamp);
 238     return clamp_s8(x-y, clamp);
 239 }
 240 
 241 static inline long s8g_mul(long x, long y, int clamp)
 242 {
 243     if (x == 0) return 0;
 244     if (y > 128) return (x>0)?range_s8hi(0, clamp):range_s8lo(0, clamp);
 245     return clamp_s8(x*y, clamp);
 246 }
 247 
 248 #define u8u8_add(x, y, clamp)   clamp_u8(x+y, clamp)
 249 #define u8u8_sub(x, y, clamp)   clamp_u8((long)(x-y), clamp)
 250 #define u8u8_mul(x, y, clamp)   clamp_u8(x*y, clamp)
 251 
 252 static inline u_long u8g_add(u_long x, u_long y, int clamp)
 253 {
 254     if (y > 255)  return range_u8hi(0, clamp);
 255     return clamp_u8(x+y, clamp);
 256 }
 257 
 258 static inline u_long u8g_sub(u_long x, u_long y, int clamp)
 259 {
 260     if (y > x)   return range_u8lo(0, clamp);
 261     return x-y;                 /* never overflows */
 262 }
 263 
 264 static inline u_long u8g_mul(u_long x, u_long y, int clamp)
 265 {
 266     if (x == 0) return 0;
 267     if (y > 255) return range_u8hi(0, clamp);
 268     return clamp_u8(x*y, clamp);
 269 }
 270 
 271 #define s16s16_add(x, y, clamp)   clamp_s16(x+y, clamp)
 272 #define s16s16_sub(x, y, clamp)   clamp_s16(x-y, clamp)
 273 #define s16s16_mul(x, y, clamp)   clamp_s16(x*y, clamp)
 274 
 275 static inline long s16g_add(long x, long y, int clamp)
 276 {
 277     if (y > 65535)  return range_s16hi(0, clamp);
 278     if (y < -65536) return range_s16lo(0, clamp);
 279     return clamp_s16(x+y, clamp);
 280 }
 281 
 282 static inline long s16g_sub(long x, long y, int clamp)
 283 {
 284     if (y < -65535) return range_s16hi(0, clamp);
 285     if (y > 65536)  return range_s16lo(0, clamp);
 286     return clamp_s16(x-y, clamp);
 287 }
 288 
 289 static inline long s16g_mul(long x, long y, int clamp)
 290 {
 291     if (x == 0) return 0;
 292     if (y > 32767) return (x>0)?range_s16hi(0, clamp):range_s16lo(0, clamp);
 293     return clamp_s16(x*y, clamp);
 294 }
 295 
 296 #define u16u16_add(x, y, clamp)   clamp_u16(x+y, clamp)
 297 #define u16u16_sub(x, y, clamp)   clamp_u16((long)(x-y), clamp)
 298 #define u16u16_mul(x, y, clamp)   clamp_u16(x*y, clamp)
 299 
 300 static inline u_long u16g_add(u_long x, u_long y, int clamp)
 301 {
 302     if (y > 65535)  return range_u16hi(0, clamp);
 303     return clamp_u16(x+y, clamp);
 304 }
 305 
 306 static inline u_long u16g_sub(u_long x, u_long y, int clamp)
 307 {
 308     if (y > x)   return range_u16lo(0, clamp);
 309     return x-y;                 /* never overflows */
 310 }
 311 
 312 static inline u_long u16g_mul(u_long x, u_long y, int clamp)
 313 {
 314     if (x == 0) return 0;
 315     if (y > 65535) return range_u16hi(0, clamp);
 316     return clamp_u16(x*y, clamp);
 317 }
 318 
 319 #if SIZEOF_LONG == 4
 320 #define s32s32_add(x, y, clamp)  s32_add_safe(x, y, clamp)
 321 #define s32s32_sub(x, y, clamp)  s32_sub_safe(x, y, clamp)
 322 #define s32s32_mul(x, y, clamp)  s32_mul_safe(x, y, clamp)
 323 #define s32g_add(x, y, clamp)    s32_add_safe(x, y, clamp)
 324 #define s32g_sub(x, y, clamp)    s32_sub_safe(x, y, clamp)
 325 #define s32g_mul(x, y, clamp)    s32_mul_safe(x, y, clamp)
 326 #else  /* SIZEOF_LONG >= 8 */
 327 #define s32s32_add(x, y, clamp)  clamp_s32(x+y, clamp)
 328 #define s32s32_sub(x, y, clamp)  clamp_s32(x-y, clamp)
 329 #define s32s32_mul(x, y, clamp)  clamp_s32(x*y, clamp)
 330 #define s32g_add(x, y, clamp)    s32_add_safe(x, y, clamp)
 331 #define s32g_sub(x, y, clamp)    s32_sub_safe(x, y, clamp)
 332 #define s32g_mul(x, y, clamp)    s32_mul_safe(x, y, clamp)
 333 #endif /* SIZEOF_LONG >= 8 */
 334 
 335 static inline long s32_add_safe(long x, long y, int clamp)
 336 {
 337     long r, v;
 338     SADDOV(r, v, x, y);
 339     if (v == 0) return clamp_s32(r, clamp);
 340     if (v > 0)  return range_s32hi(0, clamp);
 341     else        return range_s32lo(0, clamp);
 342 }
 343 
 344 
 345 static inline long s32_sub_safe(long x, long y, int clamp)
 346 {
 347     long r, v;
 348     SSUBOV(r, v, x, y);
 349     if (v == 0) return clamp_s32(r, clamp);
 350     if (v > 0)  return range_s32hi(0, clamp);
 351     else        return range_s32lo(0, clamp);
 352 }
 353 
 354 static inline long s32_mul_safe(long x, long y, int clamp)
 355 {
 356     long r, v;
 357     SMULOV(r, v, x, y);
 358     if (v == 0) return clamp_s32(r, clamp);
 359     if (v > 0)  return range_s32hi(0, clamp);
 360     else        return range_s32lo(0, clamp);
 361 }
 362 
 363 #if SIZEOF_LONG == 4
 364 #define u32u32_add(x, y, clamp)  u32_add_safe(x, y, clamp)
 365 #define u32u32_sub(x, y, clamp)  u32_sub_safe(x, y, clamp)
 366 #define u32u32_mul(x, y, clamp)  u32_mul_safe(x, y, clamp)
 367 #define u32g_add(x, y, clamp)    u32_add_safe(x, y, clamp)
 368 #define u32g_sub(x, y, clamp)    u32_sub_safe(x, y, clamp)
 369 #define u32g_mul(x, y, clamp)    u32_mul_safe(x, y, clamp)
 370 #else  /* SIZEOF_LONG >= 8 */
 371 #define u32u32_add(x, y, clamp)  clamp_u32(x+y, clamp)
 372 #define u32u32_sub(x, y, clamp)  u32_sub_safe(x, y, clamp)
 373 #define u32u32_mul(x, y, clamp)  clamp_u32(x*y, clamp)
 374 #define u32g_add(x, y, clamp)    u32_add_safe(x, y, clamp)
 375 #define u32g_sub(x, y, clamp)    u32_sub_safe(x, y, clamp)
 376 #define u32g_mul(x, y, clamp)    u32_mul_safe(x, y, clamp)
 377 #endif /* SIZEOF_LONG >= 8 */
 378 
 379 static inline u_long u32_add_safe(u_long x, u_long y, int clamp)
 380 {
 381     u_long r, v;
 382     UADDOV(r, v, x, y);
 383     if (v == 0) return clamp_u32(r, clamp);
 384     else        return range_u32hi(0, clamp);
 385 }
 386 
 387 static inline u_long u32_sub_safe(u_long x, u_long y, int clamp)
 388 {
 389     u_long r, v;
 390     USUBOV(r, v, x, y);
 391     if (v == 0) return clamp_u32(r, clamp);
 392     else        return range_u32lo(0, clamp);
 393 }
 394 
 395 static inline u_long u32_mul_safe(u_long x, u_long y, int clamp)
 396 {
 397     u_long r, v;
 398     UMULOV(r, v, x, y);
 399     if (v == 0) return clamp_u32(r, clamp);
 400     else        return range_u32hi(0, clamp);
 401 }
 402 
 403 #define s64s64_add(x, y, clamp)  s64g_add(x, y, clamp)
 404 #define s64s64_sub(x, y, clamp)  s64g_sub(x, y, clamp)
 405 #define s64s64_mul(x, y, clamp)  s64g_mul(x, y, clamp)
 406 
 407 static inline ScmInt64 s64g_add(ScmInt64 x, ScmInt64 y, int clamp)
 408 {
 409 #if SIZEOF_LONG == 4
 410     ScmObj xx = Scm_MakeInteger64(x);
 411     ScmObj yy = Scm_MakeInteger64(y);
 412     ScmObj r = Scm_Add2(xx, yy);
 413     return Scm_GetInteger64Clamp(r, clamp, NULL);
 414 #else
 415     long r, v;
 416     SADDOV(r, v, x, y);
 417     if (v == 0) return r;
 418     if (v > 0)  return range_s64hi(0, clamp);
 419     else        return range_s64lo(0, clamp);
 420 #endif
 421 }
 422 
 423 static inline ScmInt64 s64g_sub(ScmInt64 x, ScmInt64 y, int clamp)
 424 {
 425 #if SIZEOF_LONG == 4
 426     ScmObj xx = Scm_MakeInteger64(x);
 427     ScmObj yy = Scm_MakeInteger64(y);
 428     ScmObj r = Scm_Subtract2(xx, yy);
 429     return Scm_GetInteger64Clamp(r, clamp, NULL);
 430 #else
 431     long r, v;
 432     SSUBOV(r, v, x, y);
 433     if (v == 0) return r;
 434     if (v > 0)  return range_s64hi(0, clamp);
 435     else        return range_s64lo(0, clamp);
 436 #endif
 437 }
 438 
 439 static inline ScmInt64 s64g_mul(ScmInt64 x, ScmInt64 y, int clamp)
 440 {
 441 #if SIZEOF_LONG == 4
 442     ScmObj xx = Scm_MakeInteger64(x);
 443     ScmObj yy = Scm_MakeInteger64(y);
 444     ScmObj r = Scm_Multiply2(xx, yy);
 445     return Scm_GetInteger64Clamp(r, clamp, NULL);
 446 #else
 447     long r, v;
 448     SMULOV(r, v, x, y);
 449     if (v == 0) return r;
 450     if (v > 0)  return range_s64hi(0, clamp);
 451     else        return range_s64lo(0, clamp);
 452 #endif
 453 }
 454 
 455 #define u64u64_add(x, y, clamp)  u64g_add(x, y, clamp)
 456 #define u64u64_sub(x, y, clamp)  u64g_sub(x, y, clamp)
 457 #define u64u64_mul(x, y, clamp)  u64g_mul(x, y, clamp)
 458 
 459 static inline ScmUInt64 u64g_add(ScmUInt64 x, ScmUInt64 y, int clamp)
 460 {
 461 #if SIZEOF_LONG == 4
 462     ScmObj xx = Scm_MakeIntegerU64(x);
 463     ScmObj yy = Scm_MakeIntegerU64(y);
 464     ScmObj r = Scm_Add2(xx, yy);
 465     return Scm_GetIntegerU64Clamp(r, clamp, NULL);
 466 #else
 467     u_long r, v;
 468     UADDOV(r, v, x, y);
 469     if (v == 0) return r;
 470     else        return range_u64hi(0, clamp);
 471 #endif
 472 }
 473 
 474 static inline ScmUInt64 u64g_sub(ScmUInt64 x, ScmUInt64 y, int clamp)
 475 {
 476 #if SIZEOF_LONG == 4
 477     ScmObj xx = Scm_MakeIntegerU64(x);
 478     ScmObj yy = Scm_MakeIntegerU64(y);
 479     ScmObj r = Scm_Subtract2(xx, yy);
 480     return Scm_GetIntegerU64Clamp(r, clamp, NULL);
 481 #else
 482     u_long r, v;
 483     USUBOV(r, v, x, y);
 484     if (v == 0) return r;
 485     else        return range_u64lo(0, clamp);
 486 #endif
 487 }
 488 
 489 static inline ScmUInt64 u64g_mul(ScmUInt64 x, ScmUInt64 y, int clamp)
 490 {
 491 #if SIZEOF_LONG == 4
 492     ScmObj xx = Scm_MakeIntegerU64(x);
 493     ScmObj yy = Scm_MakeIntegerU64(y);
 494     ScmObj r = Scm_Multiply2(xx, yy);
 495     return Scm_GetIntegerU64Clamp(r, clamp, NULL);
 496 #else
 497     u_long r, v;
 498     UMULOV(r, v, x, y);
 499     if (v == 0) return r;
 500     else        return range_u64hi(0, clamp);
 501 #endif
 502 }
 503 
 504 #define f32f32_add(x, y, clamp)   (x+y)
 505 #define f32f32_sub(x, y, clamp)   (x-y)
 506 #define f32f32_mul(x, y, clamp)   (x*y)
 507 #define f32f32_div(x, y, clamp)   (x/y)
 508 
 509 #define f32g_add(x, y, clamp)   (x+y)
 510 #define f32g_sub(x, y, clamp)   (x-y)
 511 #define f32g_mul(x, y, clamp)   (x*y)
 512 #define f32g_div(x, y, clamp)   (x/y)
 513 
 514 #define f64f64_add(x, y, clamp)   (x+y)
 515 #define f64f64_sub(x, y, clamp)   (x-y)
 516 #define f64f64_mul(x, y, clamp)   (x*y)
 517 #define f64f64_div(x, y, clamp)   (x/y)
 518 
 519 #define f64g_add(x, y, clamp)   (x+y)
 520 #define f64g_sub(x, y, clamp)   (x-y)
 521 #define f64g_mul(x, y, clamp)   (x*y)
 522 #define f64g_div(x, y, clamp)   (x/y)
 523 
 524 /****** Number extraction *****/
 525 /* like unbox, but not as strict.  sets *oor = TRUE if x is out of range. */
 526 
 527 static inline long s8num(ScmObj x, int *oor)
 528 {
 529     return Scm_GetIntegerClamp(x, SCM_CLAMP_NONE, oor);
 530 }
 531 
 532 #define s16num(x, oor)           s8num(x, oor)
 533 #define s32num(x, oor)           s8num(x, oor)
 534 
 535 static inline u_long u8num(ScmObj x, int *oor)
 536 {
 537     return Scm_GetIntegerUClamp(x, SCM_CLAMP_NONE, oor);
 538 }
 539 
 540 #define u16num(x, oor)           u8num(x, oor)
 541 #define u32num(x, oor)           u8num(x, oor)
 542 
 543 static inline ScmInt64 s64num(ScmObj x, int *oor)
 544 {
 545     return Scm_GetInteger64Clamp(x, SCM_CLAMP_NONE, oor);
 546 }
 547 
 548 static inline ScmUInt64 u64num(ScmObj x, int *oor)
 549 {
 550     return Scm_GetIntegerU64Clamp(x, SCM_CLAMP_NONE, oor);
 551 }
 552 
 553 #define f32num(x, oor)           ((*oor = FALSE),((float)Scm_GetDouble(x)))
 554 #define f64num(x, oor)           ((*oor = FALSE), Scm_GetDouble(x))
 555 /****** Bit operation *****/
 556 
 557 static inline u_long bitext(ScmObj x)
 558 {
 559     if (SCM_INTP(x)) return (u_long)SCM_INT_VALUE(x);
 560     if (SCM_BIGNUMP(x)) {
 561         if (SCM_BIGNUM_SIGN(x) > 0) {
 562             return SCM_BIGNUM(x)->values[0];
 563         } else {
 564             return ~(SCM_BIGNUM(x)->values[0]) + 1;
 565         }
 566     }
 567     Scm_Error("integer required, but got %S", x);
 568     return 0;
 569 }
 570 
 571 static inline ScmUInt64 bitext64(ScmObj x)
 572 {
 573 #if SCM_EMULATE_INT64
 574     ScmUInt64 r = {0, 0};
 575     if (SCM_INTP(x)) r.lo = SCM_INT_VALUE(x);
 576     else if (SCM_BIGNUMP(x)) {
 577         ScmObj xx = Scm_LogAnd(x, SCM_2_64_MINUS_1);
 578         ScmUInt64 ii = Scm_GetIntegerU64(xx);
 579         r.lo = ii.lo;
 580         r.hi = ii.hi;
 581     }
 582     else goto type_err;
 583 #else
 584     ScmUInt64 r = 0;
 585     if (SCM_INTP(x)) r = SCM_INT_VALUE(x);
 586     else if (SCM_BIGNUMP(x)) {
 587         ScmObj xx = Scm_LogAnd(x, SCM_2_64_MINUS_1);
 588         r = Scm_GetIntegerU64(xx);
 589     }
 590     else goto type_err;
 591 #endif
 592     return r;
 593   type_err:
 594     Scm_Error("integer required, but got %S", x);
 595     return r;                   /* dummy */
 596 }
 597 
 598 #if SCM_EMULATE_INT64
 599 #define INT64BITOP(r, x, op, y)  ((r.lo = x.lo op y.lo), (r.hi = x.hi op y.hi))
 600 #else
 601 #define INT64BITOP(r, x, op, y)  (r = x op y)
 602 #endif
 603 /****** Multiply-and-add operation. *****/
 604 
 605 static inline long s8muladd(long x, long y, long acc, ScmObj *sacc)
 606 {
 607     long k, v, m;
 608     m = x * y;
 609     SADDOV(k, v, acc, m);
 610     if (v) {
 611         *sacc = Scm_Add2(*sacc, Scm_MakeInteger(acc));
 612         return m;
 613     } else {
 614         return k;
 615     }
 616 }
 617 
 618 #define s16muladd(x, y, acc, sacc) s8muladd(x, y, acc, sacc)
 619 
 620 static inline long s32muladd(long x, long y, long acc, ScmObj *sacc)
 621 {
 622     long k, v, m;
 623     SMULOV(m, v, x, y);
 624     if (v) {
 625         *sacc = Scm_Add2(*sacc, Scm_Multiply2(Scm_MakeInteger(x),
 626                                               Scm_MakeInteger(y)));
 627         return acc;
 628     } else {
 629         SADDOV(k, v, acc, m);
 630         if (v) {
 631             *sacc = Scm_Add2(*sacc, Scm_MakeInteger(acc));
 632             return m;
 633         } else {
 634             return k;
 635         }
 636     }
 637 }
 638 
 639 #if SIZEOF_LONG == 4
 640 static inline ScmInt64 s64muladd(ScmInt64 x, ScmInt64 y, ScmInt64 acc, ScmObj *sacc)
 641 {
 642     /* we don't use acc, and operate only on sacc. */
 643     *sacc = Scm_Add2(*sacc, Scm_Multiply2(Scm_MakeInteger64(x),
 644                                           Scm_MakeInteger64(y)));
 645     return acc;
 646 }
 647 #else
 648 #define s64muladd(x, y, acc, sacc) s32muladd(x, y, acc, sacc)
 649 #endif
 650 
 651 static inline u_long u8muladd(u_long x, u_long y, u_long acc, ScmObj *sacc)
 652 {
 653     u_long k, v, m;
 654     m = x * y;
 655     UADDOV(k, v, acc, m);
 656     if (v) {
 657         *sacc = Scm_Add2(*sacc, Scm_MakeIntegerU(acc));
 658         return m;
 659     } else {
 660         return k;
 661     }
 662 }
 663 
 664 #define u16muladd(x, y, acc, sacc) u8muladd(x, y, acc, sacc)
 665 
 666 static inline u_long u32muladd(u_long x, u_long y, u_long acc, ScmObj *sacc)
 667 {
 668     u_long k, v, m;
 669     UMULOV(m, v, x, y);
 670     if (v) {
 671         *sacc = Scm_Add2(*sacc, Scm_Multiply2(Scm_MakeIntegerU(x),
 672                                               Scm_MakeIntegerU(y)));
 673         return acc;
 674     } else {
 675         UADDOV(k, v, acc, m);
 676         if (v) {
 677             *sacc = Scm_Add2(*sacc, Scm_MakeIntegerU(acc));
 678             return m;
 679         } else {
 680             return k;
 681         }
 682     }
 683 }
 684 
 685 #if SIZEOF_LONG == 4
 686 static inline ScmUInt64 u64muladd(ScmUInt64 x, ScmUInt64 y, ScmUInt64 acc, ScmObj *sacc)
 687 {
 688     /* we don't use acc, and operate only on sacc. */
 689     *sacc = Scm_Add2(*sacc, Scm_Multiply2(Scm_MakeIntegerU64(x),
 690                                           Scm_MakeIntegerU64(y)));
 691     return acc;
 692 }
 693 #else
 694 #define u64muladd(x, y, acc, sacc) u32muladd(x, y, acc, sacc)
 695 #endif
 696 
 697 #define f32muladd(x, y, acc, sacc)  (acc + x*y)
 698 #define f64muladd(x, y, acc, sacc)  (acc + x*y)
 699 
 700 #if SCM_EMULATE_INT64
 701 #define INT64LT(a, b)  ((a.hi < b.hi) || (a.hi == b.hi) && (a.lo < b.lo))
 702 #else
 703 #define INT64LT(a, b)  (a < b)
 704 #endif
 705 
 706 
 707 #define SWAP(x, y)   (t = dd.c[x], dd.c[x] = dd.c[y], dd.c[y] = t)
 708 
 709 static void swapb16(unsigned short *loc)
 710 {
 711     union {
 712         unsigned short s;
 713         unsigned char c[2];
 714     } dd;
 715     unsigned char t;
 716     dd.s = *loc;
 717     SWAP(0, 1);
 718     *loc = dd.s;
 719 }
 720 
 721 static void swapb32(ScmUInt32 *loc)
 722 {
 723     union {
 724         ScmUInt32 i;
 725         unsigned char c[4];
 726     } dd;
 727     unsigned char t;
 728     dd.i = *loc;
 729     SWAP(0, 3);
 730     SWAP(1, 2);
 731     *loc = dd.i;
 732 }
 733 
 734 static void swapb64(ScmUInt64 *loc)
 735 {
 736     union {
 737         ScmUInt64 l;
 738         unsigned char c[4];
 739     } dd;
 740     unsigned char t;
 741     dd.l = *loc;
 742     SWAP(0, 7);
 743     SWAP(1, 6);
 744     SWAP(2, 5);
 745     SWAP(3, 4);
 746     *loc = dd.l;
 747 }
 748 
 749 
 750 /*---------------------------------------------------------------
 751  * S8Vector
 752  */
 753 
 754 /*
 755  * Class stuff
 756  */
 757 
 758 static void print_s8vector(ScmObj obj, ScmPort *out, ScmWriteContext *ctx)
 759 {
 760     int i;
 761     Scm_Printf(out, "#s8(");
 762     for (i=0; i<SCM_S8VECTOR_SIZE(obj); i++) {
 763         signed char elt = SCM_S8VECTOR_ELEMENTS(obj)[i];
 764         if (i != 0) Scm_Printf(out, " ");
 765         Scm_Printf(out, "%d", elt);
 766     }
 767     Scm_Printf(out, ")");
 768 }
 769 
 770 static int compare_s8vector(ScmObj x, ScmObj y, int equalp)
 771 {
 772     int len = SCM_S8VECTOR_SIZE(x), i;
 773     signed char xx, yy;
 774     if (SCM_S8VECTOR_SIZE(y) != len) return -1;
 775     for (i=0; i<len; i++) {
 776         xx = SCM_S8VECTOR_ELEMENTS(x)[i];
 777         yy = SCM_S8VECTOR_ELEMENTS(y)[i];
 778         if (!(xx == yy)) {
 779             return -1;
 780         }
 781     }
 782     return 0;
 783 }
 784 
 785 SCM_DEFINE_BUILTIN_CLASS(Scm_S8VectorClass,
 786                          print_s8vector, compare_s8vector, NULL, NULL,
 787                          uvector_cpl);
 788 
 789 /*
 790  * Constructor
 791  */
 792 static ScmS8Vector *make_s8vector(int size, signed char *eltp)
 793 {
 794     return (ScmS8Vector*)Scm_MakeUVector(SCM_CLASS_S8VECTOR, size, eltp);
 795 }
 796 
 797 ScmObj Scm_MakeS8Vector(int size, signed char fill)
 798 {
 799     ScmS8Vector *vec = make_s8vector(size, NULL);
 800     int i;
 801     for (i=0; i<size; i++) {
 802         vec->elements[i] = fill;
 803     }
 804     return SCM_OBJ(vec);
 805 }
 806 
 807 ScmObj Scm_MakeS8VectorFromArray(int size, const signed char array[])
 808 {
 809     ScmS8Vector *vec = make_s8vector(size, NULL);
 810     int i;
 811     for (i=0; i<size; i++) {
 812         vec->elements[i] = array[i];
 813     }
 814     return SCM_OBJ(vec);
 815 }
 816 
 817 ScmObj Scm_MakeS8VectorFromArrayShared(int size, signed char array[])
 818 {
 819     ScmS8Vector *vec = make_s8vector(size, array);
 820     return SCM_OBJ(vec);
 821 }
 822 
 823 ScmObj Scm_ListToS8Vector(ScmObj list, int clamp)
 824 {
 825     int length = Scm_Length(list), i;
 826     ScmS8Vector *vec;
 827     ScmObj cp;
 828 
 829     if (length < 0) Scm_Error("improper list not allowed: %S", list);
 830     vec = make_s8vector(length, NULL);
 831     for (i=0, cp=list; i<length; i++, cp = SCM_CDR(cp)) {
 832         signed char elt;
 833         ScmObj obj = SCM_CAR(cp);
 834         elt = s8unbox(obj, clamp);
 835         vec->elements[i] = elt;
 836     }
 837     return SCM_OBJ(vec);
 838 }
 839 
 840 ScmObj Scm_VectorToS8Vector(ScmVector *ivec, int start, int end, int clamp)
 841 {
 842     int length = SCM_VECTOR_SIZE(ivec), i;
 843     ScmS8Vector *vec;
 844     SCM_CHECK_START_END(start, end, length);
 845     vec = make_s8vector(end-start, NULL);
 846     for (i=start; i<end; i++) {
 847         signed char elt;
 848         ScmObj obj = SCM_VECTOR_ELEMENT(ivec, i);
 849         elt = s8unbox(obj, clamp);
 850         vec->elements[i-start] = elt;
 851     }
 852     return SCM_OBJ(vec);
 853 }
 854 
 855 /*
 856  * Accessors and modifiers
 857  */
 858 
 859 ScmObj Scm_S8VectorFill(ScmS8Vector *vec, signed char fill, int start, int end)
 860 {
 861     int i, size = SCM_S8VECTOR_SIZE(vec);
 862     SCM_CHECK_START_END(start, end, size);
 863     SCM_UVECTOR_CHECK_MUTABLE(vec);
 864     for (i=start; i<end; i++) vec->elements[i] = fill;
 865     return SCM_OBJ(vec);
 866 }
 867 
 868 ScmObj Scm_S8VectorRef(ScmS8Vector *vec, int index, ScmObj fallback)
 869 {
 870     ScmObj r;
 871     signed char elt;
 872     if (index < 0 || index >= SCM_S8VECTOR_SIZE(vec)) {
 873         if (SCM_UNBOUNDP(fallback)) 
 874             Scm_Error("index out of range: %d", index);
 875         return fallback;
 876     }
 877     elt = vec->elements[index];
 878     r = SCM_MAKE_INT(elt);
 879     return r;
 880 }
 881 
 882 ScmObj Scm_S8VectorSet(ScmS8Vector *vec, int index, ScmObj val, int clamp)
 883 {
 884     signed char elt;
 885     if (index < 0 || index >= SCM_S8VECTOR_SIZE(vec))
 886         Scm_Error("index out of range: %d", index);
 887     SCM_UVECTOR_CHECK_MUTABLE(vec);
 888     elt = s8unbox(val, clamp);
 889     vec->elements[index] = elt;
 890     return SCM_OBJ(vec);
 891 }
 892 
 893 ScmObj Scm_S8VectorToList(ScmS8Vector *vec, int start, int end)
 894 {
 895     ScmObj head = SCM_NIL, tail;
 896     int i, size = SCM_S8VECTOR_SIZE(vec);
 897     SCM_CHECK_START_END(start, end, size);
 898     for (i=start; i<end; i++) {
 899         ScmObj obj;
 900         signed char elt = vec->elements[i];
 901         obj = SCM_MAKE_INT(elt);
 902         SCM_APPEND1(head, tail, obj);
 903     }
 904     return head;
 905 }
 906 
 907 ScmObj Scm_S8VectorToVector(ScmS8Vector *vec, int start, int end)
 908 {
 909     ScmObj ovec;
 910     int i, size = SCM_S8VECTOR_SIZE(vec);
 911     SCM_CHECK_START_END(start, end, size);
 912     ovec = Scm_MakeVector(end-start, SCM_UNDEFINED);
 913     for (i=start; i<end; i++) {
 914         ScmObj obj;
 915         signed char elt = vec->elements[i];
 916         obj = SCM_MAKE_INT(elt);
 917         SCM_VECTOR_ELEMENT(ovec, i-start) = obj;
 918     }
 919     return ovec;
 920 }
 921 
 922 ScmObj Scm_S8VectorCopy(ScmS8Vector *vec, int start, int end)
 923 {
 924     int size = SCM_S8VECTOR_SIZE(vec);
 925     SCM_CHECK_START_END(start, end, size);
 926     return Scm_MakeS8VectorFromArray(end-start,
 927                                      SCM_S8VECTOR_ELEMENTS(vec)+start);
 928 }
 929 
 930 ScmObj Scm_S8VectorCopyX(ScmS8Vector *dst,
 931                            int dstart,
 932                            ScmS8Vector *src,
 933                            int sstart,
 934                            int send)
 935 {
 936     int dlen = SCM_S8VECTOR_SIZE(dst);
 937     int slen = SCM_S8VECTOR_SIZE(src);
 938     int size;
 939     
 940     SCM_UVECTOR_CHECK_MUTABLE(dst);
 941     SCM_CHECK_START_END(sstart, send, slen);
 942 
 943     if (dstart < 0 || dstart >= dlen) return SCM_OBJ(dst);
 944     if (dlen - dstart > send - sstart)  size = send - sstart;
 945     else size = dlen - dstart;
 946 
 947     memcpy(SCM_S8VECTOR_ELEMENTS(dst) + dstart,
 948            SCM_S8VECTOR_ELEMENTS(src) + sstart,
 949            size * sizeof(signed char));
 950     return SCM_OBJ(dst);
 951 }
 952 
 953 
 954 /*---------------------------------------------------------------
 955  * U8Vector
 956  */
 957 
 958 /*
 959  * Class stuff
 960  */
 961 
 962 static void print_u8vector(ScmObj obj, ScmPort *out, ScmWriteContext *ctx)
 963 {
 964     int i;
 965     Scm_Printf(out, "#u8(");
 966     for (i=0; i<SCM_U8VECTOR_SIZE(obj); i++) {
 967         unsigned char elt = SCM_U8VECTOR_ELEMENTS(obj)[i];
 968         if (i != 0) Scm_Printf(out, " ");
 969         Scm_Printf(out, "%d", elt);
 970     }
 971     Scm_Printf(out, ")");
 972 }
 973 
 974 static int compare_u8vector(ScmObj x, ScmObj y, int equalp)
 975 {
 976     int len = SCM_U8VECTOR_SIZE(x), i;
 977     unsigned char xx, yy;
 978     if (SCM_U8VECTOR_SIZE(y) != len) return -1;
 979     for (i=0; i<len; i++) {
 980         xx = SCM_U8VECTOR_ELEMENTS(x)[i];
 981         yy = SCM_U8VECTOR_ELEMENTS(y)[i];
 982         if (!(xx == yy)) {
 983             return -1;
 984         }
 985     }
 986     return 0;
 987 }
 988 
 989 SCM_DEFINE_BUILTIN_CLASS(Scm_U8VectorClass,
 990                          print_u8vector, compare_u8vector, NULL, NULL,
 991                          uvector_cpl);
 992 
 993 /*
 994  * Constructor
 995  */
 996 static ScmU8Vector *make_u8vector(int size, unsigned char *eltp)
 997 {
 998     return (ScmU8Vector*)Scm_MakeUVector(SCM_CLASS_U8VECTOR, size, eltp);
 999 }
1000 
1001 ScmObj Scm_MakeU8Vector(int size, unsigned char fill)
1002 {
1003     ScmU8Vector *vec = make_u8vector(size, NULL);
1004     int i;
1005     for (i=0; i<size; i++) {
1006         vec->elements[i] = fill;
1007     }
1008     return SCM_OBJ(vec);
1009 }
1010 
1011 ScmObj Scm_MakeU8VectorFromArray(int size, const unsigned char array[])
1012 {
1013     ScmU8Vector *vec = make_u8vector(size, NULL);
1014     int i;
1015     for (i=0; i<size; i++) {
1016         vec->elements[i] = array[i];
1017     }
1018     return SCM_OBJ(vec);
1019 }
1020 
1021 ScmObj Scm_MakeU8VectorFromArrayShared(int size, unsigned char array[])
1022 {
1023     ScmU8Vector *vec = make_u8vector(size, array);
1024     return SCM_OBJ(vec);
1025 }
1026 
1027 ScmObj Scm_ListToU8Vector(ScmObj list, int clamp)
1028 {
1029     int length = Scm_Length(list), i;
1030     ScmU8Vector *vec;
1031     ScmObj cp;
1032 
1033     if (length < 0) Scm_Error("improper list not allowed: %S", list);
1034     vec = make_u8vector(length, NULL);
1035     for (i=0, cp=list; i<length; i++, cp = SCM_CDR(cp)) {
1036         unsigned char elt;
1037         ScmObj obj = SCM_CAR(cp);
1038         elt = u8unbox(obj, clamp);
1039         vec->elements[i] = elt;
1040     }
1041     return SCM_OBJ(vec);
1042 }
1043 
1044 ScmObj Scm_VectorToU8Vector(ScmVector *ivec, int start, int end, int clamp)
1045 {
1046     int length = SCM_VECTOR_SIZE(ivec), i;
1047     ScmU8Vector *vec;
1048     SCM_CHECK_START_END(start, end, length);
1049     vec = make_u8vector(end-start, NULL);
1050     for (i=start; i<end; i++) {
1051         unsigned char elt;
1052         ScmObj obj = SCM_VECTOR_ELEMENT(ivec, i);
1053         elt = u8unbox(obj, clamp);
1054         vec->elements[i-start] = elt;
1055     }
1056     return SCM_OBJ(vec);
1057 }
1058 
1059 /*
1060  * Accessors and modifiers
1061  */
1062 
1063 ScmObj Scm_U8VectorFill(ScmU8Vector *vec, unsigned char fill, int start, int end)
1064 {
1065     int i, size = SCM_U8VECTOR_SIZE(vec);
1066     SCM_CHECK_START_END(start, end, size);
1067     SCM_UVECTOR_CHECK_MUTABLE(vec);
1068     for (i=start; i<end; i++) vec->elements[i] = fill;
1069     return SCM_OBJ(vec);
1070 }
1071 
1072 ScmObj Scm_U8VectorRef(ScmU8Vector *vec, int index, ScmObj fallback)
1073 {
1074     ScmObj r;
1075     unsigned char elt;
1076     if (index < 0 || index >= SCM_U8VECTOR_SIZE(vec)) {
1077         if (SCM_UNBOUNDP(fallback)) 
1078             Scm_Error("index out of range: %d", index);
1079         return fallback;
1080     }
1081     elt = vec->elements[index];
1082     r = SCM_MAKE_INT(elt);
1083     return r;
1084 }
1085 
1086 ScmObj Scm_U8VectorSet(ScmU8Vector *vec, int index, ScmObj val, int clamp)
1087 {
1088     unsigned char elt;
1089     if (index < 0 || index >= SCM_U8VECTOR_SIZE(vec))
1090         Scm_Error("index out of range: %d", index);
1091     SCM_UVECTOR_CHECK_MUTABLE(vec);
1092     elt = u8unbox(val, clamp);
1093     vec->elements[index] = elt;
1094     return SCM_OBJ(vec);
1095 }
1096 
1097 ScmObj Scm_U8VectorToList(ScmU8Vector *vec, int start, int end)
1098 {
1099     ScmObj head = SCM_NIL, tail;
1100     int i, size = SCM_U8VECTOR_SIZE(vec);
1101     SCM_CHECK_START_END(start, end, size);
1102     for (i=start; i<end; i++) {
1103         ScmObj obj;
1104         unsigned char elt = vec->elements[i];
1105         obj = SCM_MAKE_INT(elt);
1106         SCM_APPEND1(head, tail, obj);
1107     }
1108     return head;
1109 }
1110 
1111 ScmObj Scm_U8VectorToVector(ScmU8Vector *vec, int start, int end)
1112 {
1113     ScmObj ovec;
1114     int i, size = SCM_U8VECTOR_SIZE(vec);
1115     SCM_CHECK_START_END(start, end, size);
1116     ovec = Scm_MakeVector(end-start, SCM_UNDEFINED);
1117     for (i=start; i<end; i++) {
1118         ScmObj obj;
1119         unsigned char elt = vec->elements[i];
1120         obj = SCM_MAKE_INT(elt);
1121         SCM_VECTOR_ELEMENT(ovec, i-start) = obj;
1122     }
1123     return ovec;
1124 }
1125 
1126 ScmObj Scm_U8VectorCopy(ScmU8Vector *vec, int start, int end)
1127 {
1128     int size = SCM_U8VECTOR_SIZE(vec);
1129     SCM_CHECK_START_END(start, end, size);
1130     return Scm_MakeU8VectorFromArray(end-start,
1131                                      SCM_U8VECTOR_ELEMENTS(vec)+start);
1132 }
1133 
1134 ScmObj Scm_U8VectorCopyX(ScmU8Vector *dst,
1135                            int dstart,
1136                            ScmU8Vector *src,
1137                            int sstart,
1138                            int send)
1139 {
1140     int dlen = SCM_U8VECTOR_SIZE(dst);
1141     int slen = SCM_U8VECTOR_SIZE(src);
1142     int size;
1143     
1144     SCM_UVECTOR_CHECK_MUTABLE(dst);
1145     SCM_CHECK_START_END(sstart, send, slen);
1146 
1147     if (dstart < 0 || dstart >= dlen) return SCM_OBJ(dst);
1148     if (dlen - dstart > send - sstart)  size = send - sstart;
1149     else size = dlen - dstart;
1150 
1151     memcpy(SCM_U8VECTOR_ELEMENTS(dst) + dstart,
1152            SCM_U8VECTOR_ELEMENTS(src) + sstart,
1153            size * sizeof(unsigned char));
1154     return SCM_OBJ(dst);
1155 }
1156 
1157 
1158 /*---------------------------------------------------------------
1159  * S16Vector
1160  */
1161 
1162 /*
1163  * Class stuff
1164  */
1165 
1166 static void print_s16vector(ScmObj obj, ScmPort *out, ScmWriteContext *ctx)
1167 {
1168     int i;
1169     Scm_Printf(out, "#s16(");
1170     for (i=0; i<SCM_S16VECTOR_SIZE(obj); i++) {
1171         short elt = SCM_S16VECTOR_ELEMENTS(obj)[i];
1172         if (i != 0) Scm_Printf(out, " ");
1173         Scm_Printf(out, "%d", elt);
1174     }
1175     Scm_Printf(out, ")");
1176 }
1177 
1178 static int compare_s16vector(ScmObj x, ScmObj y, int equalp)
1179 {
1180     int len = SCM_S16VECTOR_SIZE(x), i;
1181     short xx, yy;
1182     if (SCM_S16VECTOR_SIZE(y) != len) return -1;
1183     for (i=0; i<len; i++) {
1184         xx = SCM_S16VECTOR_ELEMENTS(x)[i];
1185         yy = SCM_S16VECTOR_ELEMENTS(y)[i];
1186         if (!(xx == yy)) {
1187             return -1;
1188         }
1189     }
1190     return 0;
1191 }
1192 
1193 SCM_DEFINE_BUILTIN_CLASS(Scm_S16VectorClass,
1194                          print_s16vector, compare_s16vector, NULL, NULL,
1195                          uvector_cpl);
1196 
1197 /*
1198  * Constructor
1199  */
1200 static ScmS16Vector *make_s16vector(int size, short *eltp)
1201 {
1202     return (ScmS16Vector*)Scm_MakeUVector(SCM_CLASS_S16VECTOR, size, eltp);
1203 }
1204 
1205 ScmObj Scm_MakeS16Vector(int size, short fill)
1206 {
1207     ScmS16Vector *vec = make_s16vector(size, NULL);
1208     int i;
1209     for (i=0; i<size; i++) {
1210         vec->elements[i] = fill;
1211     }
1212     return SCM_OBJ(vec);
1213 }
1214 
1215 ScmObj Scm_MakeS16VectorFromArray(int size, const short array[])
1216 {
1217     ScmS16Vector *vec = make_s16vector(size, NULL);
1218     int i;
1219     for (i=0; i<size; i++) {
1220         vec->elements[i] = array[i];
1221     }
1222     return SCM_OBJ(vec);
1223 }
1224 
1225 ScmObj Scm_MakeS16VectorFromArrayShared(int size, short array[])
1226 {
1227     ScmS16Vector *vec = make_s16vector(size, array);
1228     return SCM_OBJ(vec);
1229 }
1230 
1231 ScmObj Scm_ListToS16Vector(ScmObj list, int clamp)
1232 {
1233     int length = Scm_Length(list), i;
1234     ScmS16Vector *vec;
1235     ScmObj cp;
1236 
1237     if (length < 0) Scm_Error("improper list not allowed: %S", list);
1238     vec = make_s16vector(length, NULL);
1239     for (i=0, cp=list; i<length; i++, cp = SCM_CDR(cp)) {
1240         short elt;
1241         ScmObj obj = SCM_CAR(cp);
1242         elt = s16unbox(obj, clamp);
1243         vec->elements[i] = elt;
1244     }
1245     return SCM_OBJ(vec);
1246 }
1247 
1248 ScmObj Scm_VectorToS16Vector(ScmVector *ivec, int start, int end, int clamp)
1249 {
1250     int length = SCM_VECTOR_SIZE(ivec), i;
1251     ScmS16Vector *vec;
1252     SCM_CHECK_START_END(start, end, length);
1253     vec = make_s16vector(end-start, NULL);
1254     for (i=start; i<end; i++) {
1255         short elt;
1256         ScmObj obj = SCM_VECTOR_ELEMENT(ivec, i);
1257         elt = s16unbox(obj, clamp);
1258         vec->elements[i-start] = elt;
1259     }
1260     return SCM_OBJ(vec);
1261 }
1262 
1263 /*
1264  * Accessors and modifiers
1265  */
1266 
1267 ScmObj Scm_S16VectorFill(ScmS16Vector *vec, short fill, int start, int end)
1268 {
1269     int i, size = SCM_S16VECTOR_SIZE(vec);
1270     SCM_CHECK_START_END(start, end, size);
1271     SCM_UVECTOR_CHECK_MUTABLE(vec);
1272     for (i=start; i<end; i++) vec->elements[i] = fill;
1273     return SCM_OBJ(vec);
1274 }
1275 
1276 ScmObj Scm_S16VectorRef(ScmS16Vector *vec, int index, ScmObj fallback)
1277 {
1278     ScmObj r;
1279     short elt;
1280     if (index < 0 || index >= SCM_S16VECTOR_SIZE(vec)) {
1281         if (SCM_UNBOUNDP(fallback)) 
1282             Scm_Error("index out of range: %d", index);
1283         return fallback;
1284     }
1285     elt = vec->elements[index];
1286     r = SCM_MAKE_INT(elt);
1287     return r;
1288 }
1289 
1290 ScmObj Scm_S16VectorSet(ScmS16Vector *vec, int index, ScmObj val, int clamp)
1291 {
1292     short elt;
1293     if (index < 0 || index >= SCM_S16VECTOR_SIZE(vec))
1294         Scm_Error("index out of range: %d", index);
1295     SCM_UVECTOR_CHECK_MUTABLE(vec);
1296     elt = s16unbox(val, clamp);
1297     vec->elements[index] = elt;
1298     return SCM_OBJ(vec);
1299 }
1300 
1301 ScmObj Scm_S16VectorToList(ScmS16Vector *vec, int start, int end)
1302 {
1303     ScmObj head = SCM_NIL, tail;
1304     int i, size = SCM_S16VECTOR_SIZE(vec);
1305     SCM_CHECK_START_END(start, end, size);
1306     for (i=start; i<end; i++) {
1307         ScmObj obj;
1308         short elt = vec->elements[i];
1309         obj = SCM_MAKE_INT(elt);
1310         SCM_APPEND1(head, tail, obj);
1311     }
1312     return head;
1313 }
1314 
1315 ScmObj Scm_S16VectorToVector(ScmS16Vector *vec, int start, int end)
1316 {
1317     ScmObj ovec;
1318     int i, size = SCM_S16VECTOR_SIZE(vec);
1319     SCM_CHECK_START_END(start, end, size);
1320     ovec = Scm_MakeVector(end-start, SCM_UNDEFINED);
1321     for (i=start; i<end; i++) {
1322         ScmObj obj;
1323         short elt = vec->elements[i];
1324         obj = SCM_MAKE_INT(elt);
1325         SCM_VECTOR_ELEMENT(ovec, i-start) = obj;
1326     }
1327     return ovec;
1328 }
1329 
1330 ScmObj Scm_S16VectorCopy(ScmS16Vector *vec, int start, int end)
1331 {
1332     int size = SCM_S16VECTOR_SIZE(vec);
1333     SCM_CHECK_START_END(start, end, size);
1334     return Scm_MakeS16VectorFromArray(end-start,
1335                                      SCM_S16VECTOR_ELEMENTS(vec)+start);
1336 }
1337 
1338 ScmObj Scm_S16VectorCopyX(ScmS16Vector *dst,
1339                            int dstart,
1340                            ScmS16Vector *src,
1341                            int sstart,
1342                            int send)
1343 {
1344     int dlen = SCM_S16VECTOR_SIZE(dst);
1345     int slen = SCM_S16VECTOR_SIZE(src);
1346     int size;
1347     
1348     SCM_UVECTOR_CHECK_MUTABLE(dst);
1349     SCM_CHECK_START_END(sstart, send, slen);
1350 
1351     if (dstart < 0 || dstart >= dlen) return SCM_OBJ(dst);
1352     if (dlen - dstart > send - sstart)  size = send - sstart;
1353     else size = dlen - dstart;
1354 
1355     memcpy(SCM_S16VECTOR_ELEMENTS(dst) + dstart,
1356            SCM_S16VECTOR_ELEMENTS(src) + sstart,
1357            size * sizeof(short));
1358     return SCM_OBJ(dst);
1359 }
1360 
1361 
1362 /*---------------------------------------------------------------
1363  * U16Vector
1364  */
1365 
1366 /*
1367  * Class stuff
1368  */
1369 
1370 static void print_u16vector(ScmObj obj, ScmPort *out, ScmWriteContext *ctx)
1371 {
1372     int i;
1373     Scm_Printf(out, "#u16(");
1374     for (i=0; i<SCM_U16VECTOR_SIZE(obj); i++) {
1375         unsigned short elt = SCM_U16VECTOR_ELEMENTS(obj)[i];
1376         if (i != 0) Scm_Printf(out, " ");
1377         Scm_Printf(out, "%d", elt);
1378     }
1379     Scm_Printf(out, ")");
1380 }
1381 
1382 static int compare_u16vector(ScmObj x, ScmObj y, int equalp)
1383 {
1384     int len = SCM_U16VECTOR_SIZE(x), i;
1385     unsigned short xx, yy;
1386     if (SCM_U16VECTOR_SIZE(y) != len) return -1;
1387     for (i=0; i<len; i++) {
1388         xx = SCM_U16VECTOR_ELEMENTS(x)[i];
1389         yy = SCM_U16VECTOR_ELEMENTS(y)[i];
1390         if (!(xx == yy)) {
1391             return -1;
1392         }
1393     }
1394     return 0;
1395 }
1396 
1397 SCM_DEFINE_BUILTIN_CLASS(Scm_U16VectorClass,
1398                          print_u16vector, compare_u16vector, NULL, NULL,
1399                          uvector_cpl);
1400 
1401 /*
1402  * Constructor
1403  */
1404 static ScmU16Vector *make_u16vector(int size, unsigned short *eltp)
1405 {
1406     return (ScmU16Vector*)Scm_MakeUVector(SCM_CLASS_U16VECTOR, size, eltp);
1407 }
1408 
1409 ScmObj Scm_MakeU16Vector(int size, unsigned short fill)
1410 {
1411     ScmU16Vector *vec = make_u16vector(size, NULL);
1412     int i;
1413     for (i=0; i<size; i++) {
1414         vec->elements[i] = fill;
1415     }
1416     return SCM_OBJ(vec);
1417 }
1418 
1419 ScmObj Scm_MakeU16VectorFromArray(int size, const unsigned short array[])
1420 {
1421     ScmU16Vector *vec = make_u16vector(size, NULL);
1422     int i;
1423     for (i=0; i<size; i++) {
1424         vec->elements[i] = array[i];
1425     }
1426     return SCM_OBJ(vec);
1427 }
1428 
1429 ScmObj Scm_MakeU16VectorFromArrayShared(int size, unsigned short array[])
1430 {
1431     ScmU16Vector *vec = make_u16vector(size, array);
1432     return SCM_OBJ(vec);
1433 }
1434 
1435 ScmObj Scm_ListToU16Vector(ScmObj list, int clamp)
1436 {
1437     int length = Scm_Length(list), i;
1438     ScmU16Vector *vec;
1439     ScmObj cp;
1440 
1441     if (length < 0) Scm_Error("improper list not allowed: %S", list);
1442     vec = make_u16vector(length, NULL);
1443     for (i=0, cp=list; i<length; i++, cp = SCM_CDR(cp)) {
1444         unsigned short elt;
1445         ScmObj obj = SCM_CAR(cp);
1446         elt = u16unbox(obj, clamp);
1447         vec->elements[i] = elt;
1448     }
1449     return SCM_OBJ(vec);
1450 }
1451 
1452 ScmObj Scm_VectorToU16Vector(ScmVector *ivec, int start, int end, int clamp)
1453 {
1454     int length = SCM_VECTOR_SIZE(ivec), i;
1455     ScmU16Vector *vec;
1456     SCM_CHECK_START_END(start, end, length);
1457     vec = make_u16vector(end-start, NULL);
1458     for (i=start; i<end; i++) {
1459         unsigned short elt;
1460         ScmObj obj = SCM_VECTOR_ELEMENT(ivec, i);
1461         elt = u16unbox(obj, clamp);
1462         vec->elements[i-start] = elt;
1463     }
1464     return SCM_OBJ(vec);
1465 }
1466 
1467 /*
1468  * Accessors and modifiers
1469  */
1470 
1471 ScmObj Scm_U16VectorFill(ScmU16Vector *vec, unsigned short fill, int start, int end)
1472 {
1473     int i, size = SCM_U16VECTOR_SIZE(vec);
1474     SCM_CHECK_START_END(start, end, size);
1475     SCM_UVECTOR_CHECK_MUTABLE(vec);
1476     for (i=start; i<end; i++) vec->elements[i] = fill;
1477     return SCM_OBJ(vec);
1478 }
1479 
1480 ScmObj Scm_U16VectorRef(ScmU16Vector *vec, int index, ScmObj fallback)
1481 {
1482     ScmObj r;
1483     unsigned short elt;
1484     if (index < 0 || index >= SCM_U16VECTOR_SIZE(vec)) {
1485         if (SCM_UNBOUNDP(fallback)) 
1486             Scm_Error("index out of range: %d", index);
1487         return fallback;
1488     }
1489     elt = vec->elements[index];
1490     r = SCM_MAKE_INT(elt);
1491     return r;
1492 }
1493 
1494 ScmObj Scm_U16VectorSet(ScmU16Vector *vec, int index, ScmObj val, int clamp)
1495 {
1496     unsigned short elt;
1497     if (index < 0 || index >= SCM_U16VECTOR_SIZE(vec))
1498         Scm_Error("index out of range: %d", index);
1499     SCM_UVECTOR_CHECK_MUTABLE(vec);
1500     elt = u16unbox(val, clamp);
1501     vec->elements[index] = elt;
1502     return SCM_OBJ(vec);
1503 }
1504 
1505 ScmObj Scm_U16VectorToList(ScmU16Vector *vec, int start, int end)
1506 {
1507     ScmObj head = SCM_NIL, tail;
1508     int i, size = SCM_U16VECTOR_SIZE(vec);
1509     SCM_CHECK_START_END(start, end, size);
1510     for (i=start; i<end; i++) {
1511         ScmObj obj;
1512         unsigned short elt = vec->elements[i];
1513         obj = SCM_MAKE_INT(elt);
1514         SCM_APPEND1(head, tail, obj);
1515     }
1516     return head;
1517 }
1518 
1519 ScmObj Scm_U16VectorToVector(ScmU16Vector *vec, int start, int end)
1520 {
1521     ScmObj ovec;
1522     int i, size = SCM_U16VECTOR_SIZE(vec);
1523     SCM_CHECK_START_END(start, end, size);
1524     ovec = Scm_MakeVector(end-start, SCM_UNDEFINED);
1525     for (i=start; i<end; i++) {
1526         ScmObj obj;
1527         unsigned short elt = vec->elements[i];
1528         obj = SCM_MAKE_INT(elt);
1529         SCM_VECTOR_ELEMENT(ovec, i-start) = obj;
1530     }
1531     return ovec;
1532 }
1533 
1534 ScmObj Scm_U16VectorCopy(ScmU16Vector *vec, int start, int end)
1535 {
1536     int size = SCM_U16VECTOR_SIZE(vec);
1537     SCM_CHECK_START_END(start, end, size);
1538     return Scm_MakeU16VectorFromArray(end-start,
1539                                      SCM_U16VECTOR_ELEMENTS(vec)+start);
1540 }
1541 
1542 ScmObj Scm_U16VectorCopyX(ScmU16Vector *dst,
1543                            int dstart,
1544                            ScmU16Vector *src,
1545                            int sstart,
1546                            int send)
1547 {
1548     int dlen = SCM_U16VECTOR_SIZE(dst);
1549     int slen = SCM_U16VECTOR_SIZE(src);
1550     int size;
1551     
1552     SCM_UVECTOR_CHECK_MUTABLE(dst);
1553     SCM_CHECK_START_END(sstart, send, slen);
1554 
1555     if (dstart < 0 || dstart >= dlen) return SCM_OBJ(dst);
1556     if (dlen - dstart > send - sstart)  size = send - sstart;
1557     else size = dlen - dstart;
1558 
1559     memcpy(SCM_U16VECTOR_ELEMENTS(dst) + dstart,
1560            SCM_U16VECTOR_ELEMENTS(src) + sstart,
1561            size * sizeof(unsigned short));
1562     return SCM_OBJ(dst);
1563 }
1564 
1565 
1566 /*---------------------------------------------------------------
1567  * S32Vector
1568  */
1569 
1570 /*
1571  * Class stuff
1572  */
1573 
1574 static void print_s32vector(ScmObj obj, ScmPort *out, ScmWriteContext *ctx)
1575 {
1576     int i;
1577     Scm_Printf(out, "#s32(");
1578     for (i=0; i<SCM_S32VECTOR_SIZE(obj); i++) {
1579         ScmInt32 elt = SCM_S32VECTOR_ELEMENTS(obj)[i];
1580         if (i != 0) Scm_Printf(out, " ");
1581         Scm_Printf(out, "%d", elt);
1582     }
1583     Scm_Printf(out, ")");
1584 }
1585 
1586 static int compare_s32vector(ScmObj x, ScmObj y, int equalp)
1587 {
1588     int len = SCM_S32VECTOR_SIZE(x), i;
1589     ScmInt32 xx, yy;
1590     if (SCM_S32VECTOR_SIZE(y) != len) return -1;
1591     for (i=0; i<len; i++) {
1592         xx = SCM_S32VECTOR_ELEMENTS(x)[i];
1593         yy = SCM_S32VECTOR_ELEMENTS(y)[i];
1594         if (!(xx == yy)) {
1595             return -1;
1596         }
1597     }
1598     return 0;
1599 }
1600 
1601 SCM_DEFINE_BUILTIN_CLASS(Scm_S32VectorClass,
1602                          print_s32vector, compare_s32vector, NULL, NULL,
1603                          uvector_cpl);
1604 
1605 /*
1606  * Constructor
1607  */
1608 static ScmS32Vector *make_s32vector(int size, ScmInt32 *eltp)
1609 {
1610     return (ScmS32Vector*)Scm_MakeUVector(SCM_CLASS_S32VECTOR, size, eltp);
1611 }
1612 
1613 ScmObj Scm_MakeS32Vector(int size, ScmInt32 fill)
1614 {
1615     ScmS32Vector *vec = make_s32vector(size, NULL);
1616     int i;
1617     for (i=0; i<size; i++) {
1618         vec->elements[i] = fill;
1619     }
1620     return SCM_OBJ(vec);
1621 }
1622 
1623 ScmObj Scm_MakeS32VectorFromArray(int size, const ScmInt32 array[])
1624 {
1625     ScmS32Vector *vec = make_s32vector(size, NULL);
1626     int i;
1627     for (i=0; i<size; i++) {
1628         vec->elements[i] = array[i];
1629     }
1630     return SCM_OBJ(vec);
1631 }
1632 
1633 ScmObj Scm_MakeS32VectorFromArrayShared(int size, ScmInt32 array[])
1634 {
1635     ScmS32Vector *vec = make_s32vector(size, array);
1636     return SCM_OBJ(vec);
1637 }
1638 
1639 ScmObj Scm_ListToS32Vector(ScmObj list, int clamp)
1640 {
1641     int length = Scm_Length(list), i;
1642     ScmS32Vector *vec;
1643     ScmObj cp;
1644 
1645     if (length < 0) Scm_Error("improper list not allowed: %S", list);
1646     vec = make_s32vector(length, NULL);
1647     for (i=0, cp=list; i<length; i++, cp = SCM_CDR(cp)) {
1648         ScmInt32 elt;
1649         ScmObj obj = SCM_CAR(cp);
1650         elt = Scm_GetInteger32Clamp(obj, clamp, NULL);
1651         vec->elements[i] = elt;
1652     }
1653     return SCM_OBJ(vec);
1654 }
1655 
1656 ScmObj Scm_VectorToS32Vector(ScmVector *ivec, int start, int end, int clamp)
1657 {
1658     int length = SCM_VECTOR_SIZE(ivec), i;
1659     ScmS32Vector *vec;
1660     SCM_CHECK_START_END(start, end, length);
1661     vec = make_s32vector(end-start, NULL);
1662     for (i=start; i<end; i++) {
1663         ScmInt32 elt;
1664         ScmObj obj = SCM_VECTOR_ELEMENT(ivec, i);
1665         elt = Scm_GetInteger32Clamp(obj, clamp, NULL);
1666         vec->elements[i-start] = elt;
1667     }
1668     return SCM_OBJ(vec);
1669 }
1670 
1671 /*
1672  * Accessors and modifiers
1673  */
1674 
1675 ScmObj Scm_S32VectorFill(ScmS32Vector *vec, ScmInt32 fill, int start, int end)
1676 {
1677     int i, size = SCM_S32VECTOR_SIZE(vec);
1678     SCM_CHECK_START_END(start, end, size);
1679     SCM_UVECTOR_CHECK_MUTABLE(vec);
1680     for (i=start; i<end; i++) vec->elements[i] = fill;
1681     return SCM_OBJ(vec);
1682 }
1683 
1684 ScmObj Scm_S32VectorRef(ScmS32Vector *vec, int index, ScmObj fallback)
1685 {
1686     ScmObj r;
1687     ScmInt32 elt;
1688     if (index < 0 || index >= SCM_S32VECTOR_SIZE(vec)) {
1689         if (SCM_UNBOUNDP(fallback)) 
1690             Scm_Error("index out of range: %d", index);
1691         return fallback;
1692     }
1693     elt = vec->elements[index];
1694     r = Scm_MakeInteger(elt);
1695     return r;
1696 }
1697 
1698 ScmObj Scm_S32VectorSet(ScmS32Vector *vec, int index, ScmObj val, int clamp)
1699 {
1700     ScmInt32 elt;
1701     if (index < 0 || index >= SCM_S32VECTOR_SIZE(vec))
1702         Scm_Error("index out of range: %d", index);
1703     SCM_UVECTOR_CHECK_MUTABLE(vec);
1704     elt = Scm_GetInteger32Clamp(val, clamp, NULL);
1705     vec->elements[index] = elt;
1706     return SCM_OBJ(vec);
1707 }
1708 
1709 ScmObj Scm_S32VectorToList(ScmS32Vector *vec, int start, int end)
1710 {
1711     ScmObj head = SCM_NIL, tail;
1712     int i, size = SCM_S32VECTOR_SIZE(vec);
1713     SCM_CHECK_START_END(start, end, size);
1714     for (i=start; i<end; i++) {
1715         ScmObj obj;
1716         ScmInt32 elt = vec->elements[i];
1717         obj = Scm_MakeInteger(elt);
1718         SCM_APPEND1(head, tail, obj);
1719     }
1720     return head;
1721 }
1722 
1723 ScmObj Scm_S32VectorToVector(ScmS32Vector *vec, int start, int end)
1724 {
1725     ScmObj ovec;
1726     int i, size = SCM_S32VECTOR_SIZE(vec);
1727     SCM_CHECK_START_END(start, end, size);
1728     ovec = Scm_MakeVector(end-start, SCM_UNDEFINED);
1729     for (i=start; i<end; i++) {
1730         ScmObj obj;
1731         ScmInt32 elt = vec->elements[i];
1732         obj = Scm_MakeInteger(elt);
1733         SCM_VECTOR_ELEMENT(ovec, i-start) = obj;
1734     }
1735     return ovec;
1736 }
1737 
1738 ScmObj Scm_S32VectorCopy(ScmS32Vector *vec, int start, int end)
1739 {
1740     int size = SCM_S32VECTOR_SIZE(vec);
1741     SCM_CHECK_START_END(start, end, size);
1742     return Scm_MakeS32VectorFromArray(end-start,
1743                                      SCM_S32VECTOR_ELEMENTS(vec)+start);
1744 }
1745 
1746 ScmObj Scm_S32VectorCopyX(ScmS32Vector *dst,
1747                            int dstart,
1748                            ScmS32Vector *src,
1749                            int sstart,
1750                            int send)
1751 {
1752     int dlen = SCM_S32VECTOR_SIZE(dst);
1753     int slen = SCM_S32VECTOR_SIZE(src);
1754     int size;
1755     
1756     SCM_UVECTOR_CHECK_MUTABLE(dst);
1757     SCM_CHECK_START_END(sstart, send, slen);
1758 
1759     if (dstart < 0 || dstart >= dlen) return SCM_OBJ(dst);
1760     if (dlen - dstart > send - sstart)  size = send - sstart;
1761     else size = dlen - dstart;
1762 
1763     memcpy(SCM_S32VECTOR_ELEMENTS(dst) + dstart,
1764            SCM_S32VECTOR_ELEMENTS(src) + sstart,
1765            size * sizeof(ScmInt32));
1766     return SCM_OBJ(dst);
1767 }
1768 
1769 
1770 /*---------------------------------------------------------------
1771  * U32Vector
1772  */
1773 
1774 /*
1775  * Class stuff
1776  */
1777 
1778 static void print_u32vector(ScmObj obj, ScmPort *out, ScmWriteContext *ctx)
1779 {
1780     int i;
1781     Scm_Printf(out, "#u32(");
1782     for (i=0; i<SCM_U32VECTOR_SIZE(obj); i++) {
1783         ScmUInt32 elt = SCM_U32VECTOR_ELEMENTS(obj)[i];
1784         if (i != 0) Scm_Printf(out, " ");
1785         Scm_Printf(out, "%u", elt);
1786     }
1787     Scm_Printf(out, ")");
1788 }
1789 
1790 static int compare_u32vector(ScmObj x, ScmObj y, int equalp)
1791 {
1792     int len = SCM_U32VECTOR_SIZE(x), i;
1793     ScmUInt32 xx, yy;
1794     if (SCM_U32VECTOR_SIZE(y) != len) return -1;
1795     for (i=0; i<len; i++) {
1796         xx = SCM_U32VECTOR_ELEMENTS(x)[i];
1797         yy = SCM_U32VECTOR_ELEMENTS(y)[i];
1798         if (!(xx == yy)) {
1799             return -1;
1800         }
1801     }
1802     return 0;
1803 }
1804 
1805 SCM_DEFINE_BUILTIN_CLASS(Scm_U32VectorClass,
1806                          print_u32vector, compare_u32vector, NULL, NULL,
1807                          uvector_cpl);
1808 
1809 /*
1810  * Constructor
1811  */
1812 static ScmU32Vector *make_u32vector(int size, ScmUInt32 *eltp)
1813 {
1814     return (ScmU32Vector*)Scm_MakeUVector(SCM_CLASS_U32VECTOR, size, eltp);
1815 }
1816 
1817 ScmObj Scm_MakeU32Vector(int size, ScmUInt32 fill)
1818 {
1819     ScmU32Vector *vec = make_u32vector(size, NULL);
1820     int i;
1821     for (i=0; i<size; i++) {
1822         vec->elements[i] = fill;
1823     }
1824     return SCM_OBJ(vec);
1825 }
1826 
1827 ScmObj Scm_MakeU32VectorFromArray(int size, const ScmUInt32 array[])
1828 {
1829     ScmU32Vector *vec = make_u32vector(size, NULL);
1830     int i;
1831     for (i=0; i<size; i++) {
1832         vec->elements[i] = array[i];
1833     }
1834     return SCM_OBJ(vec);
1835 }
1836 
1837 ScmObj Scm_MakeU32VectorFromArrayShared(int size, ScmUInt32 array[])
1838 {
1839     ScmU32Vector *vec = make_u32vector(size, array);
1840     return SCM_OBJ(vec);
1841 }
1842 
1843 ScmObj Scm_ListToU32Vector(ScmObj list, int clamp)
1844 {
1845     int length = Scm_Length(list), i;
1846     ScmU32Vector *vec;
1847     ScmObj cp;
1848 
1849     if (length < 0) Scm_Error("improper list not allowed: %S", list);
1850     vec = make_u32vector(length, NULL);
1851     for (i=0, cp=list; i<length; i++, cp = SCM_CDR(cp)) {
1852         ScmUInt32 elt;
1853         ScmObj obj = SCM_CAR(cp);
1854         elt = Scm_GetIntegerU32Clamp(obj, clamp, NULL);
1855         vec->elements[i] = elt;
1856     }
1857     return SCM_OBJ(vec);
1858 }
1859 
1860 ScmObj Scm_VectorToU32Vector(ScmVector *ivec, int start, int end, int clamp)
1861 {
1862     int length = SCM_VECTOR_SIZE(ivec), i;
1863     ScmU32Vector *vec;
1864     SCM_CHECK_START_END(start, end, length);
1865     vec = make_u32vector(end-start, NULL);
1866     for (i=start; i<end; i++) {
1867         ScmUInt32 elt;
1868         ScmObj obj = SCM_VECTOR_ELEMENT(ivec, i);
1869         elt = Scm_GetIntegerU32Clamp(obj, clamp, NULL);
1870         vec->elements[i-start] = elt;
1871     }
1872     return SCM_OBJ(vec);
1873 }
1874 
1875 /*
1876  * Accessors and modifiers
1877  */
1878 
1879 ScmObj Scm_U32VectorFill(ScmU32Vector *vec, ScmUInt32 fill, int start, int end)
1880 {
1881     int i, size = SCM_U32VECTOR_SIZE(vec);
1882     SCM_CHECK_START_END(start, end, size);
1883     SCM_UVECTOR_CHECK_MUTABLE(vec);
1884     for (i=start; i<end; i++) vec->elements[i] = fill;
1885     return SCM_OBJ(vec);
1886 }
1887 
1888 ScmObj Scm_U32VectorRef(ScmU32Vector *vec, int index, ScmObj fallback)
1889 {
1890     ScmObj r;
1891     ScmUInt32 elt;
1892     if (index < 0 || index >= SCM_U32VECTOR_SIZE(vec)) {
1893         if (SCM_UNBOUNDP(fallback)) 
1894             Scm_Error("index out of range: %d", index);
1895         return fallback;
1896     }
1897     elt = vec->elements[index];
1898     r = Scm_MakeIntegerU(elt);
1899     return r;
1900 }
1901 
1902 ScmObj Scm_U32VectorSet(ScmU32Vector *vec, int index, ScmObj val, int clamp)
1903 {
1904     ScmUInt32 elt;
1905     if (index < 0 || index >= SCM_U32VECTOR_SIZE(vec))
1906         Scm_Error("index out of range: %d", index);
1907     SCM_UVECTOR_CHECK_MUTABLE(vec);
1908     elt = Scm_GetIntegerU32Clamp(val, clamp, NULL);
1909     vec->elements[index] = elt;
1910     return SCM_OBJ(vec);
1911 }
1912 
1913 ScmObj Scm_U32VectorToList(ScmU32Vector *vec, int start, int end)
1914 {
1915     ScmObj head = SCM_NIL, tail;
1916     int i, size = SCM_U32VECTOR_SIZE(vec);
1917     SCM_CHECK_START_END(start, end, size);
1918     for (i=start; i<end; i++) {
1919         ScmObj obj;
1920         ScmUInt32 elt = vec->elements[i];
1921         obj = Scm_MakeIntegerU(elt);
1922         SCM_APPEND1(head, tail, obj);
1923     }
1924     return head;
1925 }
1926 
1927 ScmObj Scm_U32VectorToVector(ScmU32Vector *vec, int start, int end)
1928 {
1929     ScmObj ovec;
1930     int i, size = SCM_U32VECTOR_SIZE(vec);
1931     SCM_CHECK_START_END(start, end, size);
1932     ovec = Scm_MakeVector(end-start, SCM_UNDEFINED);
1933     for (i=start; i<end; i++) {
1934         ScmObj obj;
1935         ScmUInt32 elt = vec->elements[i];
1936         obj = Scm_MakeIntegerU(elt);
1937         SCM_VECTOR_ELEMENT(ovec, i-start) = obj;
1938     }
1939     return ovec;
1940 }
1941 
1942 ScmObj Scm_U32VectorCopy(ScmU32Vector *vec, int start, int end)
1943 {
1944     int size = SCM_U32VECTOR_SIZE(vec);
1945     SCM_CHECK_START_END(start, end, size);
1946     return Scm_MakeU32VectorFromArray(end-start,
1947                                      SCM_U32VECTOR_ELEMENTS(vec)+start);
1948 }
1949 
1950 ScmObj Scm_U32VectorCopyX(ScmU32Vector *dst,
1951                            int dstart,
1952                            ScmU32Vector *src,
1953                            int sstart,
1954                            int send)
1955 {
1956     int dlen = SCM_U32VECTOR_SIZE(dst);
1957     int slen = SCM_U32VECTOR_SIZE(src);
1958     int size;
1959     
1960     SCM_UVECTOR_CHECK_MUTABLE(dst);
1961     SCM_CHECK_START_END(sstart, send, slen);
1962 
1963     if (dstart < 0 || dstart >= dlen) return SCM_OBJ(dst);
1964     if (dlen - dstart > send - sstart)  size = send - sstart;
1965     else size = dlen - dstart;
1966 
1967     memcpy(SCM_U32VECTOR_ELEMENTS(dst) + dstart,
1968            SCM_U32VECTOR_ELEMENTS(src) + sstart,
1969            size * sizeof(ScmUInt32));
1970     return SCM_OBJ(dst);
1971 }
1972 
1973 
1974 /*---------------------------------------------------------------
1975  * S64Vector
1976  */
1977 
1978 /*
1979  * Class stuff
1980  */
1981 
1982 static void print_s64vector(ScmObj obj, ScmPort *out, ScmWriteContext *ctx)
1983 {
1984     int i;
1985     Scm_Printf(out, "#s64(");
1986     for (i=0; i<SCM_S64VECTOR_SIZE(obj); i++) {
1987         ScmInt64 elt = SCM_S64VECTOR_ELEMENTS(obj)[i];
1988         if (i != 0) Scm_Printf(out, " ");
1989         int64print(out, elt);
1990     }
1991     Scm_Printf(out, ")");
1992 }
1993 
1994 static int compare_s64vector(ScmObj x, ScmObj y, int equalp)
1995 {
1996     int len = SCM_S64VECTOR_SIZE(x), i;
1997     ScmInt64 xx, yy;
1998     if (SCM_S64VECTOR_SIZE(y) != len) return -1;
1999     for (i=0; i<len; i++) {
2000         xx = SCM_S64VECTOR_ELEMENTS(x)[i];
2001         yy = SCM_S64VECTOR_ELEMENTS(y)[i];
2002         if (!int64eqv(xx, yy)) {
2003             return -1;
2004         }
2005     }
2006     return 0;
2007 }
2008 
2009 SCM_DEFINE_BUILTIN_CLASS(Scm_S64VectorClass,
2010                          print_s64vector, compare_s64vector, NULL, NULL,
2011                          uvector_cpl);
2012 
2013 /*
2014  * Constructor
2015  */
2016 static ScmS64Vector *make_s64vector(int size, ScmInt64 *eltp)
2017 {
2018     return (ScmS64Vector*)Scm_MakeUVector(SCM_CLASS_S64VECTOR, size, eltp);
2019 }
2020 
2021 ScmObj Scm_MakeS64Vector(int size, ScmInt64 fill)
2022 {
2023     ScmS64Vector *vec = make_s64vector(size, NULL);
2024     int i;
2025     for (i=0; i<size; i++) {
2026         vec->elements[i] = fill;
2027     }
2028     return SCM_OBJ(vec);
2029 }
2030 
2031 ScmObj Scm_MakeS64VectorFromArray(int size, const ScmInt64 array[])
2032 {
2033     ScmS64Vector *vec = make_s64vector(size, NULL);
2034     int i;
2035     for (i=0; i<size; i++) {
2036         vec->elements[i] = array[i];
2037     }
2038     return SCM_OBJ(vec);
2039 }
2040 
2041 ScmObj Scm_MakeS64VectorFromArrayShared(int size, ScmInt64 array[])
2042 {
2043     ScmS64Vector *vec = make_s64vector(size, array);
2044     return SCM_OBJ(vec);
2045 }
2046 
2047 ScmObj Scm_ListToS64Vector(ScmObj list, int clamp)
2048 {
2049     int length = Scm_Length(list), i;
2050     ScmS64Vector *vec;
2051     ScmObj cp;
2052 
2053     if (length < 0) Scm_Error("improper list not allowed: %S", list);
2054     vec = make_s64vector(length, NULL);
2055     for (i=0, cp=list; i<length; i++, cp = SCM_CDR(cp)) {
2056         ScmInt64 elt;
2057         ScmObj obj = SCM_CAR(cp);
2058         elt = Scm_GetInteger64Clamp(obj, clamp, NULL);
2059         vec->elements[i] = elt;
2060     }
2061     return SCM_OBJ(vec);
2062 }
2063 
2064 ScmObj Scm_VectorToS64Vector(ScmVector *ivec, int start, int end, int clamp)
2065 {
2066     int length = SCM_VECTOR_SIZE(ivec), i;
2067     ScmS64Vector *vec;
2068     SCM_CHECK_START_END(start, end, length);
2069     vec = make_s64vector(end-start, NULL);
2070     for (i=start; i<end; i++) {
2071         ScmInt64 elt;
2072         ScmObj obj = SCM_VECTOR_ELEMENT(ivec, i);
2073         elt = Scm_GetInteger64Clamp(obj, clamp, NULL);
2074         vec->elements[i-start] = elt;
2075     }
2076     return SCM_OBJ(vec);
2077 }
2078 
2079 /*
2080  * Accessors and modifiers
2081  */
2082 
2083 ScmObj Scm_S64VectorFill(ScmS64Vector *vec, ScmInt64 fill, int start, int end)
2084 {
2085     int i, size = SCM_S64VECTOR_SIZE(vec);
2086     SCM_CHECK_START_END(start, end, size);
2087     SCM_UVECTOR_CHECK_MUTABLE(vec);
2088     for (i=start; i<end; i++) vec->elements[i] = fill;
2089     return SCM_OBJ(vec);
2090 }
2091 
2092 ScmObj Scm_S64VectorRef(ScmS64Vector *vec, int index, ScmObj fallback)
2093 {
2094     ScmObj r;
2095     ScmInt64 elt;
2096     if (index < 0 || index >= SCM_S64VECTOR_SIZE(vec)) {
2097         if (SCM_UNBOUNDP(fallback)) 
2098             Scm_Error("index out of range: %d", index);
2099         return fallback;
2100     }
2101     elt = vec->elements[index];
2102     r = Scm_MakeInteger64(elt);
2103     return r;
2104 }
2105 
2106 ScmObj Scm_S64VectorSet(ScmS64Vector *vec, int index, ScmObj val, int clamp)
2107 {
2108     ScmInt64 elt;
2109     if (index < 0 || index >= SCM_S64VECTOR_SIZE(vec))
2110         Scm_Error("index out of range: %d", index);
2111     SCM_UVECTOR_CHECK_MUTABLE(vec);
2112     elt = Scm_GetInteger64Clamp(val, clamp, NULL);
2113     vec->elements[index] = elt;
2114     return SCM_OBJ(vec);
2115 }
2116 
2117 ScmObj Scm_S64VectorToList(ScmS64Vector *vec, int start, int end)
2118 {
2119     ScmObj head = SCM_NIL, tail;
2120     int i, size = SCM_S64VECTOR_SIZE(vec);
2121     SCM_CHECK_START_END(start, end, size);
2122     for (i=start; i<end; i++) {
2123         ScmObj obj;
2124         ScmInt64 elt = vec->elements[i];
2125         obj = Scm_MakeInteger64(elt);
2126         SCM_APPEND1(head, tail, obj);
2127     }
2128     return head;
2129 }
2130 
2131 ScmObj Scm_S64VectorToVector(ScmS64Vector *vec, int start, int end)
2132 {
2133     ScmObj ovec;
2134     int i, size = SCM_S64VECTOR_SIZE(vec);
2135     SCM_CHECK_START_END(start, end, size);
2136     ovec = Scm_MakeVector(end-start, SCM_UNDEFINED);
2137     for (i=start; i<end; i++) {
2138         ScmObj obj;
2139         ScmInt64 elt = vec->elements[i];
2140         obj = Scm_MakeInteger64(elt);
2141         SCM_VECTOR_ELEMENT(ovec, i-start) = obj;
2142     }
2143     return ovec;
2144 }
2145 
2146 ScmObj Scm_S64VectorCopy(ScmS64Vector *vec, int start, int end)
2147 {
2148     int size = SCM_S64VECTOR_SIZE(vec);
2149     SCM_CHECK_START_END(start, end, size);
2150     return Scm_MakeS64VectorFromArray(end-start,
2151                                      SCM_S64VECTOR_ELEMENTS(vec)+start);
2152 }
2153 
2154 ScmObj Scm_S64VectorCopyX(ScmS64Vector *dst,
2155                            int dstart,
2156                            ScmS64Vector *src,
2157                            int sstart,
2158                            int send)
2159 {
2160     int dlen = SCM_S64VECTOR_SIZE(dst);
2161     int slen = SCM_S64VECTOR_SIZE(src);
2162     int size;
2163     
2164     SCM_UVECTOR_CHECK_MUTABLE(dst);
2165     SCM_CHECK_START_END(sstart, send, slen);
2166 
2167     if (dstart < 0 || dstart >= dlen) return SCM_OBJ(dst);
2168     if (dlen - dstart > send - sstart)  size = send - sstart;
2169     else size = dlen - dstart;
2170 
2171     memcpy(SCM_S64VECTOR_ELEMENTS(dst) + dstart,
2172            SCM_S64VECTOR_ELEMENTS(src) + sstart,
2173            size * sizeof(ScmInt64));
2174     return SCM_OBJ(dst);
2175 }
2176 
2177 
2178 /*---------------------------------------------------------------
2179  * U64Vector
2180  */
2181 
2182 /*
2183  * Class stuff
2184  */
2185 
2186 static void print_u64vector(ScmObj obj, ScmPort *out, ScmWriteContext *ctx)
2187 {
2188     int i;
2189     Scm_Printf(out, "#u64(");
2190     for (i=0; i<SCM_U64VECTOR_SIZE(obj); i++) {
2191         ScmUInt64 elt = SCM_U64VECTOR_ELEMENTS(obj)[i];
2192         if (i != 0) Scm_Printf(out, " ");
2193         uint64print(out, elt);
2194     }
2195     Scm_Printf(out, ")");
2196 }
2197 
2198 static int compare_u64vector(ScmObj x, ScmObj y, int equalp)
2199 {
2200     int len = SCM_U64VECTOR_SIZE(x), i;
2201     ScmUInt64 xx, yy;
2202     if (SCM_U64VECTOR_SIZE(y) != len) return -1;
2203     for (i=0; i<len; i++) {
2204         xx = SCM_U64VECTOR_ELEMENTS(x)[i];
2205         yy = SCM_U64VECTOR_ELEMENTS(y)[i];
2206         if (!uint64eqv(xx, yy)) {
2207             return -1;
2208         }
2209     }
2210     return 0;
2211 }
2212 
2213 SCM_DEFINE_BUILTIN_CLASS(Scm_U64VectorClass,
2214                          print_u64vector, compare_u64vector, NULL, NULL,
2215                          uvector_cpl);
2216 
2217 /*
2218  * Constructor
2219  */
2220 static ScmU64Vector *make_u64vector(int size, ScmUInt64 *eltp)
2221 {
2222     return (ScmU64Vector*)Scm_MakeUVector(SCM_CLASS_U64VECTOR, size, eltp);
2223 }
2224 
2225 ScmObj Scm_MakeU64Vector(int size, ScmUInt64 fill)
2226 {
2227     ScmU64Vector *vec = make_u64vector(size, NULL);
2228     int i;
2229     for (i=0; i<size; i++) {
2230         vec->elements[i] = fill;
2231     }
2232     return SCM_OBJ(vec);
2233 }
2234 
2235 ScmObj Scm_MakeU64VectorFromArray(int size, const ScmUInt64 array[])
2236 {
2237     ScmU64Vector *vec = make_u64vector(size, NULL);
2238     int i;
2239     for (i=0; i<size; i++) {
2240         vec->elements[i] = array[i];
2241     }
2242     return SCM_OBJ(vec);
2243 }
2244 
2245 ScmObj Scm_MakeU64VectorFromArrayShared(int size, ScmUInt64 array[])
2246 {
2247     ScmU64Vector *vec = make_u64vector(size, array);
2248     return SCM_OBJ(vec);
2249 }
2250 
2251 ScmObj Scm_ListToU64Vector(ScmObj list, int clamp)
2252 {
2253     int length = Scm_Length(list), i;
2254     ScmU64Vector *vec;
2255     ScmObj cp;
2256 
2257     if (length < 0) Scm_Error("improper list not allowed: %S", list);
2258     vec = make_u64vector(length, NULL);
2259     for (i=0, cp=list; i<length; i++, cp = SCM_CDR(cp)) {
2260         ScmUInt64 elt;
2261         ScmObj obj = SCM_CAR(cp);
2262         elt = Scm_GetIntegerU64Clamp(obj, clamp, NULL);
2263         vec->elements[i] = elt;
2264     }
2265     return SCM_OBJ(vec);
2266 }
2267 
2268 ScmObj Scm_VectorToU64Vector(ScmVector *ivec, int start, int end, int clamp)
2269 {
2270     int length = SCM_VECTOR_SIZE(ivec), i;
2271     ScmU64Vector *vec;
2272     SCM_CHECK_START_END(start, end, length);
2273     vec = make_u64vector(end-start, NULL);
2274     for (i=start; i<end; i++) {
2275         ScmUInt64 elt;
2276         ScmObj obj = SCM_VECTOR_ELEMENT(ivec, i);
2277         elt = Scm_GetIntegerU64Clamp(obj, clamp, NULL);
2278         vec->elements[i-start] = elt;
2279     }
2280     return SCM_OBJ(vec);
2281 }
2282 
2283 /*
2284  * Accessors and modifiers
2285  */
2286 
2287 ScmObj Scm_U64VectorFill(ScmU64Vector *vec, ScmUInt64 fill, int start, int end)
2288 {
2289     int i, size = SCM_U64VECTOR_SIZE(vec);
2290     SCM_CHECK_START_END(start, end, size);
2291     SCM_UVECTOR_CHECK_MUTABLE(vec);
2292     for (i=start; i<end; i++) vec->elements[i] = fill;
2293     return SCM_OBJ(vec);
2294 }
2295 
2296 ScmObj Scm_U64VectorRef(ScmU64Vector *vec, int index, ScmObj fallback)
2297 {
2298     ScmObj r;
2299     ScmUInt64 elt;
2300     if (index < 0 || index >= SCM_U64VECTOR_SIZE(vec)) {
2301         if (SCM_UNBOUNDP(fallback)) 
2302             Scm_Error("index out of range: %d", index);
2303         return fallback;
2304     }
2305     elt = vec->elements[index];
2306     r = Scm_MakeIntegerU64(elt);
2307     return r;
2308 }
2309 
2310 ScmObj Scm_U64VectorSet(ScmU64Vector *vec, int index, ScmObj val, int clamp)
2311 {
2312     ScmUInt64 elt;
2313     if (index < 0 || index >= SCM_U64VECTOR_SIZE(vec))
2314         Scm_Error("index out of range: %d", index);
2315     SCM_UVECTOR_CHECK_MUTABLE(vec);
2316     elt = Scm_GetIntegerU64Clamp(val, clamp, NULL);
2317     vec->elements[index] = elt;
2318     return SCM_OBJ(vec);
2319 }
2320 
2321 ScmObj Scm_U64VectorToList(ScmU64Vector *vec, int start, int end)
2322 {
2323     ScmObj head = SCM_NIL, tail;
2324     int i, size = SCM_U64VECTOR_SIZE(vec);
2325     SCM_CHECK_START_END(start, end, size);
2326     for (i=start; i<end; i++) {
2327         ScmObj obj;
2328         ScmUInt64 elt = vec->elements[i];
2329         obj = Scm_MakeIntegerU64(elt);
2330         SCM_APPEND1(head, tail, obj);
2331     }
2332     return head;
2333 }
2334 
2335 ScmObj Scm_U64VectorToVector(ScmU64Vector *vec, int start, int end)
2336 {
2337     ScmObj ovec;
2338     int i, size = SCM_U64VECTOR_SIZE(vec);
2339     SCM_CHECK_START_END(start, end, size);
2340     ovec = Scm_MakeVector(end-start, SCM_UNDEFINED);
2341     for (i=start; i<end; i++) {
2342         ScmObj obj;
2343         ScmUInt64 elt = vec->elements[i];
2344         obj = Scm_MakeIntegerU64(elt);
2345         SCM_VECTOR_ELEMENT(ovec, i-start) = obj;
2346     }
2347     return ovec;
2348 }
2349 
2350 ScmObj Scm_U64VectorCopy(ScmU64Vector *vec, int start, int end)
2351 {
2352     int size = SCM_U64VECTOR_SIZE(vec);
2353     SCM_CHECK_START_END(start, end, size);
2354     return Scm_MakeU64VectorFromArray(end-start,
2355                                      SCM_U64VECTOR_ELEMENTS(vec)+start);
2356 }
2357 
2358 ScmObj Scm_U64VectorCopyX(ScmU64Vector *dst,
2359                            int dstart,
2360                            ScmU64Vector *src,
2361                            int sstart,
2362                            int send)
2363 {
2364     int dlen = SCM_U64VECTOR_SIZE(dst);
2365     int slen = SCM_U64VECTOR_SIZE(src);
2366     int size;
2367     
2368     SCM_UVECTOR_CHECK_MUTABLE(dst);
2369     SCM_CHECK_START_END(sstart, send, slen);
2370 
2371     if (dstart < 0 || dstart >= dlen) return SCM_OBJ(dst);
2372     if (dlen - dstart > send - sstart)  size = send - sstart;
2373     else size = dlen - dstart;
2374 
2375     memcpy(SCM_U64VECTOR_ELEMENTS(dst) + dstart,
2376            SCM_U64VECTOR_ELEMENTS(src) + sstart,
2377            size * sizeof(ScmUInt64));
2378     return SCM_OBJ(dst);
2379 }
2380 
2381 
2382 /*---------------------------------------------------------------
2383  * F32Vector
2384  */
2385 
2386 /*
2387  * Class stuff
2388  */
2389 
2390 static void print_f32vector(ScmObj obj, ScmPort *out, ScmWriteContext *ctx)
2391 {
2392     int i;
2393     Scm_Printf(out, "#f32(");
2394     for (i=0; i<SCM_F32VECTOR_SIZE(obj); i++) {
2395         float elt = SCM_F32VECTOR_ELEMENTS(obj)[i];
2396         if (i != 0) Scm_Printf(out, " ");
2397         Scm_Printf(out, "%.9g", elt);
2398     }
2399     Scm_Printf(out, ")");
2400 }
2401 
2402 static int compare_f32vector(ScmObj x, ScmObj y, int equalp)
2403 {
2404     int len = SCM_F32VECTOR_SIZE(x), i;
2405     float xx, yy;
2406     if (SCM_F32VECTOR_SIZE(y) != len) return -1;
2407     for (i=0; i<len; i++) {
2408         xx = SCM_F32VECTOR_ELEMENTS(x)[i];
2409         yy = SCM_F32VECTOR_ELEMENTS(y)[i];
2410         if (!(xx == yy)) {
2411             return -1;
2412         }
2413     }
2414     return 0;
2415 }
2416 
2417 SCM_DEFINE_BUILTIN_CLASS(Scm_F32VectorClass,
2418                          print_f32vector, compare_f32vector, NULL, NULL,
2419                          uvector_cpl);
2420 
2421 /*
2422  * Constructor
2423  */
2424 static ScmF32Vector *make_f32vector(int size, float *eltp)
2425 {
2426     return (ScmF32Vector*)Scm_MakeUVector(SCM_CLASS_F32VECTOR, size, eltp);
2427 }
2428 
2429 ScmObj Scm_MakeF32Vector(int size, float fill)
2430 {
2431     ScmF32Vector *vec = make_f32vector(size, NULL);
2432     int i;
2433     for (i=0; i<size; i++) {
2434         vec->elements[i] = fill;
2435     }
2436     return SCM_OBJ(vec);
2437 }
2438 
2439 ScmObj Scm_MakeF32VectorFromArray(int size, const float array[])
2440 {
2441     ScmF32Vector *vec = make_f32vector(size, NULL);
2442     int i;
2443     for (i=0; i<size; i++) {
2444         vec->elements[i] = array[i];
2445     }
2446     return SCM_OBJ(vec);
2447 }
2448 
2449 ScmObj Scm_MakeF32VectorFromArrayShared(int size, float array[])
2450 {
2451     ScmF32Vector *vec = make_f32vector(size, array);
2452     return SCM_OBJ(vec);
2453 }
2454 
2455 ScmObj Scm_ListToF32Vector(ScmObj list, int clamp)
2456 {
2457     int length = Scm_Length(list), i;
2458     ScmF32Vector *vec;
2459     ScmObj cp;
2460 
2461     if (length < 0) Scm_Error("improper list not allowed: %S", list);
2462     vec = make_f32vector(length, NULL);
2463     for (i=0, cp=list; i<length; i++, cp = SCM_CDR(cp)) {
2464         float elt;
2465         ScmObj obj = SCM_CAR(cp);
2466         elt = (float)Scm_GetDouble(obj);
2467         vec->elements[i] = elt;
2468     }
2469     return SCM_OBJ(vec);
2470 }
2471 
2472 ScmObj Scm_VectorToF32Vector(ScmVector *ivec, int start, int end, int clamp)
2473 {
2474     int length = SCM_VECTOR_SIZE(ivec), i;
2475     ScmF32Vector *vec;
2476     SCM_CHECK_START_END(start, end, length);
2477     vec = make_f32vector(end-start, NULL);
2478     for (i=start; i<end; i++) {
2479         float elt;
2480         ScmObj obj = SCM_VECTOR_ELEMENT(ivec, i);
2481         elt = (float)Scm_GetDouble(obj);
2482         vec->elements[i-start] = elt;
2483     }
2484     return SCM_OBJ(vec);
2485 }
2486 
2487 /*
2488  * Accessors and modifiers
2489  */
2490 
2491 ScmObj Scm_F32VectorFill(ScmF32Vector *vec, float fill, int start, int end)
2492 {
2493     int i, size = SCM_F32VECTOR_SIZE(vec);
2494     SCM_CHECK_START_END(start, end, size);
2495     SCM_UVECTOR_CHECK_MUTABLE(vec);
2496     for (i=start; i<end; i++) vec->elements[i] = fill;
2497     return SCM_OBJ(vec);
2498 }
2499 
2500 ScmObj Scm_F32VectorRef(ScmF32Vector *vec, int index, ScmObj fallback)
2501 {
2502     ScmObj r;
2503     float elt;
2504     if (index < 0 || index >= SCM_F32VECTOR_SIZE(vec)) {
2505         if (SCM_UNBOUNDP(fallback)) 
2506             Scm_Error("index out of range: %d", index);
2507         return fallback;
2508     }
2509     elt = vec->elements[index];
2510     r = Scm_MakeFlonum((double)elt);
2511     return r;
2512 }
2513 
2514 ScmObj Scm_F32VectorSet(ScmF32Vector *vec, int index, ScmObj val, int clamp)
2515 {
2516     float elt;
2517     if (index < 0 || index >= SCM_F32VECTOR_SIZE(vec))
2518         Scm_Error("index out of range: %d", index);
2519     SCM_UVECTOR_CHECK_MUTABLE(vec);
2520     elt = (float)Scm_GetDouble(val);
2521     vec->elements[index] = elt;
2522     return SCM_OBJ(vec);
2523 }
2524 
2525 ScmObj Scm_F32VectorToList(ScmF32Vector *vec, int start, int end)
2526 {
2527     ScmObj head = SCM_NIL, tail;
2528     int i, size = SCM_F32VECTOR_SIZE(vec);
2529     SCM_CHECK_START_END(start, end, size);
2530     for (i=start; i<end; i++) {
2531         ScmObj obj;
2532         float elt = vec->elements[i];
2533         obj = Scm_MakeFlonum((double)elt);
2534         SCM_APPEND1(head, tail, obj);
2535     }
2536     return head;
2537 }
2538 
2539 ScmObj Scm_F32VectorToVector(ScmF32Vector *vec, int start, int end)
2540 {
2541     ScmObj ovec;
2542     int i, size = SCM_F32VECTOR_SIZE(vec);
2543     SCM_CHECK_START_END(start, end, size);
2544     ovec = Scm_MakeVector(end-start, SCM_UNDEFINED);
2545     for (i=start; i<end; i++) {
2546         ScmObj obj;
2547         float elt = vec->elements[i];
2548         obj = Scm_MakeFlonum((double)elt);
2549         SCM_VECTOR_ELEMENT(ovec, i-start) = obj;
2550     }
2551     return ovec;
2552 }
2553 
2554 ScmObj Scm_F32VectorCopy(ScmF32Vector *vec, int start, int end)
2555 {
2556     int size = SCM_F32VECTOR_SIZE(vec);
2557     SCM_CHECK_START_END(start, end, size);
2558     return Scm_MakeF32VectorFromArray(end-start,
2559                                      SCM_F32VECTOR_ELEMENTS(vec)+start);
2560 }
2561 
2562 ScmObj Scm_F32VectorCopyX(ScmF32Vector *dst,
2563                            int dstart,
2564                            ScmF32Vector *src,
2565                            int sstart,
2566                            int send)
2567 {
2568     int dlen = SCM_F32VECTOR_SIZE(dst);
2569     int slen = SCM_F32VECTOR_SIZE(src);
2570     int size;
2571     
2572     SCM_UVECTOR_CHECK_MUTABLE(dst);
2573     SCM_CHECK_START_END(sstart, send, slen);
2574 
2575     if (dstart < 0 || dstart >= dlen) return SCM_OBJ(dst);
2576     if (dlen - dstart > send - sstart)  size = send - sstart;
2577     else size = dlen - dstart;
2578 
2579     memcpy(SCM_F32VECTOR_ELEMENTS(dst) + dstart,
2580            SCM_F32VECTOR_ELEMENTS(src) + sstart,
2581            size * sizeof(float));
2582     return SCM_OBJ(dst);
2583 }
2584 
2585 
2586 /*---------------------------------------------------------------
2587  * F64Vector
2588  */
2589 
2590 /*
2591  * Class stuff
2592  */
2593 
2594 static void print_f64vector(ScmObj obj, ScmPort *out, ScmWriteContext *ctx)
2595 {
2596     int i;
2597     Scm_Printf(out, "#f64(");
2598     for (i=0; i<SCM_F64VECTOR_SIZE(obj); i++) {
2599         double elt = SCM_F64VECTOR_ELEMENTS(obj)[i];
2600         if (i != 0) Scm_Printf(out, " ");
2601         Scm_PrintDouble(out, (double)elt, 0);
2602     }
2603     Scm_Printf(out, ")");
2604 }
2605 
2606 static int compare_f64vector(ScmObj x, ScmObj y, int equalp)
2607 {
2608     int len = SCM_F64VECTOR_SIZE(x), i;
2609     double xx, yy;
2610     if (SCM_F64VECTOR_SIZE(y) != len) return -1;
2611     for (i=0; i<len; i++) {
2612         xx = SCM_F64VECTOR_ELEMENTS(x)[i];
2613         yy = SCM_F64VECTOR_ELEMENTS(y)[i];
2614         if (!(xx == yy)) {
2615             return -1;
2616         }
2617     }
2618     return 0;
2619 }
2620 
2621 SCM_DEFINE_BUILTIN_CLASS(Scm_F64VectorClass,
2622                          print_f64vector, compare_f64vector, NULL, NULL,
2623                          uvector_cpl);
2624 
2625 /*
2626  * Constructor
2627  */
2628 static ScmF64Vector *make_f64vector(int size, double *eltp)
2629 {
2630     return (ScmF64Vector*)Scm_MakeUVector(SCM_CLASS_F64VECTOR, size, eltp);
2631 }
2632 
2633 ScmObj Scm_MakeF64Vector(int size, double fill)
2634 {
2635     ScmF64Vector *vec = make_f64vector(size, NULL);
2636     int i;
2637     for (i=0; i<size; i++) {
2638         vec->elements[i] = fill;
2639     }
2640     return SCM_OBJ(vec);
2641 }
2642 
2643 ScmObj Scm_MakeF64VectorFromArray(int size, const double array[])
2644 {
2645     ScmF64Vector *vec = make_f64vector(size, NULL);
2646     int i;
2647     for (i=0; i<size; i++) {
2648         vec->elements[i] = array[i];
2649     }
2650     return SCM_OBJ(vec);
2651 }
2652 
2653 ScmObj Scm_MakeF64VectorFromArrayShared(int size, double array[])
2654 {
2655     ScmF64Vector *vec = make_f64vector(size, array);
2656     return SCM_OBJ(vec);
2657 }
2658 
2659 ScmObj Scm_ListToF64Vector(ScmObj list, int clamp)
2660 {
2661     int length = Scm_Length(list), i;
2662     ScmF64Vector *vec;
2663     ScmObj cp;
2664 
2665     if (length < 0) Scm_Error("improper list not allowed: %S", list);
2666     vec = make_f64vector(length, NULL);
2667     for (i=0, cp=list; i<length; i++, cp = SCM_CDR(cp)) {
2668         double elt;
2669         ScmObj obj = SCM_CAR(cp);
2670         elt = Scm_GetDouble(obj);
2671         vec->elements[i] = elt;
2672     }
2673     return SCM_OBJ(vec);
2674 }
2675 
2676 ScmObj Scm_VectorToF64Vector(ScmVector *ivec, int start, int end, int clamp)
2677 {
2678     int length = SCM_VECTOR_SIZE(ivec), i;
2679     ScmF64Vector *vec;
2680     SCM_CHECK_START_END(start, end, length);
2681     vec = make_f64vector(end-start, NULL);
2682     for (i=start; i<end; i++) {
2683         double elt;
2684         ScmObj obj = SCM_VECTOR_ELEMENT(ivec, i);
2685         elt = Scm_GetDouble(obj);
2686         vec->elements[i-start] = elt;
2687     }
2688     return SCM_OBJ(vec);
2689 }
2690 
2691 /*
2692  * Accessors and modifiers
2693  */
2694 
2695 ScmObj Scm_F64VectorFill(ScmF64Vector *vec, double fill, int start, int end)
2696 {
2697     int i, size = SCM_F64VECTOR_SIZE(vec);
2698     SCM_CHECK_START_END(start, end, size);
2699     SCM_UVECTOR_CHECK_MUTABLE(vec);
2700     for (i=start; i<end; i++) vec->elements[i] = fill;
2701     return SCM_OBJ(vec);
2702 }
2703 
2704 ScmObj Scm_F64VectorRef(ScmF64Vector *vec, int index, ScmObj fallback)
2705 {
2706     ScmObj r;
2707     double elt;
2708     if (index < 0 || index >= SCM_F64VECTOR_SIZE(vec)) {
2709         if (SCM_UNBOUNDP(fallback)) 
2710             Scm_Error("index out of range: %d", index);
2711         return fallback;
2712     }
2713     elt = vec->elements[index];
2714     r = Scm_MakeFlonum(elt);
2715     return r;
2716 }
2717 
2718 ScmObj Scm_F64VectorSet(ScmF64Vector *vec, int index, ScmObj val, int clamp)
2719 {
2720     double elt;
2721     if (index < 0 || index >= SCM_F64VECTOR_SIZE(vec))
2722         Scm_Error("index out of range: %d", index);
2723     SCM_UVECTOR_CHECK_MUTABLE(vec);
2724     elt = Scm_GetDouble(val);
2725     vec->elements[index] = elt;
2726     return SCM_OBJ(vec);
2727 }
2728 
2729 ScmObj Scm_F64VectorToList(ScmF64Vector *vec, int start, int end)
2730 {
2731     ScmObj head = SCM_NIL, tail;
2732     int i, size = SCM_F64VECTOR_SIZE(vec);
2733     SCM_CHECK_START_END(start, end, size);
2734     for (i=start; i<end; i++) {
2735         ScmObj obj;
2736         double elt = vec->elements[i];
2737         obj = Scm_MakeFlonum(elt);
2738         SCM_APPEND1(head, tail, obj);
2739     }
2740     return head;
2741 }
2742 
2743 ScmObj Scm_F64VectorToVector(ScmF64Vector *vec, int start, int end)
2744 {
2745     ScmObj ovec;
2746     int i, size = SCM_F64VECTOR_SIZE(vec);
2747     SCM_CHECK_START_END(start, end, size);
2748     ovec = Scm_MakeVector(end-start, SCM_UNDEFINED);
2749     for (i=start; i<end; i++) {
2750         ScmObj obj;
2751         double elt = vec->elements[i];
2752         obj = Scm_MakeFlonum(elt);
2753         SCM_VECTOR_ELEMENT(ovec, i-start) = obj;
2754     }
2755     return ovec;
2756 }
2757 
2758 ScmObj Scm_F64VectorCopy(ScmF64Vector *vec, int start, int end)
2759 {
2760     int size = SCM_F64VECTOR_SIZE(vec);
2761     SCM_CHECK_START_END(start, end, size);
2762     return Scm_MakeF64VectorFromArray(end-start,
2763                                      SCM_F64VECTOR_ELEMENTS(vec)+start);
2764 }
2765 
2766 ScmObj Scm_F64VectorCopyX(ScmF64Vector *dst,
2767                            int dstart,
2768                            ScmF64Vector *src,
2769                            int sstart,
2770                            int send)
2771 {
2772     int dlen = SCM_F64VECTOR_SIZE(dst);
2773     int slen = SCM_F64VECTOR_SIZE(src);
2774     int size;
2775     
2776     SCM_UVECTOR_CHECK_MUTABLE(dst);
2777     SCM_CHECK_START_END(sstart, send, slen);
2778 
2779     if (dstart < 0 || dstart >= dlen) return SCM_OBJ(dst);
2780     if (dlen - dstart > send - sstart)  size = send - sstart;
2781     else size = dlen - dstart;
2782 
2783     memcpy(SCM_F64VECTOR_ELEMENTS(dst) + dstart,
2784            SCM_F64VECTOR_ELEMENTS(src) + sstart,
2785            size * sizeof(double));
2786     return SCM_OBJ(dst);
2787 }
2788 
2789 static void s8vector_add(const char *name,
2790                                  ScmObj d, ScmObj s0, ScmObj s1, int clamp)
2791 {
2792     int i, size = SCM_S8VECTOR_SIZE(d), oor;
2793     long r, v0, v1;
2794     ScmObj rr, vv1;
2795 
2796     switch (arg2_check(name, s0, s1, TRUE)) {
2797     case ARGTYPE_UVECTOR:
2798         for (i=0; i<size; i++) {
2799             v0 = SCM_S8VECTOR_ELEMENTS(s0)[i];
2800             v1 = SCM_S8VECTOR_ELEMENTS(s1)[i];
2801             r = s8s8_add(v0, v1, clamp);
2802             SCM_S8VECTOR_ELEMENTS(d)[i] = (signed char)r;
2803         }
2804         break;
2805     case ARGTYPE_VECTOR:
2806         for (i=0; i<size; i++) {
2807             v0 = SCM_S8VECTOR_ELEMENTS(s0)[i];
2808             vv1 = SCM_VECTOR_ELEMENTS(s1)[i];
2809             v1 = s8num(vv1, &oor);
2810             if (!oor) {
2811                 r = s8g_add(v0, v1, clamp);
2812             } else {
2813                 rr = SCM_MAKE_INT(v0);
2814                 rr = Scm_Add2(rr, vv1);
2815                 r = s8unbox(rr, clamp);
2816             }
2817             SCM_S8VECTOR_ELEMENTS(d)[i] = (signed char)r;
2818         }
2819         break;
2820     case ARGTYPE_LIST:
2821         for (i=0; i<size; i++) {
2822             v0 = SCM_S8VECTOR_ELEMENTS(s0)[i];
2823             vv1 = SCM_CAR(s1); s1 = SCM_CDR(s1);
2824             v1 = s8num(vv1, &oor);
2825             if (!oor) {
2826                 r = s8g_add(v0, v1, clamp);
2827             } else {
2828                 rr = SCM_MAKE_INT(v0);
2829                 rr = Scm_Add2(rr, vv1);
2830                 r = s8unbox(rr, clamp);
2831             }
2832             SCM_S8VECTOR_ELEMENTS(d)[i] = (signed char)r;
2833         }
2834         break;
2835     case ARGTYPE_CONST:
2836         v1 = s8num(s1, &oor);
2837         for (i=0; i<size; i++) {
2838             v0 = SCM_S8VECTOR_ELEMENTS(s0)[i];
2839             if (!oor) {
2840                 r = s8g_add(v0, v1, clamp);
2841             } else {
2842                 rr = SCM_MAKE_INT(v0);
2843                 rr = Scm_Add2(rr, s1);
2844                 r = s8unbox(rr, clamp);
2845             }
2846             SCM_S8VECTOR_ELEMENTS(d)[i] = (signed char)r;
2847         }
2848     }
2849 }
2850 
2851 ScmObj Scm_S8VectorAdd(ScmS8Vector *s0, ScmObj s1, int clamp)
2852 {
2853     ScmObj d = Scm_MakeUVector(SCM_CLASS_S8VECTOR,
2854                                SCM_S8VECTOR_SIZE(s0),
2855                                NULL);
2856     s8vector_add("s8vector-add", d, SCM_OBJ(s0), s1, clamp);
2857     return d;
2858 }
2859 
2860 ScmObj Scm_S8VectorAddX(ScmS8Vector *s0, ScmObj s1, int clamp)
2861 {
2862     s8vector_add("s8vector-add!", SCM_OBJ(s0), SCM_OBJ(s0), s1, clamp);
2863     return SCM_OBJ(s0);
2864 }
2865 
2866 static void u8vector_add(const char *name,
2867                                  ScmObj d, ScmObj s0, ScmObj s1, int clamp)
2868 {
2869     int i, size = SCM_U8VECTOR_SIZE(d), oor;
2870     long r, v0, v1;
2871     ScmObj rr, vv1;
2872 
2873     switch (arg2_check(name, s0, s1, TRUE)) {
2874     case ARGTYPE_UVECTOR:
2875         for (i=0; i<size; i++) {
2876             v0 = SCM_U8VECTOR_ELEMENTS(s0)[i];
2877             v1 = SCM_U8VECTOR_ELEMENTS(s1)[i];
2878             r = u8u8_add(v0, v1, clamp);
2879             SCM_U8VECTOR_ELEMENTS(d)[i] = (unsigned char)r;
2880         }
2881         break;
2882     case ARGTYPE_VECTOR:
2883         for (i=0; i<size; i++) {
2884             v0 = SCM_U8VECTOR_ELEMENTS(s0)[i];
2885             vv1 = SCM_VECTOR_ELEMENTS(s1)[i];
2886             v1 = u8num(vv1, &oor);
2887             if (!oor) {
2888                 r = u8g_add(v0, v1, clamp);
2889             } else {
2890                 rr = SCM_MAKE_INT(v0);
2891                 rr = Scm_Add2(rr, vv1);
2892                 r = u8unbox(rr, clamp);
2893             }
2894             SCM_U8VECTOR_ELEMENTS(d)[i] = (unsigned char)r;
2895         }
2896         break;
2897     case ARGTYPE_LIST:
2898         for (i=0; i<size; i++) {
2899             v0 = SCM_U8VECTOR_ELEMENTS(s0)[i];
2900             vv1 = SCM_CAR(s1); s1 = SCM_CDR(s1);
2901             v1 = u8num(vv1, &oor);
2902             if (!oor) {
2903                 r = u8g_add(v0, v1, clamp);
2904             } else {
2905                 rr = SCM_MAKE_INT(v0);
2906                 rr = Scm_Add2(rr, vv1);
2907                 r = u8unbox(rr, clamp);
2908             }
2909             SCM_U8VECTOR_ELEMENTS(d)[i] = (unsigned char)r;
2910         }
2911         break;
2912     case ARGTYPE_CONST:
2913         v1 = u8num(s1, &oor);
2914         for (i=0; i<size; i++) {
2915             v0 = SCM_U8VECTOR_ELEMENTS(s0)[i];
2916             if (!oor) {
2917                 r = u8g_add(v0, v1, clamp);
2918             } else {
2919                 rr = SCM_MAKE_INT(v0);
2920                 rr = Scm_Add2(rr, s1);
2921                 r = u8unbox(rr, clamp);
2922             }
2923             SCM_U8VECTOR_ELEMENTS(d)[i] = (unsigned char)r;
2924         }
2925     }
2926 }
2927 
2928 ScmObj Scm_U8VectorAdd(ScmU8Vector *s0, ScmObj s1, int clamp)
2929 {
2930     ScmObj d = Scm_MakeUVector(SCM_CLASS_U8VECTOR,
2931                                SCM_U8VECTOR_SIZE(s0),
2932                                NULL);
2933     u8vector_add("u8vector-add", d, SCM_OBJ(s0), s1, clamp);
2934     return d;
2935 }
2936 
2937 ScmObj Scm_U8VectorAddX(ScmU8Vector *s0, ScmObj s1, int clamp)
2938 {
2939     u8vector_add("u8vector-add!", SCM_OBJ(s0), SCM_OBJ(s0), s1, clamp);
2940     return SCM_OBJ(s0);
2941 }
2942 
2943 static void s16vector_add(const char *name,
2944                                  ScmObj d, ScmObj s0, ScmObj s1, int clamp)
2945 {
2946     int i, size = SCM_S16VECTOR_SIZE(d), oor;
2947     long r, v0, v1;
2948     ScmObj rr, vv1;
2949 
2950     switch (arg2_check(name, s0, s1, TRUE)) {
2951     case ARGTYPE_UVECTOR:
2952         for (i=0; i<size; i++) {
2953             v0 = SCM_S16VECTOR_ELEMENTS(s0)[i];
2954             v1 = SCM_S16VECTOR_ELEMENTS(s1)[i];
2955             r = s16s16_add(v0, v1, clamp);
2956             SCM_S16VECTOR_ELEMENTS(d)[i] = (short)r;
2957         }
2958         break;
2959     case ARGTYPE_VECTOR:
2960         for (i=0; i<size; i++) {
2961             v0 = SCM_S16VECTOR_ELEMENTS(s0)[i];
2962             vv1 = SCM_VECTOR_ELEMENTS(s1)[i];
2963             v1 = s16num(vv1, &oor);
2964             if (!oor) {
2965                 r = s16g_add(v0, v1, clamp);
2966             } else {
2967                 rr = SCM_MAKE_INT(v0);
2968                 rr = Scm_Add2(rr, vv1);
2969                 r = s16unbox(rr, clamp);
2970             }
2971             SCM_S16VECTOR_ELEMENTS(d)[i] = (short)r;
2972         }
2973         break;
2974     case ARGTYPE_LIST:
2975         for (i=0; i<size; i++) {
2976             v0 = SCM_S16VECTOR_ELEMENTS(s0)[i];
2977             vv1 = SCM_CAR(s1); s1 = SCM_CDR(s1);
2978             v1 = s16num(vv1, &oor);
2979             if (!oor) {
2980                 r = s16g_add(v0, v1, clamp);
2981             } else {
2982                 rr = SCM_MAKE_INT(v0);
2983                 rr = Scm_Add2(rr, vv1);
2984                 r = s16unbox(rr, clamp);
2985             }
2986             SCM_S16VECTOR_ELEMENTS(d)[i] = (short)r;
2987         }
2988         break;
2989     case ARGTYPE_CONST:
2990         v1 = s16num(s1, &oor);
2991         for (i=0; i<size; i++) {
2992             v0 = SCM_S16VECTOR_ELEMENTS(s0)[i];
2993             if (!oor) {
2994                 r = s16g_add(v0, v1, clamp);
2995             } else {
2996                 rr = SCM_MAKE_INT(v0);
2997                 rr = Scm_Add2(rr, s1);
2998                 r = s16unbox(rr, clamp);
2999             }
3000             SCM_S16VECTOR_ELEMENTS(d)[i] = (short)r;
3001         }
3002     }
3003 }
3004 
3005 ScmObj Scm_S16VectorAdd(ScmS16Vector *s0, ScmObj s1, int clamp)
3006 {
3007     ScmObj d = Scm_MakeUVector(SCM_CLASS_S16VECTOR,
3008                                SCM_S16VECTOR_SIZE(s0),
3009                                NULL);
3010     s16vector_add("s16vector-add", d, SCM_OBJ(s0), s1, clamp);
3011     return d;
3012 }
3013 
3014 ScmObj Scm_S16VectorAddX(ScmS16Vector *s0, ScmObj s1, int clamp)
3015 {
3016     s16vector_add("s16vector-add!", SCM_OBJ(s0), SCM_OBJ(s0), s1, clamp);
3017     return SCM_OBJ(s0);
3018 }
3019 
3020 static void u16vector_add(const char *name,
3021                                  ScmObj d, ScmObj s0, ScmObj s1, int clamp)
3022 {
3023     int i, size = SCM_U16VECTOR_SIZE(d), oor;
3024     long r, v0, v1;
3025     ScmObj rr, vv1;
3026 
3027     switch (arg2_check(name, s0, s1, TRUE)) {
3028     case ARGTYPE_UVECTOR:
3029         for (i=0; i<size; i++) {
3030             v0 = SCM_U16VECTOR_ELEMENTS(s0)[i];
3031             v1 = SCM_U16VECTOR_ELEMENTS(s1)[i];
3032             r = u16u16_add(v0, v1, clamp);
3033             SCM_U16VECTOR_ELEMENTS(d)[i] = (unsigned short)r;
3034         }
3035         break;
3036     case ARGTYPE_VECTOR:
3037         for (i=0; i<size; i++) {
3038             v0 = SCM_U16VECTOR_ELEMENTS(s0)[i];
3039             vv1 = SCM_VECTOR_ELEMENTS(s1)[i];
3040             v1 = u16num(vv1, &oor);
3041             if (!oor) {
3042                 r = u16g_add(v0, v1, clamp);
3043             } else {
3044                 rr = SCM_MAKE_INT(v0);
3045                 rr = Scm_Add2(rr, vv1);
3046                 r = u16unbox(rr, clamp);
3047             }
3048             SCM_U16VECTOR_ELEMENTS(d)[i] = (unsigned short)r;
3049         }
3050         break;
3051     case ARGTYPE_LIST:
3052         for (i=0; i<size; i++) {
3053             v0 = SCM_U16VECTOR_ELEMENTS(s0)[i];
3054             vv1 = SCM_CAR(s1); s1 = SCM_CDR(s1);
3055             v1 = u16num(vv1, &oor);
3056             if (!oor) {
3057                 r = u16g_add(v0, v1, clamp);
3058             } else {
3059                 rr = SCM_MAKE_INT(v0);
3060                 rr = Scm_Add2(rr, vv1);
3061                 r = u16unbox(rr, clamp);
3062             }
3063             SCM_U16VECTOR_ELEMENTS(d)[i] = (unsigned short)r;
3064         }
3065         break;
3066     case ARGTYPE_CONST:
3067         v1 = u16num(s1, &oor);
3068         for (i=0; i<size; i++) {
3069             v0 = SCM_U16VECTOR_ELEMENTS(s0)[i];
3070             if (!oor) {
3071                 r = u16g_add(v0, v1, clamp);
3072             } else {
3073                 rr = SCM_MAKE_INT(v0);
3074                 rr = Scm_Add2(rr, s1);
3075                 r = u16unbox(rr, clamp);
3076             }
3077             SCM_U16VECTOR_ELEMENTS(d)[i] = (unsigned short)r;
3078         }
3079     }
3080 }
3081 
3082 ScmObj Scm_U16VectorAdd(ScmU16Vector *s0, ScmObj s1, int clamp)
3083 {
3084     ScmObj d = Scm_MakeUVector(SCM_CLASS_U16VECTOR,
3085                                SCM_U16VECTOR_SIZE(s0),
3086                                NULL);
3087     u16vector_add("u16vector-add", d, SCM_OBJ(s0), s1, clamp);
3088     return d;
3089 }
3090 
3091 ScmObj Scm_U16VectorAddX(ScmU16Vector *s0, ScmObj s1, int clamp)
3092 {
3093     u16vector_add("u16vector-add!", SCM_OBJ(s0), SCM_OBJ(s0), s1, clamp);
3094     return SCM_OBJ(s0);
3095 }
3096 
3097 static void s32vector_add(const char *name,
3098                                  ScmObj d, ScmObj s0, ScmObj s1, int clamp)
3099 {
3100     int i, size = SCM_S32VECTOR_SIZE(d), oor;
3101     long r, v0, v1;
3102     ScmObj rr, vv1;
3103 
3104     switch (arg2_check(name, s0, s1, TRUE)) {
3105     case ARGTYPE_UVECTOR:
3106         for (i=0; i<size; i++) {
3107             v0 = SCM_S32VECTOR_ELEMENTS(s0)[i];
3108             v1 = SCM_S32VECTOR_ELEMENTS(s1)[i];
3109             r = s32s32_add(v0, v1, clamp);
3110             SCM_S32VECTOR_ELEMENTS(d)[i] = (ScmInt32)r;
3111         }
3112         break;
3113     case ARGTYPE_VECTOR:
3114         for (i=0; i<size; i++) {
3115             v0 = SCM_S32VECTOR_ELEMENTS(s0)[i];
3116             vv1 = SCM_VECTOR_ELEMENTS(s1)[i];
3117             v1 = s32num(vv1, &oor);
3118             if (!oor) {
3119                 r = s32g_add(v0, v1, clamp);
3120             } else {
3121                 rr = Scm_MakeInteger(v0);
3122                 rr = Scm_Add2(rr, vv1);
3123                 r = Scm_GetInteger32Clamp(rr, clamp, NULL);
3124             }
3125             SCM_S32VECTOR_ELEMENTS(d)[i] = (ScmInt32)r;
3126         }
3127         break;
3128     case ARGTYPE_LIST:
3129         for (i=0; i<size; i++) {
3130             v0 = SCM_S32VECTOR_ELEMENTS(s0)[i];
3131             vv1 = SCM_CAR(s1); s1 = SCM_CDR(s1);
3132             v1 = s32num(vv1, &oor);
3133             if (!oor) {
3134                 r = s32g_add(v0, v1, clamp);
3135             } else {
3136                 rr = Scm_MakeInteger(v0);
3137                 rr = Scm_Add2(rr, vv1);
3138                 r = Scm_GetInteger32Clamp(rr, clamp, NULL);
3139             }
3140             SCM_S32VECTOR_ELEMENTS(d)[i] = (ScmInt32)r;
3141         }
3142         break;
3143     case ARGTYPE_CONST:
3144         v1 = s32num(s1, &oor);
3145         for (i=0; i<size; i++) {
3146             v0 = SCM_S32VECTOR_ELEMENTS(s0)[i];
3147             if (!oor) {
3148                 r = s32g_add(v0, v1, clamp);
3149             } else {
3150                 rr = Scm_MakeInteger(v0);
3151                 rr = Scm_Add2(rr, s1);
3152                 r = Scm_GetInteger32Clamp(rr, clamp, NULL);
3153             }
3154             SCM_S32VECTOR_ELEMENTS(d)[i] = (ScmInt32)r;
3155         }
3156     }
3157 }
3158 
3159 ScmObj Scm_S32VectorAdd(ScmS32Vector *s0, ScmObj s1, int clamp)
3160 {
3161     ScmObj d = Scm_MakeUVector(SCM_CLASS_S32VECTOR,
3162                                SCM_S32VECTOR_SIZE(s0),
3163                                NULL);
3164     s32vector_add("s32vector-add", d, SCM_OBJ(s0), s1, clamp);
3165     return d;
3166 }
3167 
3168 ScmObj Scm_S32VectorAddX(ScmS32Vector *s0, ScmObj s1, int clamp)
3169 {
3170     s32vector_add("s32vector-add!", SCM_OBJ(s0), SCM_OBJ(s0), s1, clamp);
3171     return SCM_OBJ(s0);
3172 }
3173 
3174 static void u32vector_add(const char *name,
3175                                  ScmObj d, ScmObj s0, ScmObj s1, int clamp)
3176 {
3177     int i, size = SCM_U32VECTOR_SIZE(d), oor;
3178     u_long r, v0, v1;
3179     ScmObj rr, vv1;
3180 
3181     switch (arg2_check(name, s0, s1, TRUE)) {
3182     case ARGTYPE_UVECTOR:
3183         for (i=0; i<size; i++) {
3184             v0 = SCM_U32VECTOR_ELEMENTS(s0)[i];
3185             v1 = SCM_U32VECTOR_ELEMENTS(s1)[i];
3186             r = u32u32_add(v0, v1, clamp);
3187             SCM_U32VECTOR_ELEMENTS(d)[i] = (ScmUInt32)r;
3188         }
3189         break;
3190     case ARGTYPE_VECTOR:
3191         for (i=0; i<size; i++) {
3192             v0 = SCM_U32VECTOR_ELEMENTS(s0)[i];
3193             vv1 = SCM_VECTOR_ELEMENTS(s1)[i];
3194             v1 = u32num(vv1, &oor);
3195             if (!oor) {
3196                 r = u32g_add(v0, v1, clamp);
3197             } else {
3198                 rr = Scm_MakeIntegerU(v0);
3199                 rr = Scm_Add2(rr, vv1);
3200                 r = Scm_GetIntegerU32Clamp(rr, clamp, NULL);
3201             }
3202             SCM_U32VECTOR_ELEMENTS(d)[i] = (ScmUInt32)r;
3203         }
3204         break;
3205     case ARGTYPE_LIST:
3206         for (i=0; i<size; i++) {
3207             v0 = SCM_U32VECTOR_ELEMENTS(s0)[i];
3208             vv1 = SCM_CAR(s1); s1 = SCM_CDR(s1);
3209             v1 = u32num(vv1, &oor);
3210             if (!oor) {
3211                 r = u32g_add(v0, v1, clamp);
3212             } else {
3213                 rr = Scm_MakeIntegerU(v0);
3214                 rr = Scm_Add2(rr, vv1);
3215                 r = Scm_GetIntegerU32Clamp(rr, clamp, NULL);
3216             }
3217             SCM_U32VECTOR_ELEMENTS(d)[i] = (ScmUInt32)r;
3218         }
3219         break;
3220     case ARGTYPE_CONST:
3221         v1 = u32num(s1, &oor);
3222         for (i=0; i<size; i++) {
3223             v0 = SCM_U32VECTOR_ELEMENTS(s0)[i];
3224             if (!oor) {
3225                 r = u32g_add(v0, v1, clamp);
3226             } else {
3227                 rr = Scm_MakeIntegerU(v0);
3228                 rr = Scm_Add2(rr, s1);
3229                 r = Scm_GetIntegerU32Clamp(rr, clamp, NULL);
3230             }
3231             SCM_U32VECTOR_ELEMENTS(d)[i] = (ScmUInt32)r;
3232         }
3233     }
3234 }
3235 
3236 ScmObj Scm_U32VectorAdd(ScmU32Vector *s0, ScmObj s1, int clamp)
3237 {
3238     ScmObj d = Scm_MakeUVector(SCM_CLASS_U32VECTOR,
3239                                SCM_U32VECTOR_SIZE(s0),
3240                                NULL);
3241     u32vector_add("u32vector-add", d, SCM_OBJ(s0), s1, clamp);
3242     return d;
3243 }
3244 
3245 ScmObj Scm_U32VectorAddX(ScmU32Vector *s0, ScmObj s1, int clamp)
3246 {
3247     u32vector_add("u32vector-add!", SCM_OBJ(s0), SCM_OBJ(s0), s1, clamp);
3248     return SCM_OBJ(s0);
3249 }
3250 
3251 static void s64vector_add(const char *name,
3252                                  ScmObj d, ScmObj s0, ScmObj s1, int clamp)
3253 {
3254     int i, size = SCM_S64VECTOR_SIZE(d), oor;
3255     ScmInt64 r, v0, v1;
3256     ScmObj rr, vv1;
3257 
3258     switch (arg2_check(name, s0, s1, TRUE)) {
3259     case ARGTYPE_UVECTOR:
3260         for (i=0; i<size; i++) {
3261             v0 = SCM_S64VECTOR_ELEMENTS(s0)[i];
3262             v1 = SCM_S64VECTOR_ELEMENTS(s1)[i];
3263             r = s64s64_add(v0, v1, clamp);
3264             SCM_S64VECTOR_ELEMENTS(d)[i] = (ScmInt64)r;
3265         }
3266         break;
3267     case ARGTYPE_VECTOR:
3268         for (i=0; i<size; i++) {
3269             v0 = SCM_S64VECTOR_ELEMENTS(s0)[i];
3270             vv1 = SCM_VECTOR_ELEMENTS(s1)[i];
3271             v1 = s64num(vv1, &oor);
3272             if (!oor) {
3273                 r = s64g_add(v0, v1, clamp);
3274             } else {
3275                 rr = Scm_MakeInteger64(v0);
3276                 rr = Scm_Add2(rr, vv1);
3277                 r = Scm_GetInteger64Clamp(rr, clamp, NULL);
3278             }
3279             SCM_S64VECTOR_ELEMENTS(d)[i] = (ScmInt64)r;
3280         }
3281         break;
3282     case ARGTYPE_LIST:
3283         for (i=0; i<size; i++) {
3284             v0 = SCM_S64VECTOR_ELEMENTS(s0)[i];
3285             vv1 = SCM_CAR(s1); s1 = SCM_CDR(s1);
3286             v1 = s64num(vv1, &oor);
3287             if (!oor) {
3288                 r = s64g_add(v0, v1, clamp);
3289             } else {
3290                 rr = Scm_MakeInteger64(v0);
3291                 rr = Scm_Add2(rr, vv1);
3292                 r = Scm_GetInteger64Clamp(rr, clamp, NULL);
3293             }
3294             SCM_S64VECTOR_ELEMENTS(d)[i] = (ScmInt64)r;
3295         }
3296         break;
3297     case ARGTYPE_CONST:
3298         v1 = s64num(s1, &oor);
3299         for (i=0; i<size; i++) {
3300             v0 = SCM_S64VECTOR_ELEMENTS(s0)[i];
3301             if (!oor) {
3302                 r = s64g_add(v0, v1, clamp);
3303             } else {
3304                 rr = Scm_MakeInteger64(v0);
3305                 rr = Scm_Add2(rr, s1);
3306                 r = Scm_GetInteger64Clamp(rr, clamp, NULL);
3307             }
3308             SCM_S64VECTOR_ELEMENTS(d)[i] = (ScmInt64)r;
3309         }
3310     }
3311 }
3312 
3313 ScmObj Scm_S64VectorAdd(ScmS64Vector *s0, ScmObj s1, int clamp)
3314 {
3315     ScmObj d = Scm_MakeUVector(SCM_CLASS_S64VECTOR,
3316                                SCM_S64VECTOR_SIZE(s0),
3317                                NULL);
3318     s64vector_add("s64vector-add", d, SCM_OBJ(s0), s1, clamp);
3319     return d;
3320 }
3321 
3322 ScmObj Scm_S64VectorAddX(ScmS64Vector *s0, ScmObj s1, int clamp)
3323 {
3324     s64vector_add("s64vector-add!", SCM_OBJ(s0), SCM_OBJ(s0), s1, clamp);
3325     return SCM_OBJ(s0);
3326 }
3327 
3328 static void u64vector_add(const char *name,
3329                                  ScmObj d, ScmObj s0, ScmObj s1, int clamp)
3330 {
3331     int i, size = SCM_U64VECTOR_SIZE(d), oor;
3332     ScmUInt64 r, v0, v1;
3333     ScmObj rr, vv1;
3334 
3335     switch (arg2_check(name, s0, s1, TRUE)) {
3336     case ARGTYPE_UVECTOR:
3337         for (i=0; i<size; i++) {
3338             v0 = SCM_U64VECTOR_ELEMENTS(s0)[i];
3339             v1 = SCM_U64VECTOR_ELEMENTS(s1)[i];
3340             r = u64u64_add(v0, v1, clamp);
3341             SCM_U64VECTOR_ELEMENTS(d)[i] = (ScmUInt64)r;
3342         }
3343         break;
3344     case ARGTYPE_VECTOR:
3345         for (i=0; i<size; i++) {
3346             v0 = SCM_U64VECTOR_ELEMENTS(s0)[i];
3347             vv1 = SCM_VECTOR_ELEMENTS(s1)[i];
3348             v1 = u64num(vv1, &oor);
3349             if (!oor) {
3350                 r = u64g_add(v0, v1, clamp);
3351             } else {
3352                 rr = Scm_MakeIntegerU64(v0);
3353                 rr = Scm_Add2(rr, vv1);
3354                 r = Scm_GetIntegerU64Clamp(rr, clamp, NULL);
3355             }
3356             SCM_U64VECTOR_ELEMENTS(d)[i] = (ScmUInt64)r;
3357         }
3358         break;
3359     case ARGTYPE_LIST:
3360         for (i=0; i<size; i++) {
3361             v0 = SCM_U64VECTOR_ELEMENTS(s0)[i];
3362             vv1 = SCM_CAR(s1); s1 = SCM_CDR(s1);
3363             v1 = u64num(vv1, &oor);
3364             if (!oor) {
3365                 r = u64g_add(v0, v1, clamp);
3366             } else {
3367                 rr = Scm_MakeIntegerU64(v0);
3368                 rr = Scm_Add2(rr, vv1);
3369                 r = Scm_GetIntegerU64Clamp(rr, clamp, NULL);
3370             }
3371             SCM_U64VECTOR_ELEMENTS(d)[i] = (ScmUInt64)r;
3372         }
3373         break;
3374     case ARGTYPE_CONST:
3375         v1 = u64num(s1, &oor);
3376         for (i=0; i<size; i++) {
3377             v0 = SCM_U64VECTOR_ELEMENTS(s0)[i];
3378             if (!oor) {
3379                 r = u64g_add(v0, v1, clamp);
3380             } else {
3381                 rr = Scm_MakeIntegerU64(v0);
3382                 rr = Scm_Add2(rr, s1);
3383                 r = Scm_GetIntegerU64Clamp(rr, clamp, NULL);
3384             }
3385             SCM_U64VECTOR_ELEMENTS(d)[i] = (ScmUInt64)r;
3386         }
3387     }
3388 }
3389 
3390 ScmObj Scm_U64VectorAdd(ScmU64Vector *s0, ScmObj s1, int clamp)
3391 {
3392     ScmObj d = Scm_MakeUVector(SCM_CLASS_U64VECTOR,
3393                                SCM_U64VECTOR_SIZE(s0),
3394                                NULL);
3395     u64vector_add("u64vector-add", d, SCM_OBJ(s0), s1, clamp);
3396     return d;
3397 }
3398 
3399 ScmObj Scm_U64VectorAddX(ScmU64Vector *s0, ScmObj s1, int clamp)
3400 {
3401     u64vector_add("u64vector-add!", SCM_OBJ(s0), SCM_OBJ(s0), s1, clamp);
3402     return SCM_OBJ(s0);
3403 }
3404 
3405 static void f32vector_add(const char *name,
3406                                  ScmObj d, ScmObj s0, ScmObj s1, int clamp)
3407 {
3408     int i, size = SCM_F32VECTOR_SIZE(d), oor;
3409     double r, v0, v1;
3410     ScmObj rr, vv1;
3411 
3412     switch (arg2_check(name, s0, s1, TRUE)) {
3413     case ARGTYPE_UVECTOR:
3414         for (i=0; i<size; i++) {
3415             v0 = SCM_F32VECTOR_ELEMENTS(s0)[i];
3416             v1 = SCM_F32VECTOR_ELEMENTS(s1)[i];
3417             r = f32f32_add(v0, v1, clamp);
3418             SCM_F32VECTOR_ELEMENTS(d)[i] = (float)r;
3419         }
3420         break;
3421     case ARGTYPE_VECTOR:
3422         for (i=0; i<size; i++) {
3423             v0 = SCM_F32VECTOR_ELEMENTS(s0)[i];
3424             vv1 = SCM_VECTOR_ELEMENTS(s1)[i];
3425             v1 = f32num(vv1, &oor);
3426             if (!oor) {
3427                 r = f32g_add(v0, v1, clamp);
3428             } else {
3429                 rr = Scm_MakeFlonum((double)v0);
3430                 rr = Scm_Add2(rr, vv1);
3431                 r = (float)Scm_GetDouble(rr);
3432             }
3433             SCM_F32VECTOR_ELEMENTS(d)[i] = (float)r;
3434         }
3435         break;
3436     case ARGTYPE_LIST:
3437         for (i=0; i<size; i++) {
3438             v0 = SCM_F32VECTOR_ELEMENTS(s0)[i];
3439             vv1 = SCM_CAR(s1); s1 = SCM_CDR(s1);
3440             v1 = f32num(vv1, &oor);
3441             if (!oor) {
3442                 r = f32g_add(v0, v1, clamp);
3443             } else {
3444                 rr = Scm_MakeFlonum((double)v0);
3445                 rr = Scm_Add2(rr, vv1);
3446                 r = (float)Scm_GetDouble(rr);
3447             }
3448             SCM_F32VECTOR_ELEMENTS(d)[i] = (float)r;
3449         }
3450         break;
3451     case ARGTYPE_CONST:
3452         v1 = f32num(s1, &oor);
3453         for (i=0; i<size; i++) {
3454             v0 = SCM_F32VECTOR_ELEMENTS(s0)[i];
3455             if (!oor) {
3456                 r = f32g_add(v0, v1, clamp);
3457             } else {
3458                 rr = Scm_MakeFlonum((double)v0);
3459                 rr = Scm_Add2(rr, s1);
3460                 r = (float)Scm_GetDouble(rr);
3461             }
3462             SCM_F32VECTOR_ELEMENTS(d)[i] = (float)r;
3463         }
3464     }
3465 }
3466 
3467 ScmObj Scm_F32VectorAdd(ScmF32Vector *s0, ScmObj s1, int clamp)
3468 {
3469     ScmObj d = Scm_MakeUVector(SCM_CLASS_F32VECTOR,
3470                                SCM_F32VECTOR_SIZE(s0),
3471                                NULL);
3472     f32vector_add("f32vector-add", d, SCM_OBJ(s0), s1, clamp);
3473     return d;
3474 }
3475 
3476 ScmObj Scm_F32VectorAddX(ScmF32Vector *s0, ScmObj s1, int clamp)
3477 {
3478     f32vector_add("f32vector-add!", SCM_OBJ(s0), SCM_OBJ(s0), s1, clamp);
3479     return SCM_OBJ(s0);
3480 }
3481 
3482 static void f64vector_add(const char *name,
3483                                  ScmObj d, ScmObj s0, ScmObj s1, int clamp)
3484 {
3485     int i, size = SCM_F64VECTOR_SIZE(d), oor;
3486     double r, v0, v1;
3487     ScmObj rr, vv1;
3488 
3489     switch (arg2_check(name, s0, s1, TRUE)) {
3490     case ARGTYPE_UVECTOR:
3491         for (i=0; i<size; i++) {
3492             v0 = SCM_F64VECTOR_ELEMENTS(s0)[i];
3493             v1 = SCM_F64VECTOR_ELEMENTS(s1)[i];
3494             r = f64f64_add(v0, v1, clamp);
3495             SCM_F64VECTOR_ELEMENTS(d)[i] = (double)r;
3496         }
3497         break;
3498     case ARGTYPE_VECTOR:
3499         for (i=0; i<size; i++) {
3500             v0 = SCM_F64VECTOR_ELEMENTS(s0)[i];
3501             vv1 = SCM_VECTOR_ELEMENTS(s1)[i];
3502             v1 = f64num(vv1, &oor);
3503             if (!oor) {
3504                 r = f64g_add(v0, v1, clamp);
3505             } else {
3506                 rr = Scm_MakeFlonum(v0);
3507                 rr = Scm_Add2(rr, vv1);
3508                 r = Scm_GetDouble(rr);
3509             }
3510             SCM_F64VECTOR_ELEMENTS(d)[i] = (double)r;
3511         }
3512         break;
3513     case ARGTYPE_LIST:
3514         for (i=0; i<size; i++) {
3515             v0 = SCM_F64VECTOR_ELEMENTS(s0)[i];
3516             vv1 = SCM_CAR(s1); s1 = SCM_CDR(s1);
3517             v1 = f64num(vv1, &oor);
3518             if (!oor) {
3519                 r = f64g_add(v0, v1, clamp);
3520             } else {
3521                 rr = Scm_MakeFlonum(v0);
3522                 rr = Scm_Add2(rr, vv1);
3523                 r = Scm_GetDouble(rr);
3524             }
3525             SCM_F64VECTOR_ELEMENTS(d)[i] = (double)r;
3526         }
3527         break;
3528     case ARGTYPE_CONST:
3529         v1 = f64num(s1, &oor);
3530         for (i=0; i<size; i++) {
3531             v0 = SCM_F64VECTOR_ELEMENTS(s0)[i];
3532             if (!oor) {
3533                 r = f64g_add(v0, v1, clamp);
3534             } else {
3535                 rr = Scm_MakeFlonum(v0);
3536                 rr = Scm_Add2(rr, s1);
3537                 r = Scm_GetDouble(rr);
3538             }
3539             SCM_F64VECTOR_ELEMENTS(d)[i] = (double)r;
3540         }
3541     }
3542 }
3543 
3544 ScmObj Scm_F64VectorAdd(ScmF64Vector *s0, ScmObj s1, int clamp)
3545 {
3546     ScmObj d = Scm_MakeUVector(SCM_CLASS_F64VECTOR,
3547                                SCM_F64VECTOR_SIZE(s0),
3548                                NULL);
3549     f64vector_add("f64vector-add", d, SCM_OBJ(s0), s1, clamp);
3550     return d;
3551 }
3552 
3553 ScmObj Scm_F64VectorAddX(ScmF64Vector *s0, ScmObj s1, int clamp)
3554 {
3555     f64vector_add("f64vector-add!", SCM_OBJ(s0), SCM_OBJ(s0), s1, clamp);
3556     return SCM_OBJ(s0);
3557 }
3558 
3559 static void s8vector_sub(const char *name,
3560                                  ScmObj d, ScmObj s0, ScmObj s1, int clamp)
3561 {
3562     int i, size = SCM_S8VECTOR_SIZE(d), oor;
3563     long r, v0, v1;
3564     ScmObj rr, vv1;
3565 
3566     switch (arg2_check(name, s0, s1, TRUE)) {
3567     case ARGTYPE_UVECTOR:
3568         for (i=0; i<size; i++) {
3569             v0 = SCM_S8VECTOR_ELEMENTS(s0)[i];
3570             v1 = SCM_S8VECTOR_ELEMENTS(s1)[i];
3571             r = s8s8_sub(v0, v1, clamp);
3572             SCM_S8VECTOR_ELEMENTS(d)[i] = (signed char)r;
3573         }
3574         break;
3575     case ARGTYPE_VECTOR:
3576         for (i=0; i<size; i++) {
3577             v0 = SCM_S8VECTOR_ELEMENTS(s0)[i];
3578             vv1 = SCM_VECTOR_ELEMENTS(s1)[i];
3579             v1 = s8num(vv1, &oor);
3580             if (!oor) {
3581                 r = s8g_sub(v0, v1, clamp);
3582             } else {
3583                 rr = SCM_MAKE_INT(v0);
3584                 rr = Scm_Subtract2(rr, vv1);
3585                 r = s8unbox(rr, clamp);
3586             }
3587             SCM_S8VECTOR_ELEMENTS(d)[i] = (signed char)r;
3588         }
3589         break;
3590     case ARGTYPE_LIST:
3591         for (i=0; i<size; i++) {
3592             v0 = SCM_S8VECTOR_ELEMENTS(s0)[i];
3593             vv1 = SCM_CAR(s1); s1 = SCM_CDR(s1);
3594             v1 = s8num(vv1, &oor);
3595             if (!oor) {
3596                 r = s8g_sub(v0, v1, clamp);
3597             } else {
3598                 rr = SCM_MAKE_INT(v0);
3599                 rr = Scm_Subtract2(rr, vv1);
3600                 r = s8unbox(rr, clamp);
3601             }
3602             SCM_S8VECTOR_ELEMENTS(d)[i] = (signed char)r;
3603         }
3604         break;
3605     case ARGTYPE_CONST:
3606         v1 = s8num(s1, &oor);
3607         for (i=0; i<size; i++) {
3608             v0 = SCM_S8VECTOR_ELEMENTS(s0)[i];
3609             if (!oor) {
3610                 r = s8g_sub(v0, v1, clamp);
3611             } else {
3612                 rr = SCM_MAKE_INT(v0);
3613                 rr = Scm_Subtract2(rr, s1);
3614                 r = s8unbox(rr, clamp);
3615             }
3616             SCM_S8VECTOR_ELEMENTS(d)[i] = (signed char)r;
3617         }
3618     }
3619 }
3620 
3621 ScmObj Scm_S8VectorSub(ScmS8Vector *s0, ScmObj s1, int clamp)
3622 {
3623     ScmObj d = Scm_MakeUVector(SCM_CLASS_S8VECTOR,
3624                                SCM_S8VECTOR_SIZE(s0),
3625                                NULL);
3626     s8vector_sub("s8vector-sub", d, SCM_OBJ(s0), s1, clamp);
3627     return d;
3628 }
3629 
3630 ScmObj Scm_S8VectorSubX(ScmS8Vector *s0, ScmObj s1, int clamp)
3631 {
3632     s8vector_sub("s8vector-sub!", SCM_OBJ(s0), SCM_OBJ(s0), s1, clamp);
3633     return SCM_OBJ(s0);
3634 }
3635 
3636 static void u8vector_sub(const char *name,
3637                                  ScmObj d, ScmObj s0, ScmObj s1, int clamp)
3638 {
3639     int i, size = SCM_U8VECTOR_SIZE(d), oor;
3640     long r, v0, v1;
3641     ScmObj rr, vv1;
3642 
3643     switch (arg2_check(name, s0, s1, TRUE)) {
3644     case ARGTYPE_UVECTOR:
3645         for (i=0; i<size; i++) {
3646             v0 = SCM_U8VECTOR_ELEMENTS(s0)[i];
3647             v1 = SCM_U8VECTOR_ELEMENTS(s1)[i];
3648             r = u8u8_sub(v0, v1, clamp);
3649             SCM_U8VECTOR_ELEMENTS(d)[i] = (unsigned char)r;
3650         }
3651         break;
3652     case ARGTYPE_VECTOR:
3653         for (i=0; i<size; i++) {
3654             v0 = SCM_U8VECTOR_ELEMENTS(s0)[i];
3655             vv1 = SCM_VECTOR_ELEMENTS(s1)[i];
3656             v1 = u8num(vv1, &oor);
3657             if (!oor) {
3658                 r = u8g_sub(v0, v1, clamp);
3659             } else {
3660                 rr = SCM_MAKE_INT(v0);
3661                 rr = Scm_Subtract2(rr, vv1);
3662                 r = u8unbox(rr, clamp);
3663             }
3664             SCM_U8VECTOR_ELEMENTS(d)[i] = (unsigned char)r;
3665         }
3666         break;
3667     case ARGTYPE_LIST:
3668         for (i=0; i<size; i++) {
3669             v0 = SCM_U8VECTOR_ELEMENTS(s0)[i];
3670             vv1 = SCM_CAR(s1); s1 = SCM_CDR(s1);
3671             v1 = u8num(vv1, &oor);
3672             if (!oor) {
3673                 r = u8g_sub(v0, v1, clamp);
3674             } else {
3675                 rr = SCM_MAKE_INT(v0);
3676                 rr = Scm_Subtract2(rr, vv1);
3677                 r = u8unbox(rr, clamp);
3678             }
3679             SCM_U8VECTOR_ELEMENTS(d)[i] = (unsigned char)r;
3680         }
3681         break;
3682     case ARGTYPE_CONST:
3683         v1 = u8num(s1, &oor);
3684         for (i=0; i<size; i++) {
3685             v0 = SCM_U8VECTOR_ELEMENTS(s0)[i];
3686             if (!oor) {
3687                 r = u8g_sub(v0, v1, clamp);
3688             } else {
3689                 rr = SCM_MAKE_INT(v0);
3690                 rr = Scm_Subtract2(rr, s1);
3691                 r = u8unbox(rr, clamp);
3692             }
3693             SCM_U8VECTOR_ELEMENTS(d)[i] = (unsigned char)r;
3694         }
3695     }
3696 }
3697 
3698 ScmObj Scm_U8VectorSub(ScmU8Vector *s0, ScmObj s1, int clamp)
3699 {
3700     ScmObj d = Scm_MakeUVector(SCM_CLASS_U8VECTOR,
3701                                SCM_U8VECTOR_SIZE(s0),
3702                                NULL);
3703     u8vector_sub("u8vector-sub", d, SCM_OBJ(s0), s1, clamp);
3704     return d;
3705 }
3706 
3707 ScmObj Scm_U8VectorSubX(ScmU8Vector *s0, ScmObj s1, int clamp)
3708 {
3709     u8vector_sub("u8vector-sub!", SCM_OBJ(s0), SCM_OBJ(s0), s1, clamp);
3710     return SCM_OBJ(s0);
3711 }
3712 
3713 static void s16vector_sub(const char *name,
3714                                  ScmObj d, ScmObj s0, ScmObj s1, int clamp)
3715 {
3716     int i, size = SCM_S16VECTOR_SIZE(d), oor;
3717     long r, v0, v1;
3718     ScmObj rr, vv1;
3719 
3720     switch (arg2_check(name, s0, s1, TRUE)) {
3721     case ARGTYPE_UVECTOR:
3722         for (i=0; i<size; i++) {
3723             v0 = SCM_S16VECTOR_ELEMENTS(s0)[i];
3724             v1 = SCM_S16VECTOR_ELEMENTS(s1)[i];
3725             r = s16s16_sub(v0, v1, clamp);
3726             SCM_S16VECTOR_ELEMENTS(d)[i] = (short)r;
3727         }
3728         break;
3729     case ARGTYPE_VECTOR:
3730         for (i=0; i<size; i++) {
3731             v0 = SCM_S16VECTOR_ELEMENTS(s0)[i];
3732             vv1 = SCM_VECTOR_ELEMENTS(s1)[i];
3733             v1 = s16num(vv1, &oor);
3734             if (!oor) {
3735                 r = s16g_sub(v0, v1, clamp);
3736             } else {
3737                 rr = SCM_MAKE_INT(v0);
3738                 rr = Scm_Subtract2(rr, vv1);
3739                 r = s16unbox(rr, clamp);
3740             }
3741             SCM_S16VECTOR_ELEMENTS(d)[i] = (short)r;
3742         }
3743         break;
3744     case ARGTYPE_LIST:
3745         for (i=0; i<size; i++) {
3746             v0 = SCM_S16VECTOR_ELEMENTS(s0)[i];
3747             vv1 = SCM_CAR(s1); s1 = SCM_CDR(s1);
3748             v1 = s16num(vv1, &oor);
3749             if (!oor) {
3750                 r = s16g_sub(v0, v1, clamp);
3751             } else {
3752                 rr = SCM_MAKE_INT(v0);
3753                 rr = Scm_Subtract2(rr, vv1);
3754                 r = s16unbox(rr, clamp);
3755             }
3756             SCM_S16VECTOR_ELEMENTS(d)[i] = (short)r;
3757         }
3758         break;
3759     case ARGTYPE_CONST:
3760         v1 = s16num(s1, &oor);
3761         for (i=0; i<size; i++) {
3762             v0 = SCM_S16VECTOR_ELEMENTS(s0)[i];
3763             if (!oor) {
3764                 r = s16g_sub(v0, v1, clamp);
3765             } else {
3766                 rr = SCM_MAKE_INT(v0);
3767                 rr = Scm_Subtract2(rr, s1);
3768                 r = s16unbox(rr, clamp);
3769             }
3770             SCM_S16VECTOR_ELEMENTS(d)[i] = (short)r;
3771         }
3772     }
3773 }
3774 
3775 ScmObj Scm_S16VectorSub(ScmS16Vector *s0, ScmObj s1, int clamp)
3776 {
3777     ScmObj d = Scm_MakeUVector(SCM_CLASS_S16VECTOR,
3778                                SCM_S16VECTOR_SIZE(s0),
3779                                NULL);
3780     s16vector_sub("s16vector-sub", d, SCM_OBJ(s0), s1, clamp);
3781     return d;
3782 }
3783 
3784 ScmObj Scm_S16VectorSubX(ScmS16Vector *s0, ScmObj s1, int clamp)
3785 {
3786     s16vector_sub("s16vector-sub!", SCM_OBJ(s0), SCM_OBJ(s0), s1, clamp);
3787     return SCM_OBJ(s0);
3788 }
3789 
3790 static void u16vector_sub(const char *name,
3791                                  ScmObj d, ScmObj s0, ScmObj s1, int clamp)
3792 {
3793     int i, size = SCM_U16VECTOR_SIZE(d), oor;
3794     long r, v0, v1;
3795     ScmObj rr, vv1;
3796 
3797     switch (arg2_check(name, s0, s1, TRUE)) {
3798     case ARGTYPE_UVECTOR:
3799         for (i=0; i<size; i++) {
3800             v0 = SCM_U16VECTOR_ELEMENTS(s0)[i];
3801             v1 = SCM_U16VECTOR_ELEMENTS(s1)[i];
3802             r = u16u16_sub(v0, v1, clamp);
3803             SCM_U16VECTOR_ELEMENTS(d)[i] = (unsigned short)r;
3804         }
3805         break;
3806     case ARGTYPE_VECTOR:
3807         for (i=0; i<size; i++) {
3808             v0 = SCM_U16VECTOR_ELEMENTS(s0)[i];
3809             vv1 = SCM_VECTOR_ELEMENTS(s1)[i];
3810             v1 = u16num(vv1, &oor);
3811             if (!oor) {
3812                 r = u16g_sub(v0, v1, clamp);
3813             } else {
3814                 rr = SCM_MAKE_INT(v0);
3815                 rr = Scm_Subtract2(rr, vv1);
3816                 r = u16unbox(rr, clamp);
3817             }
3818             SCM_U16VECTOR_ELEMENTS(d)[i] = (unsigned short)r;
3819         }
3820         break;
3821     case ARGTYPE_LIST:
3822         for (i=0; i<size; i++) {
3823             v0 = SCM_U16VECTOR_ELEMENTS(s0)[i];
3824             vv1 = SCM_CAR(s1); s1 = SCM_CDR(s1);
3825             v1 = u16num(vv1, &oor);
3826             if (!oor) {
3827                 r = u16g_sub(v0, v1, clamp);
3828             } else {
3829                 rr = SCM_MAKE_INT(v0);
3830                 rr = Scm_Subtract2(rr, vv1);
3831                 r = u16unbox(rr, clamp);
3832             }
3833             SCM_U16VECTOR_ELEMENTS(d)[i] = (unsigned short)r;
3834         }
3835         break;
3836     case ARGTYPE_CONST:
3837         v1 = u16num(s1, &oor);
3838         for (i=0; i<size; i++) {
3839             v0 = SCM_U16VECTOR_ELEMENTS(s0)[i];
3840             if (!oor) {
3841                 r = u16g_sub(v0, v1, clamp);
3842             } else {
3843                 rr = SCM_MAKE_INT(v0);
3844                 rr = Scm_Subtract2(rr, s1);
3845                 r = u16unbox(rr, clamp);
3846             }
3847             SCM_U16VECTOR_ELEMENTS(d)[i] = (unsigned short)r;
3848         }
3849     }
3850 }
3851 
3852 ScmObj Scm_U16VectorSub(ScmU16Vector *s0, ScmObj s1, int clamp)
3853 {
3854     ScmObj d = Scm_MakeUVector(SCM_CLASS_U16VECTOR,
3855                                SCM_U16VECTOR_SIZE(s0),
3856                                NULL);
3857     u16vector_sub("u16vector-sub", d, SCM_OBJ(s0), s1, clamp);
3858     return d;
3859 }
3860 
3861 ScmObj Scm_U16VectorSubX(ScmU16Vector *s0, ScmObj s1, int clamp)
3862 {
3863     u16vector_sub("u16vector-sub!", SCM_OBJ(s0), SCM_OBJ(s0), s1, clamp);
3864     return SCM_OBJ(s0);
3865 }
3866 
3867 static void s32vector_sub(const char *name,
3868                                  ScmObj d, ScmObj s0, ScmObj s1, int clamp)
3869 {
3870     int i, size = SCM_S32VECTOR_SIZE(d), oor;
3871     long r, v0, v1;
3872     ScmObj rr, vv1;
3873 
3874     switch (arg2_check(name, s0, s1, TRUE)) {
3875     case ARGTYPE_UVECTOR:
3876         for (i=0; i<size; i++) {
3877             v0 = SCM_S32VECTOR_ELEMENTS(s0)[i];
3878             v1 = SCM_S32VECTOR_ELEMENTS(s1)[i];
3879             r = s32s32_sub(v0, v1, clamp);
3880             SCM_S32VECTOR_ELEMENTS(d)[i] = (ScmInt32)r;
3881         }
3882         break;
3883     case ARGTYPE_VECTOR:
3884         for (i=0; i<size; i++) {
3885             v0 = SCM_S32VECTOR_ELEMENTS(s0)[i];
3886             vv1 = SCM_VECTOR_ELEMENTS(s1)[i];
3887             v1 = s32num(vv1, &oor);
3888             if (!oor) {
3889                 r = s32g_sub(v0, v1, clamp);
3890             } else {
3891                 rr = Scm_MakeInteger(v0);
3892                 rr = Scm_Subtract2(rr, vv1);
3893                 r = Scm_GetInteger32Clamp(rr, clamp, NULL);
3894             }
3895             SCM_S32VECTOR_ELEMENTS(d)[i] = (ScmInt32)r;
3896         }
3897         break;
3898     case ARGTYPE_LIST:
3899         for (i=0; i<size; i++) {
3900             v0 = SCM_S32VECTOR_ELEMENTS(s0)[i];
3901             vv1 = SCM_CAR(s1); s1 = SCM_CDR(s1);
3902             v1 = s32num(vv1, &oor);
3903             if (!oor) {
3904                 r = s32g_sub(v0, v1, clamp);
3905             } else {
3906                 rr = Scm_MakeInteger(v0);
3907                 rr = Scm_Subtract2(rr, vv1);
3908                 r = Scm_GetInteger32Clamp(rr, clamp, NULL);
3909             }
3910             SCM_S32VECTOR_ELEMENTS(d)[i] = (ScmInt32)r;
3911         }
3912         break;
3913     case ARGTYPE_CONST:
3914         v1 = s32num(s1, &oor);
3915         for (i=0; i<size; i++) {
3916             v0 = SCM_S32VECTOR_ELEMENTS(s0)[i];
3917             if (!oor) {
3918                 r = s32g_sub(v0, v1, clamp);
3919             } else {
3920                 rr = Scm_MakeInteger(v0);
3921                 rr = Scm_Subtract2(rr, s1);
3922                 r = Scm_GetInteger32Clamp(rr, clamp, NULL);
3923             }
3924             SCM_S32VECTOR_ELEMENTS(d)[i] = (ScmInt32)r;
3925         }
3926     }
3927 }
3928 
3929 ScmObj Scm_S32VectorSub(ScmS32Vector *s0, ScmObj s1, int clamp)
3930 {
3931     ScmObj d = Scm_MakeUVector(SCM_CLASS_S32VECTOR,
3932                                SCM_S32VECTOR_SIZE(s0),
3933                                NULL);
3934     s32vector_sub("s32vector-sub", d, SCM_OBJ(s0), s1, clamp);
3935     return d;
3936 }
3937 
3938 ScmObj Scm_S32VectorSubX(ScmS32Vector *s0, ScmObj s1, int clamp)
3939 {
3940     s32vector_sub("s32vector-sub!", SCM_OBJ(s0), SCM_OBJ(s0), s1, clamp);
3941     return SCM_OBJ(s0);
3942 }
3943 
3944 static void u32vector_sub(const char *name,
3945                                  ScmObj d, ScmObj s0, ScmObj s1, int clamp)
3946 {
3947     int i, size = SCM_U32VECTOR_SIZE(d), oor;
3948     u_long r, v0, v1;
3949     ScmObj rr, vv1;
3950 
3951     switch (arg2_check(name, s0, s1, TRUE)) {
3952     case ARGTYPE_UVECTOR:
3953         for (i=0; i<size; i++) {
3954             v0 = SCM_U32VECTOR_ELEMENTS(s0)[i];
3955             v1 = SCM_U32VECTOR_ELEMENTS(s1)[i];
3956             r = u32u32_sub(v0, v1, clamp);
3957             SCM_U32VECTOR_ELEMENTS(d)[i] = (ScmUInt32)r;
3958         }
3959         break;
3960     case ARGTYPE_VECTOR:
3961         for (i=0; i<size; i++) {
3962             v0 = SCM_U32VECTOR_ELEMENTS(s0)[i];
3963             vv1 = SCM_VECTOR_ELEMENTS(s1)[i];
3964             v1 = u32num(vv1, &oor);
3965             if (!oor) {
3966                 r = u32g_sub(v0, v1, clamp);
3967             } else {
3968                 rr = Scm_MakeIntegerU(v0);
3969                 rr = Scm_Subtract2(rr, vv1);
3970                 r = Scm_GetIntegerU32Clamp(rr, clamp, NULL);
3971             }
3972             SCM_U32VECTOR_ELEMENTS(d)[i] = (ScmUInt32)r;
3973         }
3974         break;
3975     case ARGTYPE_LIST:
3976         for (i=0; i<size; i++) {
3977             v0 = SCM_U32VECTOR_ELEMENTS(s0)[i];
3978             vv1 = SCM_CAR(s1); s1 = SCM_CDR(s1);
3979             v1 = u32num(vv1, &oor);
3980             if (!oor) {
3981                 r = u32g_sub(v0, v1, clamp);
3982             } else {
3983                 rr = Scm_MakeIntegerU(v0);
3984                 rr = Scm_Subtract2(rr, vv1);
3985                 r = Scm_GetIntegerU32Clamp(rr, clamp, NULL);
3986             }
3987             SCM_U32VECTOR_ELEMENTS(d)[i] = (ScmUInt32)r;
3988         }
3989         break;
3990     case ARGTYPE_CONST:
3991         v1 = u32num(s1, &oor);
3992         for (i=0; i<size; i++) {
3993             v0 = SCM_U32VECTOR_ELEMENTS(s0)[i];
3994             if (!oor) {
3995                 r = u32g_sub(v0, v1, clamp);
3996             } else {
3997                 rr = Scm_MakeIntegerU(v0);
3998                 rr = Scm_Subtract2(rr, s1);
3999                 r = Scm_GetIntegerU32Clamp(rr, clamp, NULL);
4000             }
4001             SCM_U32VECTOR_ELEMENTS(d)[i] = (ScmUInt32)r;
4002         }
4003     }
4004 }
4005 
4006 ScmObj Scm_U32VectorSub(ScmU32Vector *s0, ScmObj s1, int clamp)
4007 {
4008     ScmObj d = Scm_MakeUVector(SCM_CLASS_U32VECTOR,
4009                                SCM_U32VECTOR_SIZE(s0),
4010                                NULL);
4011     u32vector_sub("u32vector-sub", d, SCM_OBJ(s0), s1, clamp);
4012     return d;
4013 }
4014 
4015 ScmObj Scm_U32VectorSubX(ScmU32Vector *s0, ScmObj s1, int clamp)
4016 {
4017     u32vector_sub("u32vector-sub!", SCM_OBJ(s0), SCM_OBJ(s0), s1, clamp);
4018     return SCM_OBJ(s0);
4019 }
4020 
4021 static void s64vector_sub(const char *name,
4022                                  ScmObj d, ScmObj s0, ScmObj s1, int clamp)
4023 {
4024     int i, size = SCM_S64VECTOR_SIZE(d), oor;
4025     ScmInt64 r, v0, v1;
4026     ScmObj rr, vv1;
4027 
4028     switch (arg2_check(name, s0, s1, TRUE)) {
4029     case ARGTYPE_UVECTOR:
4030         for (i=0; i<size; i++) {
4031             v0 = SCM_S64VECTOR_ELEMENTS(s0)[i];
4032             v1 = SCM_S64VECTOR_ELEMENTS(s1)[i];
4033             r = s64s64_sub(v0, v1, clamp);
4034             SCM_S64VECTOR_ELEMENTS(d)[i] = (ScmInt64)r;
4035         }
4036         break;
4037     case ARGTYPE_VECTOR:
4038         for (i=0; i<size; i++) {
4039             v0 = SCM_S64VECTOR_ELEMENTS(s0)[i];
4040             vv1 = SCM_VECTOR_ELEMENTS(s1)[i];
4041             v1 = s64num(vv1, &oor);
4042             if (!oor) {
4043                 r = s64g_sub(v0, v1, clamp);
4044             } else {
4045                 rr = Scm_MakeInteger64(v0);
4046                 rr = Scm_Subtract2(rr, vv1);
4047                 r = Scm_GetInteger64Clamp(rr, clamp, NULL);
4048             }
4049             SCM_S64VECTOR_ELEMENTS(d)[i] = (ScmInt64)r;
4050         }
4051         break;
4052     case ARGTYPE_LIST:
4053         for (i=0; i<size; i++) {
4054             v0 = SCM_S64VECTOR_ELEMENTS(s0)[i];
4055             vv1 = SCM_CAR(s1); s1 = SCM_CDR(s1);
4056             v1 = s64num(vv1, &oor);
4057             if (!oor) {
4058                 r = s64g_sub(v0, v1, clamp);
4059             } else {
4060                 rr = Scm_MakeInteger64(v0);
4061                 rr = Scm_Subtract2(rr, vv1);
4062                 r = Scm_GetInteger64Clamp(rr, clamp, NULL);
4063             }
4064             SCM_S64VECTOR_ELEMENTS(d)[i] = (ScmInt64)r;
4065         }
4066         break;
4067     case ARGTYPE_CONST:
4068         v1 = s64num(s1, &oor);
4069         for (i=0; i<size; i++) {
4070             v0 = SCM_S64VECTOR_ELEMENTS(s0)[i];
4071             if (!oor) {
4072                 r = s64g_sub(v0, v1, clamp);
4073             } else {
4074                 rr = Scm_MakeInteger64(v0);
4075                 rr = Scm_Subtract2(rr, s1);
4076                 r = Scm_GetInteger64Clamp(rr, clamp, NULL);
4077             }
4078             SCM_S64VECTOR_ELEMENTS(d)[i] = (ScmInt64)r;
4079         }
4080     }
4081 }
4082 
4083 ScmObj Scm_S64VectorSub(ScmS64Vector *s0, ScmObj s1, int clamp)
4084 {
4085     ScmObj d = Scm_MakeUVector(SCM_CLASS_S64VECTOR,
4086                                SCM_S64VECTOR_SIZE(s0),
4087                                NULL);
4088     s64vector_sub("s64vector-sub", d, SCM_OBJ(s0), s1, clamp);
4089     return d;
4090 }
4091 
4092 ScmObj Scm_S64VectorSubX(ScmS64Vector *s0, ScmObj s1, int clamp)
4093 {
4094     s64vector_sub("s64vector-sub!", SCM_OBJ(s0), SCM_OBJ(s0), s1, clamp);
4095     return SCM_OBJ(s0);
4096 }
4097 
4098 static void u64vector_sub(const char *name,
4099                                  ScmObj d, ScmObj s0, ScmObj s1, int clamp)
4100 {
4101     int i, size = SCM_U64VECTOR_SIZE(d), oor;
4102     ScmUInt64 r, v0, v1;
4103     ScmObj rr, vv1;
4104 
4105     switch (arg2_check(name, s0, s1, TRUE)) {
4106     case ARGTYPE_UVECTOR:
4107         for (i=0; i<size; i++) {
4108             v0 = SCM_U64VECTOR_ELEMENTS(s0)[i];
4109             v1 = SCM_U64VECTOR_ELEMENTS(s1)[i];
4110             r = u64u64_sub(v0, v1, clamp);
4111             SCM_U64VECTOR_ELEMENTS(d)[i] = (ScmUInt64)r;
4112         }
4113         break;
4114     case ARGTYPE_VECTOR:
4115         for (i=0; i<size; i++) {
4116             v0 = SCM_U64VECTOR_ELEMENTS(s0)[i];
4117             vv1 = SCM_VECTOR_ELEMENTS(s1)[i];
4118             v1 = u64num(vv1, &oor);
4119             if (!oor) {
4120                 r = u64g_sub(v0, v1, clamp);
4121             } else {
4122                 rr = Scm_MakeIntegerU64(v0);
4123                 rr = Scm_Subtract2(rr, vv1);
4124                 r = Scm_GetIntegerU64Clamp(rr, clamp, NULL);
4125             }
4126             SCM_U64VECTOR_ELEMENTS(d)[i] = (ScmUInt64)r;
4127         }
4128         break;
4129     case ARGTYPE_LIST:
4130         for (i=0; i<size; i++) {
4131             v0 = SCM_U64VECTOR_ELEMENTS(s0)[i];
4132             vv1 = SCM_CAR(s1); s1 = SCM_CDR(s1);
4133             v1 = u64num(vv1, &oor);
4134             if (!oor) {
4135                 r = u64g_sub(v0, v1, clamp);
4136             } else {
4137                 rr = Scm_MakeIntegerU64(v0);
4138                 rr = Scm_Subtract2(rr, vv1);
4139                 r = Scm_GetIntegerU64Clamp(rr, clamp, NULL);
4140             }
4141             SCM_U64VECTOR_ELEMENTS(d)[i] = (ScmUInt64)r;
4142         }
4143         break;
4144     case ARGTYPE_CONST:
4145         v1 = u64num(s1, &oor);
4146         for (i=0; i<size; i++) {
4147             v0 = SCM_U64VECTOR_ELEMENTS(s0)[i];
4148             if (!oor) {
4149                 r = u64g_sub(v0, v1, clamp);
4150             } else {
4151                 rr = Scm_MakeIntegerU64(v0);
4152                 rr = Scm_Subtract2(rr, s1);
4153                 r = Scm_GetIntegerU64Clamp(rr, clamp, NULL);
4154             }
4155             SCM_U64VECTOR_ELEMENTS(d)[i] = (ScmUInt64)r;
4156         }
4157     }
4158 }
4159 
4160 ScmObj Scm_U64VectorSub(ScmU64Vector *s0, ScmObj s1, int clamp)
4161 {
4162     ScmObj d = Scm_MakeUVector(SCM_CLASS_U64VECTOR,
4163                                SCM_U64VECTOR_SIZE(s0),
4164                                NULL);
4165     u64vector_sub("u64vector-sub", d, SCM_OBJ(s0), s1, clamp);
4166     return d;
4167 }
4168 
4169 ScmObj Scm_U64VectorSubX(ScmU64Vector *s0, ScmObj s1, int clamp)
4170 {
4171     u64vector_sub("u64vector-sub!", SCM_OBJ(s0), SCM_OBJ(s0), s1, clamp);
4172     return SCM_OBJ(s0);
4173 }
4174 
4175 static void f32vector_sub(const char *name,
4176                                  ScmObj d, ScmObj s0, ScmObj s1, int clamp)
4177 {
4178     int i, size = SCM_F32VECTOR_SIZE(d), oor;
4179     double r, v0, v1;
4180     ScmObj rr, vv1;
4181 
4182     switch (arg2_check(name, s0, s1, TRUE)) {
4183     case ARGTYPE_UVECTOR:
4184         for (i=0; i<size; i++) {
4185             v0 = SCM_F32VECTOR_ELEMENTS(s0)[i];
4186             v1 = SCM_F32VECTOR_ELEMENTS(s1)[i];
4187             r = f32f32_sub(v0, v1, clamp);
4188             SCM_F32VECTOR_ELEMENTS(d)[i] = (float)r;
4189         }
4190         break;
4191     case ARGTYPE_VECTOR:
4192         for (i=0; i<size; i++) {
4193             v0 = SCM_F32VECTOR_ELEMENTS(s0)[i];
4194             vv1 = SCM_VECTOR_ELEMENTS(s1)[i];
4195             v1 = f32num(vv1, &oor);
4196             if (!oor) {
4197                 r = f32g_sub(v0, v1, clamp);
4198             } else {
4199                 rr = Scm_MakeFlonum((double)v0);
4200                 rr = Scm_Subtract2(rr, vv1);
4201                 r = (float)Scm_GetDouble(rr);
4202             }
4203             SCM_F32VECTOR_ELEMENTS(d)[i] = (float)r;
4204         }
4205         break;
4206     case ARGTYPE_LIST:
4207         for (i=0; i<size; i++) {
4208             v0 = SCM_F32VECTOR_ELEMENTS(s0)[i];
4209             vv1 = SCM_CAR(s1); s1 = SCM_CDR(s1);
4210             v1 = f32num(vv1, &oor);
4211             if (!oor) {
4212                 r = f32g_sub(v0, v1, clamp);
4213             } else {
4214                 rr = Scm_MakeFlonum((double)v0);
4215                 rr = Scm_Subtract2(rr, vv1);
4216                 r = (float)Scm_GetDouble(rr);
4217             }
4218             SCM_F32VECTOR_ELEMENTS(d)[i] = (float)r;
4219         }
4220         break;
4221     case ARGTYPE_CONST:
4222         v1 = f32num(s1, &oor);
4223         for (i=0; i<size; i++) {
4224             v0 = SCM_F32VECTOR_ELEMENTS(s0)[i];
4225             if (!oor) {
4226                 r = f32g_sub(v0, v1, clamp);
4227             } else {
4228                 rr = Scm_MakeFlonum((double)v0);
4229                 rr = Scm_Subtract2(rr, s1);
4230                 r = (float)Scm_GetDouble(rr);
4231             }
4232             SCM_F32VECTOR_ELEMENTS(d)[i] = (float)r;
4233         }
4234     }
4235 }
4236 
4237 ScmObj Scm_F32VectorSub(ScmF32Vector *s0, ScmObj s1, int clamp)
4238 {
4239     ScmObj d = Scm_MakeUVector(SCM_CLASS_F32VECTOR,
4240                                SCM_F32VECTOR_SIZE(s0),
4241                                NULL);
4242     f32vector_sub("f32vector-sub", d, SCM_OBJ(s0), s1, clamp);
4243     return d;
4244 }
4245 
4246 ScmObj Scm_F32VectorSubX(ScmF32Vector *s0, ScmObj s1, int clamp)
4247 {
4248     f32vector_sub("f32vector-sub!", SCM_OBJ(s0), SCM_OBJ(s0), s1, clamp);
4249     return SCM_OBJ(s0);
4250 }
4251 
4252 static void f64vector_sub(const char *name,
4253                                  ScmObj d, ScmObj s0, ScmObj s1, int clamp)
4254 {
4255     int i, size = SCM_F64VECTOR_SIZE(d), oor;
4256     double r, v0, v1;
4257     ScmObj rr, vv1;
4258 
4259     switch (arg2_check(name, s0, s1, TRUE)) {
4260     case ARGTYPE_UVECTOR:
4261         for (i=0; i<size; i++) {
4262             v0 = SCM_F64VECTOR_ELEMENTS(s0)[i];
4263             v1 = SCM_F64VECTOR_ELEMENTS(s1)[i];
4264             r = f64f64_sub(v0, v1, clamp);
4265             SCM_F64VECTOR_ELEMENTS(d)[i] = (double)r;
4266         }
4267         break;
4268     case ARGTYPE_VECTOR:
4269         for (i=0; i<size; i++) {
4270             v0 = SCM_F64VECTOR_ELEMENTS(s0)[i];
4271             vv1 = SCM_VECTOR_ELEMENTS(s1)[i];
4272             v1 = f64num(vv1, &oor);
4273             if (!oor) {
4274                 r = f64g_sub(v0, v1, clamp);
4275             } else {
4276                 rr = Scm_MakeFlonum(v0);
4277                 rr = Scm_Subtract2(rr, vv1);
4278                 r = Scm_GetDouble(rr);
4279             }
4280             SCM_F64VECTOR_ELEMENTS(d)[i] = (double)r;
4281         }
4282         break;
4283     case ARGTYPE_LIST:
4284         for (i=0; i<size; i++) {
4285             v0 = SCM_F64VECTOR_ELEMENTS(s0)[i];
4286             vv1 = SCM_CAR(s1); s1 = SCM_CDR(s1);
4287             v1 = f64num(vv1, &oor);
4288             if (!oor) {
4289                 r = f64g_sub(v0, v1, clamp);
4290             } else {
4291                 rr = Scm_MakeFlonum(v0);
4292                 rr = Scm_Subtract2(rr, vv1);
4293                 r = Scm_GetDouble(rr);
4294             }
4295             SCM_F64VECTOR_ELEMENTS(d)[i] = (double)r;
4296         }
4297         break;
4298     case ARGTYPE_CONST:
4299         v1 = f64num(s1, &oor);
4300         for (i=0; i<size; i++) {
4301             v0 = SCM_F64VECTOR_ELEMENTS(s0)[i];
4302             if (!oor) {
4303                 r = f64g_sub(v0, v1, clamp);
4304             } else {
4305                 rr = Scm_MakeFlonum(v0);
4306                 rr = Scm_Subtract2(rr, s1);
4307                 r = Scm_GetDouble(rr);
4308             }
4309             SCM_F64VECTOR_ELEMENTS(d)[i] = (double)r;
4310         }
4311     }
4312 }
4313 
4314 ScmObj Scm_F64VectorSub(ScmF64Vector *s0, ScmObj s1, int clamp)
4315 {
4316     ScmObj d = Scm_MakeUVector(SCM_CLASS_F64VECTOR,
4317                                SCM_F64VECTOR_SIZE(s0),
4318                                NULL);
4319     f64vector_sub("f64vector-sub", d, SCM_OBJ(s0), s1, clamp);
4320     return d;
4321 }
4322 
4323 ScmObj Scm_F64VectorSubX(ScmF64Vector *s0, ScmObj s1, int clamp)
4324 {
4325     f64vector_sub("f64vector-sub!", SCM_OBJ(s0), SCM_OBJ(s0), s1, clamp);
4326     return SCM_OBJ(s0);
4327 }
4328 
4329 static void s8vector_mul(const char *name,
4330                                  ScmObj d, ScmObj s0, ScmObj s1, int clamp)
4331 {
4332     int i, size = SCM_S8VECTOR_SIZE(d), oor;
4333     long r, v0, v1;
4334     ScmObj rr, vv1;
4335 
4336     switch (arg2_check(name, s0, s1, TRUE)) {
4337     case ARGTYPE_UVECTOR:
4338         for (i=0; i<size; i++) {
4339             v0 = SCM_S8VECTOR_ELEMENTS(s0)[i];
4340             v1 = SCM_S8VECTOR_ELEMENTS(s1)[i];
4341             r = s8s8_mul(v0, v1, clamp);
4342             SCM_S8VECTOR_ELEMENTS(d)[i] = (signed char)r;
4343         }
4344         break;
4345     case ARGTYPE_VECTOR:
4346         for (i=0; i<size; i++) {
4347             v0 = SCM_S8VECTOR_ELEMENTS(s0)[i];
4348             vv1 = SCM_VECTOR_ELEMENTS(s1)[i];
4349             v1 = s8num(vv1, &oor);
4350             if (!oor) {
4351                 r = s8g_mul(v0, v1, clamp);
4352             } else {
4353                 rr = SCM_MAKE_INT(v0);
4354                 rr = Scm_Multiply2(rr, vv1);
4355                 r = s8unbox(rr, clamp);
4356             }
4357             SCM_S8VECTOR_ELEMENTS(d)[i] = (signed char)r;
4358         }
4359         break;
4360     case ARGTYPE_LIST:
4361         for (i=0; i<size; i++) {
4362             v0 = SCM_S8VECTOR_ELEMENTS(s0)[i];
4363             vv1 = SCM_CAR(s1); s1 = SCM_CDR(s1);
4364             v1 = s8num(vv1, &oor);
4365             if (!oor) {
4366                 r = s8g_mul(v0, v1, clamp);
4367             } else {
4368                 rr = SCM_MAKE_INT(v0);
4369                 rr = Scm_Multiply2(rr, vv1);
4370                 r = s8unbox(rr, clamp);
4371             }
4372             SCM_S8VECTOR_ELEMENTS(d)[i] = (signed char)r;
4373         }
4374         break;
4375     case ARGTYPE_CONST:
4376         v1 = s8num(s1, &oor);
4377         for (i=0; i<size; i++) {
4378             v0 = SCM_S8VECTOR_ELEMENTS(s0)[i];
4379             if (!oor) {
4380                 r = s8g_mul(v0, v1, clamp);
4381             } else {
4382                 rr = SCM_MAKE_INT(v0);
4383                 rr = Scm_Multiply2(rr, s1);
4384                 r = s8unbox(rr, clamp);
4385             }
4386             SCM_S8VECTOR_ELEMENTS(d)[i] = (signed char)r;
4387         }
4388     }
4389 }
4390 
4391 ScmObj Scm_S8VectorMul(ScmS8Vector *s0, ScmObj s1, int clamp)
4392 {
4393     ScmObj d = Scm_MakeUVector(SCM_CLASS_S8VECTOR,
4394                                SCM_S8VECTOR_SIZE(s0),
4395                                NULL);
4396     s8vector_mul("s8vector-mul", d, SCM_OBJ(s0), s1, clamp);
4397     return d;
4398 }
4399 
4400 ScmObj Scm_S8VectorMulX(ScmS8Vector *s0, ScmObj s1, int clamp)
4401 {
4402     s8vector_mul("s8vector-mul!", SCM_OBJ(s0), SCM_OBJ(s0), s1, clamp);
4403     return SCM_OBJ(s0);
4404 }
4405 
4406 static void u8vector_mul(const char *name,
4407                                  ScmObj d, ScmObj s0, ScmObj s1, int clamp)
4408 {
4409     int i, size = SCM_U8VECTOR_SIZE(d), oor;
4410     long r, v0, v1;
4411     ScmObj rr, vv1;
4412 
4413     switch (arg2_check(name, s0, s1, TRUE)) {
4414     case ARGTYPE_UVECTOR:
4415         for (i=0; i<size; i++) {
4416             v0 = SCM_U8VECTOR_ELEMENTS(s0)[i];
4417             v1 = SCM_U8VECTOR_ELEMENTS(s1)[i];
4418             r = u8u8_mul(v0, v1, clamp);
4419             SCM_U8VECTOR_ELEMENTS(d)[i] = (unsigned char)r;
4420         }
4421         break;
4422     case ARGTYPE_VECTOR:
4423         for (i=0; i<size; i++) {
4424             v0 = SCM_U8VECTOR_ELEMENTS(s0)[i];
4425             vv1 = SCM_VECTOR_ELEMENTS(s1)[i];
4426             v1 = u8num(vv1, &oor);
4427             if (!oor) {
4428                 r = u8g_mul(v0, v1, clamp);
4429             } else {
4430                 rr = SCM_MAKE_INT(v0);
4431                 rr = Scm_Multiply2(rr, vv1);
4432                 r = u8unbox(rr, clamp);
4433             }
4434             SCM_U8VECTOR_ELEMENTS(d)[i] = (unsigned char)r;
4435         }
4436         break;
4437     case ARGTYPE_LIST:
4438         for (i=0; i<size; i++) {
4439             v0 = SCM_U8VECTOR_ELEMENTS(s0)[i];
4440             vv1 = SCM_CAR(s1); s1 = SCM_CDR(s1);
4441             v1 = u8num(vv1, &oor);
4442             if (!oor) {
4443                 r = u8g_mul(v0, v1, clamp);
4444             } else {
4445                 rr = SCM_MAKE_INT(v0);
4446                 rr = Scm_Multiply2(rr, vv1);
4447                 r = u8unbox(rr, clamp);
4448             }
4449             SCM_U8VECTOR_ELEMENTS(d)[i] = (unsigned char)r;
4450         }
4451         break;
4452     case ARGTYPE_CONST:
4453         v1 = u8num(s1, &oor);
4454         for (i=0; i<size; i++) {
4455             v0 = SCM_U8VECTOR_ELEMENTS(s0)[i];
4456             if (!oor) {
4457                 r = u8g_mul(v0, v1, clamp);
4458             } else {
4459                 rr = SCM_MAKE_INT(v0);
4460                 rr = Scm_Multiply2(rr, s1);
4461                 r = u8unbox(rr, clamp);
4462             }
4463             SCM_U8VECTOR_ELEMENTS(d)[i] = (unsigned char)r;
4464         }
4465     }
4466 }
4467 
4468 ScmObj Scm_U8VectorMul(ScmU8Vector *s0, ScmObj s1, int clamp)
4469 {
4470     ScmObj d = Scm_MakeUVector(SCM_CLASS_U8VECTOR,
4471                                SCM_U8VECTOR_SIZE(s0),
4472                                NULL);
4473     u8vector_mul("u8vector-mul", d, SCM_OBJ(s0), s1, clamp);
4474     return d;
4475 }
4476 
4477 ScmObj Scm_U8VectorMulX(ScmU8Vector *s0, ScmObj s1, int clamp)
4478 {
4479     u8vector_mul("u8vector-mul!", SCM_OBJ(s0), SCM_OBJ(s0), s1, clamp);
4480     return SCM_OBJ(s0);
4481 }
4482 
4483 static void s16vector_mul(const char *name,
4484                                  ScmObj d, ScmObj s0, ScmObj s1, int clamp)
4485 {
4486     int i, size = SCM_S16VECTOR_SIZE(d),