| 1 |
/* -*- Mode: C; c-basic-offset: 2; indent-tabs-mode: nil -*- */ |
| 2 |
/* vim: set filetype=c tabstop=2 shiftwidth=2 expandtab: */ |
| 3 |
|
| 4 |
/* |
| 5 |
* write_sse.d - ugly printer for SSE types |
| 6 |
* |
| 7 |
* Copyright (c) 1984 Taiichi Yuasa and Masami Hagiya |
| 8 |
* Copyright (c) 1990 Giuseppe Attardi |
| 9 |
* Copyright (c) 2001 Juan Jose Garcia Ripoll |
| 10 |
* |
| 11 |
* See file 'LICENSE' for the copyright details. |
| 12 |
* |
| 13 |
*/ |
| 14 |
|
| 15 |
#include <ecl/config.h> |
| 16 |
|
| 17 |
#ifdef ECL_SSE2 |
| 18 |
#include <ecl/ecl.h> |
| 19 |
#include <ecl/internal.h> |
| 20 |
|
| 21 |
|
| 22 |
static int |
| 23 |
is_all_FF(void *ptr, int size) { |
| 24 |
int i; |
| 25 |
for (i = 0; i < size; i++) |
| 26 |
if (((unsigned char*)ptr)[i] != 0xFF) |
| 27 |
return 0; |
| 28 |
return 1; |
| 29 |
} |
| 30 |
|
| 31 |
static void |
| 32 |
write_sse_float(float v, cl_object stream) |
| 33 |
{ |
| 34 |
if (is_all_FF(&v, sizeof(float))) { |
| 35 |
writestr_stream(" TRUE", stream); |
| 36 |
} else { |
| 37 |
ecl_write_char(' ', stream); |
| 38 |
si_write_ugly_object(ecl_make_single_float(v), stream); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
static void |
| 43 |
write_sse_double(double v, cl_object stream) |
| 44 |
{ |
| 45 |
if (is_all_FF(&v, sizeof(double))) |
| 46 |
writestr_stream(" TRUE", stream); |
| 47 |
else { |
| 48 |
ecl_write_char(' ', stream); |
| 49 |
si_write_ugly_object(ecl_make_double_float(v), stream); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
static void |
| 54 |
write_sse_pack(cl_object x, cl_object stream) |
| 55 |
{ |
| 56 |
int i; |
| 57 |
cl_elttype etype = x->sse.elttype; |
| 58 |
cl_object mode = ecl_symbol_value(@'ext::*sse-pack-print-mode*'); |
| 59 |
|
| 60 |
if (mode != ECL_NIL) { |
| 61 |
if (mode == @':float') etype = ecl_aet_sf; |
| 62 |
else if (mode == @':double') etype = ecl_aet_df; |
| 63 |
else etype = ecl_aet_b8; |
| 64 |
} |
| 65 |
|
| 66 |
switch (etype) { |
| 67 |
case ecl_aet_sf: |
| 68 |
for (i = 0; i < 4; i++) |
| 69 |
write_sse_float(x->sse.data.sf[i], stream); |
| 70 |
break; |
| 71 |
case ecl_aet_df: |
| 72 |
write_sse_double(x->sse.data.df[0], stream); |
| 73 |
write_sse_double(x->sse.data.df[1], stream); |
| 74 |
break; |
| 75 |
default: { |
| 76 |
cl_object buffer = si_get_buffer_string(); |
| 77 |
for (i = 0; i < 16; i++) { |
| 78 |
ecl_string_push_extend(buffer, ' '); |
| 79 |
if (i%4 == 0) ecl_string_push_extend(buffer, ' '); |
| 80 |
si_integer_to_string(buffer, ecl_make_fixnum(x->sse.data.b8[i]), |
| 81 |
ecl_make_fixnum(16), ECL_NIL, ECL_NIL); |
| 82 |
} |
| 83 |
si_do_write_sequence(buffer, stream, ecl_make_fixnum(0), ECL_NIL); |
| 84 |
si_put_buffer_string(buffer); |
| 85 |
break; |
| 86 |
} |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
void |
| 91 |
_ecl_write_sse(cl_object x, cl_object stream) |
| 92 |
{ |
| 93 |
if (ecl_print_readably()) FEprint_not_readable(x); |
| 94 |
writestr_stream("#<SSE", stream); |
| 95 |
write_sse_pack(x, stream); |
| 96 |
ecl_write_char('>', stream); |
| 97 |
} |
| 98 |
#endif |