Module: SIMDStringUpcase

Defined in:
ext/simd_string_upcase/simd_string_upcase.c

Class Method Summary collapse

Class Method Details

.instruction_setObject

Function to return the used instruction set



169
170
171
172
173
174
175
176
177
178
179
# File 'ext/simd_string_upcase/simd_string_upcase.c', line 169

static VALUE get_instruction_set(VALUE self) {
    if (has_avx2) {
        return rb_str_new_cstr("AVX2");
    } else if (has_avx) {
        return rb_str_new_cstr("AVX");
    } else if (has_sse2) {
        return rb_str_new_cstr("SSE2");
    } else {
        return rb_str_new_cstr("DEFAULT");
    }
}

.upcase(str) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'ext/simd_string_upcase/simd_string_upcase.c', line 144

static VALUE simd_upcase(VALUE self, VALUE str) {
    // Check if the string is ASCII only
    long len = RSTRING_LEN(str);
    char *text = StringValuePtr(str);
    for (long i = 0; i < len; i++) {
        if ((unsigned char)text[i] > 127) {
            // Fallback to default Ruby implementation for non-ASCII characters
            return rb_funcall(str, rb_intern("upcase"), 0);
        }
    }

    // Use SIMD optimized version for ASCII-only strings
    if (has_avx2) {
        return upcase_avx2(self, str);
    } else if (has_avx) {
        return upcase_avx1(self, str);
    } else if (has_sse2) {
        return upcase_sse2(self, str);
    } else {
        // Fallback to default Ruby implementation
        return rb_funcall(str, rb_intern("upcase"), 0);
    }
}