+#if HAVE_INT128
+void psi_strto_i128(char *ptr, char *end, token_t real_type, impl_val *val) {
+ unsigned __int128 i = 0;
+ bool oct = false, hex = false, sign = false;
+
+ if (*ptr == '+') {
+ ++ptr;
+ } else if (*ptr == '-') {
+ sign = true;
+ ++ptr;
+ } else if (*ptr == '\\') {
+ switch (*++ptr) {
+ case 'x':
+ hex = true;
+ ++ptr;
+ break;
+ case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':
+ oct = true;
+ break;
+ default:
+ goto fail;
+ }
+ }
+ while (ptr < end) {
+ switch (*ptr) {
+ case '8':case '9':
+ if (oct) {
+ goto fail;
+ }
+ /* no break */
+ case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':
+ if (oct) {
+ i <<= 3;
+ } else if (hex) {
+ i <<= 4;
+ } else {
+ i *= 10;
+ }
+ i += *ptr - '0';
+ break;
+ case 'a':case 'b':case 'c':case 'd':case 'e':case 'f':
+ if (!hex) {
+ goto fail;
+ }
+ i <<= 4;
+ i += 10 + (*ptr - 'a');
+ break;
+ case 'A':case 'B':case 'C':case 'D':case 'E':case 'F':
+ if (!hex) {
+ goto fail;
+ }
+ i <<= 4;
+ i += 10 + (*ptr - 'A');
+ break;
+ default:
+ fail:
+ zend_error(E_WARNING, "A non well formed numeric value encountered");
+ goto stop;
+ }
+ ++ptr;
+ }
+
+stop:
+ if (real_type == PSI_T_UINT128) {
+ if (sign) {
+ val->u128 = -i;
+ } else {
+ val->u128 = i;
+ }
+ } else {
+ if (sign) {
+ val->i128 = -i;
+ } else {
+ val->i128 = i;
+ }
+ }
+}
+#endif
+