forked from Unidata/netcdf-c
/
ncx_cray.c
3847 lines (3201 loc) · 68.3 KB
/
ncx_cray.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 1996, University Corporation for Atmospheric Research
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
*
*/
/* $Id: ncx_cray.c,v 1.60 2004/09/30 18:47:12 russ Exp $ */
#ifndef _CRAY
#error "ncx_cray.c is a cray specific implementation"
#endif
#if HAVE_CONFIG_H
#include <config.h>
#endif
/*
* An external data representation interface.
*/
/*
* TODO: Fix "off diagonal" functions (ncx_{put,get}[n]_t1_t2() s.t. t1 != t2)
* to be use IEG functions when diagonals are.
*
* Whine to cray about IEG function limiting behavior.
*/
#include <string.h>
#include <limits.h>
/* alias poorly named limits.h macros */
#define SHORT_MAX SHRT_MAX
#define SHORT_MIN SHRT_MIN
#define USHORT_MAX USHRT_MAX
#include <float.h>
#include <assert.h>
#include "ncx.h"
/**/
#if USE_IEG
#define C_SIZE_T size_t
extern int
CRAY2IEG(
const int *typep,
const C_SIZE_T *nump,
word *foreignp,
const int *bitoffp,
const void *local,
const int *stride
);
extern int
IEG2CRAY(
const int *typep,
const C_SIZE_T *nump,
const word *foreignp,
const int *bitoffp,
void *local,
const int *stride
);
static const int Zero = 0;
static const C_SIZE_T One = 1;
static const int ThirtyTwo = 32;
static const int UnitStride = 1;
static const int Cray2_I32 = 1; /* 32 bit two complement */
static const int Cray2_F32 = 2; /* IEEE single precision */
static const int Cray2_I16 = 7; /* 16 bit twos complement */
static const int Cray2_F64 = 8; /* CRAY float to IEEE double */
#define SHORT_USE_IEG 1
#define INT_USE_IEG 1
#define FLOAT_USE_IEG 1
#define DOUBLE_USE_IEG 1
#if _CRAY1
/*
* Return the number of bits "into" a word that (void *) is.
* N.B. This is based on the CRAY1 (PVP) address structure,
* which puts the address within a word in the leftmost 3 bits
* of the address.
*/
static size_t
bitoff(const void *vp)
{
const size_t bitoffset = ((size_t)vp >> (64 - 6)) & 0x3f;
return bitoffset;
}
# else
#error "Don't use IEG2CRAY, CRAY2IEG except on CRAY1 (MPP) platforms"
#define bitoff(vp) ((size_t)(vp) % 64) /* N.B. Assumes 64 bit word */
# endif /* _CRAY1 */
#endif /* USE_IEG */
#if _CRAY1
/*
* Return the number of bytes "into" a word that (void *) is.
* N.B. This is based on the CRAY1 (PVP) address structure,
* which puts the address within a word in the leftmost 3 bits
* of the address.
*/
static size_t
byteoff(const void *vp)
{
const size_t byteoffset = ((size_t)vp >> (64 - 3)) & 0x7;
return byteoffset;
}
#else
#define byteoff(vp) ((size_t)(vp) % 8) /* N.B. Assumes 64 bit word */
#endif /* _CRAY1 */
/*
* Return the number of bytes until the next "word" boundary
*/
static size_t
word_align(const void *vp)
{
const size_t rem = byteoff(vp);
if(rem == 0)
return 0;
return sizeof(word) - rem;
}
static const char nada[X_ALIGN] = {0, 0, 0, 0};
/*
* Primitive numeric conversion functions.
*/
/* x_schar */
/* We don't implement and x_schar primitives. */
/* x_short */
typedef short ix_short;
#define SIZEOF_IX_SHORT SIZEOF_SHORT
#define IX_SHORT_MAX SHORT_MAX
static void
cget_short_short(const void *xp, short *ip, int which)
{
const long *wp = xp;
switch(which) {
case 0:
*ip = (short)(*wp >> 48);
break;
case 1:
*ip = (short)((*wp >> 32) & 0xffff);
break;
case 2:
*ip = (short)((*wp >> 16) & 0xffff);
break;
case 3:
*ip = (short)(*wp & 0xffff);
break;
}
if(*ip & 0x8000)
{
/* extern is negative */
*ip |= (~(0xffff));
}
}
#define get_ix_short(xp, ip) cget_short_short((xp), (ip), byteoff(xp)/X_SIZEOF_SHORT)
static int
cput_short_short(void *xp, const short *ip, int which)
{
word *wp = xp;
switch(which) {
case 0:
*wp = (*ip << 48)
| (*wp & 0x0000ffffffffffff);
break;
case 1:
*wp = ((*ip << 32) & 0x0000ffff00000000)
| (*wp & 0xffff0000ffffffff);
break;
case 2:
*wp = ((*ip << 16) & 0x00000000ffff0000)
| (*wp & 0xffffffff0000ffff);
break;
case 3:
*wp = (*ip & 0x000000000000ffff)
| (*wp & 0xffffffffffff0000);
break;
}
if(*ip > X_SHORT_MAX || *ip < X_SHORT_MIN)
return NC_ERANGE;
return NC_NOERR;
}
int
ncx_get_short_schar(const void *xp, schar *ip)
{
ix_short xx;
get_ix_short(xp, &xx);
*ip = xx;
if(xx > SCHAR_MAX || xx < SCHAR_MIN)
return NC_ERANGE;
return NC_NOERR;
}
int
ncx_get_short_uchar(const void *xp, uchar *ip)
{
ix_short xx;
get_ix_short(xp, &xx);
*ip = xx;
if(xx > UCHAR_MAX || xx < 0)
return NC_ERANGE;
return NC_NOERR;
}
int
ncx_get_short_short(const void *xp, short *ip)
{
get_ix_short(xp, ip);
return NC_NOERR;
}
int
ncx_get_short_int(const void *xp, int *ip)
{
ix_short xx;
get_ix_short(xp, &xx);
*ip = xx;
return NC_NOERR;
}
int
ncx_get_short_long(const void *xp, long *ip)
{
ix_short xx;
get_ix_short(xp, &xx);
*ip = xx;
return NC_NOERR;
}
int
ncx_get_short_float(const void *xp, float *ip)
{
ix_short xx;
get_ix_short(xp, &xx);
*ip = xx;
return NC_NOERR;
}
int
ncx_get_short_double(const void *xp, double *ip)
{
ix_short xx;
get_ix_short(xp, &xx);
*ip = xx;
return NC_NOERR;
}
int
ncx_put_short_schar(void *xp, const schar *ip)
{
uchar *cp = xp;
if(*ip & 0x80)
*cp++ = 0xff;
else
*cp++ = 0;
*cp = (uchar)*ip;
return NC_NOERR;
}
int
ncx_put_short_uchar(void *xp, const uchar *ip)
{
uchar *cp = xp;
*cp++ = 0;
*cp = *ip;
return NC_NOERR;
}
int
ncx_put_short_short(void *xp, const short *ip)
{
return cput_short_short(xp, ip, byteoff(xp)/X_SIZEOF_SHORT);
}
int
ncx_put_short_int(void *xp, const int *ip)
{
ix_short xx = (ix_short)*ip;
return cput_short_short(xp, &xx, byteoff(xp)/X_SIZEOF_SHORT);
}
int
ncx_put_short_long(void *xp, const long *ip)
{
ix_short xx = (ix_short)*ip;
return cput_short_short(xp, &xx, byteoff(xp)/X_SIZEOF_SHORT);
}
int
ncx_put_short_float(void *xp, const float *ip)
{
ix_short xx = (ix_short)*ip;
const int status = cput_short_short(xp, &xx, byteoff(xp)/X_SIZEOF_SHORT);
if(status != NC_NOERR)
return status;
if(*ip > X_SHORT_MAX || *ip < X_SHORT_MIN)
return NC_ERANGE;
return NC_NOERR;
}
int
ncx_put_short_double(void *xp, const double *ip)
{
ix_short xx = (ix_short)*ip;
const int status = cput_short_short(xp, &xx, byteoff(xp)/X_SIZEOF_SHORT);
if(status != NC_NOERR)
return status;
if(*ip > X_SHORT_MAX || *ip < X_SHORT_MIN)
return NC_ERANGE;
return NC_NOERR;
}
/* x_int */
typedef int ix_int;
#define SIZEOF_IX_INT SIZEOF_INT
#define IX_INT_MAX INT_MAX
static void
cget_int_int(const void *xp, int *ip, int which)
{
const long *wp = xp;
if(which == 0)
{
*ip = (int)(*wp >> 32);
}
else
{
*ip = (int)(*wp & 0xffffffff);
}
if(*ip & 0x80000000)
{
/* extern is negative */
*ip |= (~(0xffffffff));
}
}
#define get_ix_int(xp, ip) cget_int_int((xp), (ip), byteoff(xp))
static int
cput_int_int(void *xp, const int *ip, int which)
{
word *wp = xp;
if(which == 0)
{
*wp = (*ip << 32) | (*wp & 0xffffffff);
}
else
{
*wp = (*wp & ~0xffffffff) | (*ip & 0xffffffff);
}
if(*ip > X_INT_MAX || *ip < X_INT_MIN)
return NC_ERANGE;
return NC_NOERR;
}
#define put_ix_int(xp, ip) cput_int_int((xp), (ip), byteoff(xp))
int
ncx_get_int_schar(const void *xp, schar *ip)
{
ix_int xx;
get_ix_int(xp, &xx);
*ip = xx;
if(xx > SCHAR_MAX || xx < SCHAR_MIN)
return NC_ERANGE;
return NC_NOERR;
}
int
ncx_get_int_uchar(const void *xp, uchar *ip)
{
ix_int xx;
get_ix_int(xp, &xx);
*ip = xx;
if(xx > UCHAR_MAX || xx < 0)
return NC_ERANGE;
return NC_NOERR;
}
int
ncx_get_int_short(const void *xp, short *ip)
{
ix_int xx;
get_ix_int(xp, &xx);
*ip = xx;
if(xx > SHORT_MAX || xx < SHORT_MIN)
return NC_ERANGE;
return NC_NOERR;
}
int
ncx_get_int_int(const void *xp, int *ip)
{
ix_int xx;
get_ix_int(xp, &xx);
*ip = xx;
return NC_NOERR;
}
static void
cget_int_long(const void *xp, long *ip, int which)
{
const long *wp = xp;
if(which == 0)
{
*ip = (int)(*wp >> 32);
}
else
{
*ip = (int)(*wp & 0xffffffff);
}
if(*ip & 0x80000000)
{
/* extern is negative */
*ip |= (~(0xffffffff));
}
}
int
ncx_get_int_long(const void *xp, long *ip)
{
cget_int_long(xp, ip, byteoff(xp));
return NC_NOERR;
}
int
ncx_get_int_float(const void *xp, float *ip)
{
ix_int xx;
get_ix_int(xp, &xx);
*ip = xx;
if(xx > FLT_MAX || xx < (-FLT_MAX))
return NC_ERANGE;
return NC_NOERR;
}
int
ncx_get_int_double(const void *xp, double *ip)
{
ix_int xx;
get_ix_int(xp, &xx);
*ip = xx;
return NC_NOERR;
}
int
ncx_put_int_schar(void *xp, const schar *ip)
{
uchar *cp = xp;
if(*ip & 0x80)
{
*cp++ = 0xff;
*cp++ = 0xff;
*cp++ = 0xff;
}
else
{
*cp++ = 0x00;
*cp++ = 0x00;
*cp++ = 0x00;
}
*cp = (uchar)*ip;
return NC_NOERR;
}
int
ncx_put_int_uchar(void *xp, const uchar *ip)
{
uchar *cp = xp;
*cp++ = 0x00;
*cp++ = 0x00;
*cp++ = 0x00;
*cp = *ip;
return NC_NOERR;
}
int
ncx_put_int_short(void *xp, const short *ip)
{
ix_int xx = (ix_int)(*ip);
return put_ix_int(xp, &xx);
}
int
ncx_put_int_int(void *xp, const int *ip)
{
return put_ix_int(xp, ip);
}
static int
cput_int_long(void *xp, const long *ip, int which)
{
long *wp = xp;
if(which == 0)
{
*wp = (*ip << 32) | (*wp & 0xffffffff);
}
else
{
*wp = (*wp & ~0xffffffff) | (*ip & 0xffffffff);
}
if(*ip > X_INT_MAX || *ip < X_INT_MIN)
return NC_ERANGE;
return NC_NOERR;
}
int
ncx_put_int_long(void *xp, const long *ip)
{
return cput_int_long(xp, ip, byteoff(xp));
}
int
ncx_put_int_float(void *xp, const float *ip)
{
ix_int xx = (ix_int)(*ip);
const int status = put_ix_int(xp, &xx);
if(status != NC_NOERR)
return status;
if(*ip > (double)X_INT_MAX || *ip < (double)X_INT_MIN)
return NC_ERANGE;
return NC_NOERR;
}
int
ncx_put_int_double(void *xp, const double *ip)
{
ix_int xx = (ix_int)(*ip);
const int status = put_ix_int(xp, &xx);
if(status != NC_NOERR)
return status;
if(*ip > X_INT_MAX || *ip < X_INT_MIN)
return NC_ERANGE;
return NC_NOERR;
}
/* x_float */
#if defined(NO_IEEE_FLOAT)
struct cray_single {
unsigned int sign : 1;
unsigned int exp :15;
unsigned int mant :48;
};
typedef struct cray_single cray_single;
static const int cs_ieis_bias = 0x4000 - 0x7f;
static const int cs_id_bias = 0x4000 - 0x3ff;
#endif
struct ieee_single_hi {
unsigned int sign : 1;
unsigned int exp : 8;
unsigned int mant :23;
unsigned int pad :32;
};
typedef struct ieee_single_hi ieee_single_hi;
struct ieee_single_lo {
unsigned int pad :32;
unsigned int sign : 1;
unsigned int exp : 8;
unsigned int mant :23;
};
typedef struct ieee_single_lo ieee_single_lo;
static const int ieee_single_bias = 0x7f;
struct ieee_double {
unsigned int sign : 1;
unsigned int exp :11;
unsigned int mant :52;
};
typedef struct ieee_double ieee_double;
static const int ieee_double_bias = 0x3ff;
#if FLOAT_USE_IEG
static void
get_ix_float(const void *xp, float *ip)
{
const int bo = bitoff(xp);
(void) IEG2CRAY(&Cray2_F32, &One, (word *)xp, &bo, ip, &UnitStride);
}
static int
put_ix_float(void *xp, const float *ip)
{
const int bo = bitoff(xp);
int status = CRAY2IEG(&Cray2_F32, &One, (word *)xp, &bo, ip, &UnitStride);
if(status != 0)
status = NC_ERANGE;
/* else, status == 0 == NC_NOERR */
return status;
}
#else
/* !FLOAT_USE_IEG */
#if defined(NO_IEEE_FLOAT)
static void
cget_float_float(const void *xp, float *ip, int which)
{
if(which == 0)
{
const ieee_single_hi *isp = (const ieee_single_hi *) xp;
cray_single *csp = (cray_single *) ip;
if(isp->exp == 0)
{
/* ieee subnormal */
*ip = (double)isp->mant;
if(isp->mant != 0)
{
csp->exp -= (ieee_single_bias + 22);
}
}
else
{
csp->exp = isp->exp + cs_ieis_bias + 1;
csp->mant = isp->mant << (48 - 1 - 23);
csp->mant |= (1 << (48 - 1));
}
csp->sign = isp->sign;
}
else
{
const ieee_single_lo *isp = (const ieee_single_lo *) xp;
cray_single *csp = (cray_single *) ip;
if(isp->exp == 0)
{
/* ieee subnormal */
*ip = (double)isp->mant;
if(isp->mant != 0)
{
csp->exp -= (ieee_single_bias + 22);
}
}
else
{
csp->exp = isp->exp + cs_ieis_bias + 1;
csp->mant = isp->mant << (48 - 1 - 23);
csp->mant |= (1 << (48 - 1));
}
csp->sign = isp->sign;
}
}
static int
cput_float_float(void *xp, const float *ip, int which)
{
int status = NC_NOERR;
if(which == 0)
{
ieee_single_hi *isp = (ieee_single_hi*)xp;
const cray_single *csp = (const cray_single *) ip;
int ieee_exp = csp->exp - cs_ieis_bias -1;
isp->sign = csp->sign;
if(ieee_exp >= 0xff
|| *ip > X_FLOAT_MAX || *ip < X_FLOAT_MIN)
{
/* NC_ERANGE => ieee Inf */
isp->exp = 0xff;
isp->mant = 0x0;
return NC_ERANGE;
}
/* else */
if(ieee_exp > 0)
{
/* normal ieee representation */
isp->exp = ieee_exp;
/* assumes cray rep is in normal form */
/* assert(csp->mant & 0x800000000000); */
isp->mant = (((csp->mant << 1) &
0xffffffffffff) >> (48 - 23));
}
else if(ieee_exp > -23)
{
/* ieee subnormal, right */
const int rshift = (48 - 23 - ieee_exp);
isp->mant = csp->mant >> rshift;
isp->exp = 0;
}
else
{
/* smaller than ieee can represent */
isp->exp = 0;
isp->mant = 0;
}
}
else
{
ieee_single_lo *isp = (ieee_single_lo*)xp;
const cray_single *csp = (const cray_single *) ip;
int ieee_exp = csp->exp - cs_ieis_bias -1;
isp->sign = csp->sign;
if(ieee_exp >= 0xff
|| *ip > X_FLOAT_MAX || *ip < X_FLOAT_MIN)
{
/* NC_ERANGE => ieee Inf */
isp->exp = 0xff;
isp->mant = 0x0;
return NC_ERANGE;
}
/* else */
if(ieee_exp > 0)
{
/* normal ieee representation */
isp->exp = ieee_exp;
/* assumes cray rep is in normal form */
/* assert(csp->mant & 0x800000000000); */
isp->mant = (((csp->mant << 1) &
0xffffffffffff) >> (48 - 23));
}
else if(ieee_exp > -23)
{
/* ieee subnormal, right */
const int rshift = (48 - 23 - ieee_exp);
isp->mant = csp->mant >> rshift;
isp->exp = 0;
}
else
{
/* smaller than ieee can represent */
isp->exp = 0;
isp->mant = 0;
}
}
return NC_NOERR;
}
#define get_ix_float(xp, ip) cget_float_float((xp), (ip), byteoff(xp))
#define put_ix_float(xp, ip) cput_float_float((xp), (ip), byteoff(xp))
#else
/* IEEE Cray with only doubles */
static void
cget_float_float(const void *xp, float *ip, int which)
{
ieee_double *idp = (ieee_double *) ip;
if(which == 0)
{
const ieee_single_hi *isp = (const ieee_single_hi *) xp;
if(isp->exp == 0 && isp->mant == 0)
{
idp->exp = 0;
idp->mant = 0;
}
else
{
idp->exp = isp->exp + (ieee_double_bias - ieee_single_bias);
idp->mant = isp->mant << (52 - 23);
}
idp->sign = isp->sign;
}
else
{
const ieee_single_lo *isp = (const ieee_single_lo *) xp;
if(isp->exp == 0 && isp->mant == 0)
{
idp->exp = 0;
idp->mant = 0;
}
else
{
idp->exp = isp->exp + (ieee_double_bias - ieee_single_bias);
idp->mant = isp->mant << (52 - 23);
}
idp->sign = isp->sign;
}
}
static int
cput_float_float(void *xp, const float *ip, int which)
{
const ieee_double *idp = (const ieee_double *) ip;
if(which == 0)
{
ieee_single_hi *isp = (ieee_single_hi*)xp;
if(idp->exp > (ieee_double_bias - ieee_single_bias))
isp->exp = idp->exp - (ieee_double_bias - ieee_single_bias);
else
isp->exp = 0;
isp->mant = idp->mant >> (52 - 23);
isp->sign = idp->sign;
}
else
{
ieee_single_lo *isp = (ieee_single_lo*)xp;
if(idp->exp > (ieee_double_bias - ieee_single_bias))
isp->exp = idp->exp - (ieee_double_bias - ieee_single_bias);
else
isp->exp = 0;
isp->mant = idp->mant >> (52 - 23);
isp->sign = idp->sign;
}
if(*ip > X_FLOAT_MAX || *ip < X_FLOAT_MIN)
return NC_ERANGE;
return NC_NOERR;
}
#define get_ix_float(xp, ip) cget_float_float((xp), (ip), byteoff(xp))
#define put_ix_float(xp, ip) cput_float_float((xp), (ip), byteoff(xp))
#endif /* NO_IEEE_FLOAT */
#endif /* FLOAT_USE_IEG */
int
ncx_get_float_schar(const void *xp, schar *ip)
{
float xx;
get_ix_float(xp, &xx);
*ip = (schar) xx;
if(xx > SCHAR_MAX || xx < SCHAR_MIN)
return NC_ERANGE;
return NC_NOERR;
}
int
ncx_get_float_uchar(const void *xp, uchar *ip)
{
float xx;
get_ix_float(xp, &xx);
*ip = (uchar) xx;
if(xx > UCHAR_MAX || xx < 0)
return NC_ERANGE;
return NC_NOERR;
}
int
ncx_get_float_short(const void *xp, short *ip)
{
float xx;
get_ix_float(xp, &xx);
*ip = (short) xx;
if(xx > SHORT_MAX || xx < SHORT_MIN)
return NC_ERANGE;
return NC_NOERR;
}
int
ncx_get_float_int(const void *xp, int *ip)
{
float xx;
get_ix_float(xp, &xx);
*ip = (int) xx;
if(xx > (double)INT_MAX || xx < (double)INT_MIN)
return NC_ERANGE;
return NC_NOERR;
}
int
ncx_get_float_long(const void *xp, long *ip)
{
float xx;
get_ix_float(xp, &xx);
*ip = (long) xx;
if(xx > LONG_MAX || xx < LONG_MIN)
return NC_ERANGE;
return NC_NOERR;
}
int
ncx_get_float_float(const void *xp, float *ip)
{
get_ix_float(xp, ip);
return NC_NOERR;
}
int
ncx_get_float_double(const void *xp, double *ip)
{
#if SIZEOF_FLOAT == SIZEOF_DOUBLE && FLT_MANT_DIG == DBL_MANT_DIG
return ncx_get_float_float(xp, (float *)ip);
#else
float xx;
get_ix_float(xp, &xx);
*ip = xx;
return NC_NOERR;
#endif
}
int
ncx_put_float_schar(void *xp, const schar *ip)
{
float xx = (float) *ip;
return put_ix_float(xp, &xx);
}
int
ncx_put_float_uchar(void *xp, const uchar *ip)
{
float xx = (float) *ip;
return put_ix_float(xp, &xx);
}
int
ncx_put_float_short(void *xp, const short *ip)
{
float xx = (float) *ip;
return put_ix_float(xp, &xx);
}
int
ncx_put_float_int(void *xp, const int *ip)
{
float xx = (float) *ip;
return put_ix_float(xp, &xx);
}
int
ncx_put_float_long(void *xp, const long *ip)
{
float xx = (float) *ip;
return put_ix_float(xp, &xx);
}
int
ncx_put_float_float(void *xp, const float *ip)
{
return put_ix_float(xp, ip);
}
int
ncx_put_float_double(void *xp, const double *ip)
{
#if SIZEOF_FLOAT == SIZEOF_DOUBLE && FLT_MANT_DIG == DBL_MANT_DIG
return put_ix_float(xp, (float *)ip);
#else
float xx = (float) *ip;
int status = put_ix_float(xp, &xx);
if(*ip > X_FLOAT_MAX || *ip < X_FLOAT_MIN)
return NC_ERANGE;
return status;
#endif
}
/* x_double */
#if X_SIZEOF_DOUBLE == SIZEOF_DOUBLE && !defined(NO_IEEE_FLOAT)
static void
get_ix_double(const void *xp, double *ip)
{
(void) memcpy(ip, xp, sizeof(double));
}
static int
put_ix_double(void *xp, const double *ip)
{