@@ -101,6 +101,63 @@ static inline BITTYPE PRNG_ADVANCE_BIT(BITSEEDTYPE *seed, size_t delta) {
101101 * Prototypes are in cpfloat_definitions.
102102 */
103103
104+ int cpfloat_populate_optstruct_from_format (optstruct * fpopts ) {
105+ if (fpopts == NULL )
106+ return -1 ;
107+ const char * fmt = fpopts -> format ;
108+ bool format_is_valid = true;
109+ bool is_subn_rnd_default = false;
110+ bool is_inf_no_default = false;
111+ if (fmt == NULL || fmt [0 ] == '\0' )
112+ return 1 ;
113+ else if (strcmp (fmt , "custom" ) == 0 || strcmp (fmt , "c" ) == 0 ) {
114+ return 2 ;
115+ } else if (strcmp (fmt , "q43" ) == 0 || strcmp (fmt , "e4m3" ) == 0 || strcmp (fmt , "E4M3" ) == 0 ) {
116+ fpopts -> precision = 4 ;
117+ fpopts -> emin = -6 ;
118+ fpopts -> emax = 8 ;
119+ is_inf_no_default = true;
120+ } else if (strcmp (fmt , "q52" ) == 0 || strcmp (fmt , "e5m2" ) == 0 || strcmp (fmt , "E5M2" ) == 0 ) {
121+ fpopts -> precision = 3 ;
122+ fpopts -> emin = -14 ;
123+ fpopts -> emax = 15 ;
124+ } else if (strcmp (fmt , "b" ) == 0 || strcmp (fmt , "bf16" ) == 0 || strcmp (fmt , "bfloat16" ) == 0 ) {
125+ fpopts -> precision = 8 ;
126+ fpopts -> emin = -126 ;
127+ fpopts -> emax = 127 ;
128+ is_subn_rnd_default = true;
129+ } else if (strcmp (fmt , "h" ) == 0 || strcmp (fmt , "fp16" ) == 0 || strcmp (fmt , "binary16" ) == 0 || strcmp (fmt , "half" ) == 0 ) {
130+ fpopts -> precision = 11 ;
131+ fpopts -> emin = -14 ;
132+ fpopts -> emax = 15 ;
133+ } else if (strcmp (fmt , "t" ) == 0 || strcmp (fmt , "tf32" ) == 0 || strcmp (fmt , "TensorFloat-32" ) == 0 ) {
134+ fpopts -> precision = 11 ;
135+ fpopts -> emin = -126 ;
136+ fpopts -> emax = 127 ;
137+ } else if (strcmp (fmt , "s" ) == 0 || strcmp (fmt , "fp32" ) == 0 || strcmp (fmt , "binary32" ) == 0 || strcmp (fmt , "single" ) == 0 ) {
138+ fpopts -> precision = 24 ;
139+ fpopts -> emin = -126 ;
140+ fpopts -> emax = 127 ;
141+ } else if (strcmp (fmt , "d" ) == 0 || strcmp (fmt , "fp64" ) == 0 || strcmp (fmt , "binary64" ) == 0 || strcmp (fmt , "double" ) == 0 ) {
142+ fpopts -> precision = 53 ;
143+ fpopts -> emin = -1022 ;
144+ fpopts -> emax = 1023 ;
145+ } else {
146+ format_is_valid = false;
147+ }
148+ fpopts -> subnormal = is_subn_rnd_default ? CPFLOAT_SUBN_RND : CPFLOAT_SUBN_USE ;
149+ fpopts -> explim = CPFLOAT_EXPRANGE_TARG ;
150+ fpopts -> infinity = is_inf_no_default ? CPFLOAT_INF_NO : CPFLOAT_INF_USE ;
151+ fpopts -> round = CPFLOAT_RND_NE ;
152+ fpopts -> saturation = CPFLOAT_SAT_NO ;
153+ fpopts -> flip = CPFLOAT_SOFTERR_NO ;
154+ fpopts -> p = 0.0 ;
155+ if (format_is_valid )
156+ return 0 ;
157+ else
158+ return -1 ;
159+ }
160+
104161optstruct * init_optstruct () {
105162 optstruct * fpopts = malloc (sizeof (* fpopts ));
106163 fpopts -> bitseed = NULL ;
0 commit comments